Walkable Area Problem (SOLVED)

Started by Quintaros, Tue 15/02/2005 15:22:07

Previous topic - Next topic

Quintaros

I'm working on a platform-type room for a game and I've encountered a strange problem with the walkable areas.

I have display commands for testing the character's x and y coordinates as well as the walkable area he is currently standing on:



function on_key_press(){
if (keycode==75) Display("x= %d y= %d z= % ", character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y,character[GetPlayerCharacter()].z);
  if (keycode==50)Display("walkable area is %d", GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y));
}

Strangely though the message for the character's current walkable area does not always agree with his coordinates.  When the character is to the far right in the room, the walkable area goes wrong so that he gets stuck.  This does not seem to occur on the left side of the room.

Can this have something to do with the room being greater than 320 pixels wide (ie. Scrolling when the character walks right (east))?

Or maybe it's related to using the cursor arrows to control movement? 


if ((IsKeyPressed(377)!=0)&&(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y) != 0)){
   
   if(float_to_int(speed)<40){
     speed=fadd(speed, ints_to_float(0,500));
     }
   move=fdiv(fmul(speed,int_to_float(scale)),int_to_float(100));
   move=float_to_int(move);
   if(character[GetPlayerCharacter()].animating==0) AnimateCharacter(GetPlayerCharacter(),2,4,0);
   if(character[GetPlayerCharacter()].frame!=lastframe) character[GetPlayerCharacter()].x+=move;
   lastframe=character[GetPlayerCharacter()].frame;
   Vx=fdiv(speed,fmul(int_to_float(character[GetPlayerCharacter()].animspeed),int_to_float(GetGameSpeed())));
   
}else if ((IsKeyPressed(380)!=0)){
   if(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y) == 4){
     if(character[GetPlayerCharacter()].animating==0)AnimateCharacter(GetPlayerCharacter(),6,4,0);
     if(character[GetPlayerCharacter()].frame!=lastframe){
       if(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y+1)==4){
         character[GetPlayerCharacter()].y+=1;
       }else if(GetWalkableAreaAt(character[GetPlayerCharacter()].x-1,character[GetPlayerCharacter()].y)==4){
         character[GetPlayerCharacter()].x-=1;
       }
     }       
   }else if(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y) == 5){
     if(character[GetPlayerCharacter()].animating==0)AnimateCharacter(GetPlayerCharacter(),4,4,0);
     if(character[GetPlayerCharacter()].frame!=lastframe){
       if(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y+1)==5){
         character[GetPlayerCharacter()].y+=1;
       }else if(GetWalkableAreaAt(character[GetPlayerCharacter()].x+1,character[GetPlayerCharacter()].y)==5){
         character[GetPlayerCharacter()].x+=1;
       }
     }       
   }else if(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y) != 0){
   
   if(float_to_int(speed)<40){
     speed=fadd(speed, ints_to_float(0,500));
     }
   move=fdiv(fmul(speed,int_to_float(scale)),int_to_float(100));
   move=float_to_int(move);
     if(character[GetPlayerCharacter()].animating==0)AnimateCharacter(GetPlayerCharacter(),0,4,0);
     if(character[GetPlayerCharacter()].frame!=lastframe) character[GetPlayerCharacter()].y+=move;
     lastframe=character[GetPlayerCharacter()].frame;
     }
   }else if ((IsKeyPressed(375)!=0)&&(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y) != 0)){
   
   if(float_to_int(speed)<40){
     speed=fadd(speed, ints_to_float(0,500));
     }
   move=fdiv(fmul(speed,int_to_float(scale)),int_to_float(100));
   move=float_to_int(move);
     if(character[GetPlayerCharacter()].animating==0)AnimateCharacter(GetPlayerCharacter(),1,4,0);
     if(character[GetPlayerCharacter()].frame!=lastframe) character[GetPlayerCharacter()].x-=move;
     lastframe=character[GetPlayerCharacter()].frame;
     Vx=fdiv(speed,fmul(int_to_float(character[GetPlayerCharacter()].animspeed),int_to_float(GetGameSpeed())));
     
     
   }else if ((IsKeyPressed(372)!=0)){
     if(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y)== 4){
       if(character[GetPlayerCharacter()].animating==0)AnimateCharacter(GetPlayerCharacter(),5,4,0);
       if(character[GetPlayerCharacter()].frame!=lastframe){
         if(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y-1)==4){
           character[GetPlayerCharacter()].y-=1;
         }else if(GetWalkableAreaAt(character[GetPlayerCharacter()].x+1,character[GetPlayerCharacter()].y)==4){
           character[GetPlayerCharacter()].x+=1;
         }
       }
     }else if(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y)== 5){
       if(character[GetPlayerCharacter()].animating==0)AnimateCharacter(GetPlayerCharacter(),7,4,0);
       if(character[GetPlayerCharacter()].frame!=lastframe){
         if(GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y-1)==5){
           character[GetPlayerCharacter()].y-=1;
         }else if(GetWalkableAreaAt(character[GetPlayerCharacter()].x-1,character[GetPlayerCharacter()].y)==5){
           character[GetPlayerCharacter()].x-=1;
         }
       }
         
     }else if((GetWalkableAreaAt(character[GetPlayerCharacter()].x,character[GetPlayerCharacter()].y) != 0)){
   
   if(float_to_int(speed)<40){
     speed=fadd(speed, ints_to_float(0,500));
     }
   move=fdiv(fmul(speed,int_to_float(scale)),int_to_float(100));
   move=float_to_int(move);
     if(character[GetPlayerCharacter()].animating==0)AnimateCharacter(GetPlayerCharacter(),3,4,0);
   if(character[GetPlayerCharacter()].frame!=lastframe) character[GetPlayerCharacter()].y-=move;
   lastframe=character[GetPlayerCharacter()].frame;
   }
}else{
  ReleaseCharacterView(GetPlayerCharacter());
speed=int_to_float(8 );
}


Any help would be greatly appreciated.

Scorpiorus

QuoteStrangely though the message for the character's current walkable area does not always agree with his coordinates.Ã,  When the character is to the far right in the room, the walkable area goes wrong so that he gets stuck.Ã,  This does not seem to occur on the left side of the room.

Can this have something to do with the room being greater than 320 pixels wide (ie. Scrolling when the character walks right (east))?
Yeah, this is because it's a scrolling room. You see, GetWalkableAreaAt expects screen coordinates rather than room coordinates therefore the viewport position must also be taken into account:

int screenX = character[GetPlayerCharacter()].x - GetViewportX();
int screenY = character[GetPlayerCharacter()].y - GetViewportY();

int area = GetWalkableAreaAt(screenX, screenY);

quintaros at work

Thanks,Ã,  Scorpriorus.Ã,  I knew you'd have the answer.

SMF spam blocked by CleanTalk