Ok, I’ll post up the code now, it’s not working for the top left hand side, when the line gets past the tile above the one that I’m checking from…
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package kingdom.blue;
import java.awt.Point;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
/**
*
* @author Tom
*/
public class TileTorch extends Tile {
public TileTorch(int x, int y, map m){
lightLevel = 5;
floorBlock = false;
lightSurroundings(x,y,m);
}
public void lightSurroundings(int x, int y,map m){
int firstx = x-4;
int firsty = y-4;
for(int x1 = firstx;x1 < x+4;x1++){
for(int y1 = firsty;y1 < y+4;y1++){
if(tileVisible(x,x1,y,y1,m)){
if(x1 > -1 && x1 < map.WIDTH){
if(y1 > -1 && y1 < map.HEIGHT){
if(m.Map[x1][y1] != null){
m.Map[x1][y1].lightLevel = 5;
System.out.println("lighting tile!");
}
}
}
}
}
}
}
public static boolean tileVisible(int x1, int x2, int y1, int y2, map m){
int xinc1;
int xinc2;
int yinc1;
int yinc2;
int abs;
int den;
int num;
int numadd;
int numTiles;
int deltax = (int)(x2 - x1);
int deltay = (int)(y2 - y1);
int x = x1;
int y = y1;
if (x2 >= x1)
{
xinc1 = 1;
xinc2 = 1;
}
else
{
xinc1 = -1;
xinc2 = -1;
}
if (y2 >= y1)
{
yinc1 = 1;
yinc2 = 1;
}
else
{
yinc1 = -1;
yinc2 = -1;
}
if (deltax >= deltay)
{
xinc1 = 0;
yinc2 = 0;
den = deltax;
num = deltax / 2;
numadd = deltay;
numTiles = deltax;
}
else
{
xinc2 = 0;
yinc1 = 0;
den = deltay;
num = deltay / 2;
numadd = deltax;
numTiles = deltay;
}
for (int currentTile = 0; currentTile <= numTiles; currentTile++)
{
if(x > -1 && x <= map.WIDTH){
if(y > -1 && y <= map.HEIGHT){
if(m.Map[x][y] != null){
if(m.Map[x][y].lightBlock){
return false;
}
}
}
}
num += numadd;
if (num >= den)
{
num -= den;
x += xinc1;
y += yinc1;
}
x += xinc2;
y += yinc2;
}
return true;
}
}
Now I really am off to bed, I’ll check back in the morning…