The world in my game is represented with a two dimensional array: byte[stage_height][stage_width].
If the byte is 0, the pixel is solid space, if it is 1, its hollow.
So I have a game object called A, and is placed somewhere in my world. I want to iterate from A to an other point and see if there is solid space between these two points.
I already have a function that does this, but the performance of that method is awful. Is there anything faster around here? Super-precision is not required.
Here is my function if anyone is interested:
public static boolean solidSpace (int x0, int y0, int x1, int y1)
{
float dx = Math.abs(x1-x0);
float dy = Math.abs(y1-y0);
int sx = (x0 < x1) ? 1 : -1;
int sy = (y0 < y1) ? 1 : -1;
float err = dx-dy;
byte[][] b = Stage.STAGE.stageData;
while (true)
{
if (b[y0][x0] == SOLID)
return false;
if (x0 == x1 && y0 == y1)
return true;
float e2 = 2*err;
if (e2 > -dy)
{
err -= dy;
x0 += sx;
}
if (e2 < dx)
{
err += dx;
y0 += sy;
}
}
}