Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: JimmyD on Wed 03/09/2008 20:26:04

Title: Running with the keyboard...
Post by: JimmyD on Wed 03/09/2008 20:26:04
I'm making a situation in which the character is moved using the keyboard (press, rather than tap), and am trying to implement a system of running when a different key is held along with the direction arrow. From what I've read of a several year old thread, the animation needs to pause briefly before character speed can be changed.

Couple of things - the previous thread came from the days before the KeyboardMovement module came with AGS. Should I be making the additional script within the KeyboardMovement module, or in repeadtedly_execute?

I'm sure I'll get this scripting lark figured out eventually!
Title: Re: Running with the keyboard...
Post by: JimmyD on Thu 04/09/2008 17:45:38
Well, I've found a semi-solution to my problem. I've opted to have run and walk as two discrete modes - when you press tab, it shifts between the two, depending on whether the int "running" is 1 or 0. In on_key_press I've put the following in:


  if (keycode == 9 && running == 0) {
    running = 1;
    player.LockView(2);
    player.SetWalkSpeed(8, 8 );
    return;
  }
 
   if (keycode == 9 && running == 1) {
    running = 0;
    player.LockView(1);
    player.SetWalkSpeed(4, 4);
    return;
  }


Basically, this succeeds in changing the view to a running view, and altering the player's speed when tab is pressed.

Is there any way to get around the player standing still when the speed changes, or is that something I'm going to have to work around, like having some kind of slow-to-fast change animation to mask it? Is there a way to set it to work when tab is held, rather than a press?
Title: Re: Running with the keyboard...
Post by: TwinMoon on Thu 04/09/2008 18:49:25
I can help you a little:


if (IsKeyPressed(9) == 1) {
  running = 1;
else {
  running = 0;
}


If you put this code in the repeatedly_execute the variable running will be set to 1 whenever tab is held, and set to 0 when it's not.


And if you want to change his walking speed, you'll have to stop him from moving first. There's no way around it.
However, what you could do is store the co-ordinates the player is walking to. Then you could do something like:

running = 1;
player.StopMoving();
player.SetWalkSpeed(8,8);
player.ChangeView(playerRunning);
player.Walk(movetox, movetoy);


(in which movetox and movetoy are the co-ordinates stored)