if the map is '#' then it is a wall, otherwise, it isnt.
how im doing this is basically imagining a line from the player (player.x+16,player.y+16) (the +16 is for the center of the player) to the center of the box (x+32 y+32) the argument to the function is the top left or the box
then im tracing along this line via means of the direction (end-begin).normal();
here is my current code:
- Code: Select all
bool CanSeeSQ(int x, int y){
//vec2 = float x,y : vec2i = int x,y
bool z=0;
int n=-30,m=-30;
vec2i start=vec2i((game.player.x+16),(game.player.y+16)); //start of line
vec2i end =vec2i((x+32),(y+32)); //end of line
vec2 slope=vecsubtract(end,start);
float mag=normalize(&slope); // normalize(blah) returns vector magnitude
if (mag==0)
return true;
if (mag>=game.map.visibility)
return false;
slope.x*=32;
slope.y*=32;
for (vec2 curr=start;
((slope.x)>0?(curr.x<end.x):(curr.x>end.x))&&((slope.y>0)?(curr.y<end.y):(curr.y>end.y)); // loop to the end of the line, yea this parts confusing :D
curr.x+=slope.x,curr.y+=slope.y){ // move out current position
if (z&&!(n==(int)curr.x/64)&&(m==(int)curr.y/64)) // if we saw a box, and its not the first box we saw, then we cant see the square
return false;
if (game.map[(int)curr.x/64][(int)curr.y/64]=='#'){ // this check is to make sure that we dont hide the box we're next to, else there will be a black box next to you when you normally can see the box next to you
n=(int)curr.x/64;
m=(int)curr.y/64;
z=1;
}
}
return true;
}
this pretty much crases and burns.. and i dont know why...
this is what it looks like:
http://et.ath.cx/chogblasters_current.jpg
and this is what it should look like:
http://et.ath.cx/chogblasters_iwishitwasthis.jpg
and i cant figure out whats wrong.. can anyone see a flaw in my method or something? because i sure cant :-\
thanks
