Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mehrdad on Wed 08/10/2014 11:26:20

Title: Keyboard movement problem
Post by: Mehrdad on Wed 08/10/2014 11:26:20
Hi
I'm making a platformer and I use 0 and 1 to 'k' for simple gravity
Code (ags) Select
int k = GetWalkableAreaAt (cCharacter.x-GetViewportX(), cCharacter.y-GetViewportY());
Also I use KeyboardMovement module too for combine walking and turn character.As this module don't support out of walkable area I use this code:
Code (ags) Select
  if ((IsKeyPressed(eKeyLeftArrow)==true)&&(IsKeyPressed(eKeyRightArrow)!=true)) cCharacter.x-=1;
  if ((IsKeyPressed(eKeyRightArrow)==true)&&(IsKeyPressed(eKeyLeftArrow)!=true)) cCharacter.x+=1;

Everything is ok but if I press left or right and falling to down and stand up without release left or right key, character glide without walking and when release keyboard it's fine and character continue walking without glide.
How can i fix it?
I'm Appreciate for any help
Title: Re: Keyboard movement problem
Post by: Vincent on Wed 08/10/2014 12:29:34
I'm certainly the last person on this forum who can give advice.

But a single boolean could make the difference..

Code (ags) Select

bool on_ground = true;
Title: Re: Keyboard movement problem
Post by: Mehrdad on Wed 08/10/2014 16:20:09
Sorry but I used boolean too.My main problem is when press left or right key without release it after falling and stand up.that I have glide instead walking.If I release key anythings is normal.
I think I have to disable line 1 and 2 when I have play animation falling and stand up and after that I enable it.or disable left or right key when I have falling or stand up. But  unfortunately I don't know how can I write it.
Title: Re: Keyboard movement problem
Post by: arj0n on Wed 08/10/2014 16:42:06
Maybe add a view check?
Title: Re: Keyboard movement problem
Post by: Adeel on Wed 08/10/2014 16:45:30
Quote from: Mehrdad on Wed 08/10/2014 16:20:09
I think I have to disable line 1 and 2 when I have play animation falling and stand up and after that I enable it.or disable left or right key when I have falling or stand up. But  unfortunately I don't know how can I write it.

Hello Mehrdad. Try using Character.Animating Property. If I understand it correctly, this might be what you're looking for.

E: If you don't mind, can you please post that part of the script where the character performs the animation?
Title: Re: Keyboard movement problem
Post by: Mehrdad on Thu 09/10/2014 05:45:40
Yes of course.This is my code
Code (ags) Select

KeyboardMovement.SetMode(eKeyboardMovement_Pressing);
}
  bool l = true;
  bool faceM = 1; // direction left or right
// put anything you want to happen every game cycle in here
function repeatedly_execute()
{
  int k = GetWalkableAreaAt (cCharacter.x-GetViewportX(), cCharacter.y-GetViewportY());


   //Left and Right

  if ((IsKeyPressed(eKeyLeftArrow)==true)&&(IsKeyPressed(eKeyRightArrow)!=true)){ cCharacter.x-=1;faceM=0;}
  if ((IsKeyPressed(eKeyRightArrow)==true)&&(IsKeyPressed(eKeyLeftArrow)!=true)){ cCharacter.x+=1;faceM =1;}
 
  //Falling and Stand up
  if  ((k == 0)&&(l==true)){if(faceM==1){ cCharacter.LockView(2);
  cCharacter.Animate(1, 0, 0, eBlock, eForwards);cCharacter.UnlockView();l=false;}}
  if  ((k == 0)&&(l==false)){if(faceM==1){ cCharacter.LockView(2);
  cCharacter.Animate(2, 0, 0, eBlock, eForwards);cCharacter.y+=10;cCharacter.UnlockView();}}
  if ((k == 1)&&(l==false)) {l=true;if(faceM==1){cCharacter.LockView(2);
  cCharacter.Animate(3, 0, 0, eBlock, eForwards);cCharacter.UnlockView();cCharacter.Walk(cCharacter.x+2, cCharacter.y, eBlock);}else if(faceM==0)
  {cCharacter.LockView(2);
  cCharacter.Animate(10, 0, 0, eBlock, eForwards);cCharacter.UnlockView(); cCharacter.Walk(cCharacter.x-2, cCharacter.y, eBlock);}}
 
  if  ((k == 0)&&(l==true)) {if(faceM==0){ cCharacter.LockView(2);
  cCharacter.Animate(8, 0, 0, eBlock, eForwards);cCharacter.UnlockView();l=false;}}
  if  ((k == 0)&&(l==false)){if(faceM==0){ cCharacter.LockView(2);
  cCharacter.Animate(9, 0, 0, eBlock, eForwards);cCharacter.y+=10;cCharacter.UnlockView();}}



loop 1,2,3 is: ready to falling,fall,stand up for right
loop 8,9,10 is:ready to falling,fall,stand up for left
Title: Re: Keyboard movement problem
Post by: Mehrdad on Fri 10/10/2014 07:02:19
OK
Problem solved but not complete.That take many times.It's enough for me at the moment.
And another question about moving.I used walkable area with 'int k' for horizontal obstacle(please see first post). Is it possible use same walkable area for left and right obstacle? My mean is character go to stop when collision with walkable area.
appreciate for any help or suggestions     
Title: Re: Keyboard movement problem
Post by: Cassiebsg on Fri 10/10/2014 18:35:50
Quote from: Mehrdad on Fri 10/10/2014 07:02:19
My mean is character go to stop when collision with walkable area.
appreciate for any help or suggestions     

Wouldn't regions work?