Increasing walk speed by player control

Started by jamesreg, Mon 15/02/2010 20:11:38

Previous topic - Next topic

jamesreg

I want to be able to set up the "+" and "-" keys to increase or decrease a characters walk speed.

how would I go about doing this im sure I have to put it in the global script

Ethan D

This should work
Code: ags

function on_key_press(eKeyCode keycode) 
{
if (keycode == eKeyPlus)
  {
  cEgo.SetWalkSpeed(cEgo.WalkSpeedX + 1, cEgo.WalkSpeedY + 1); 
  }
  if (keycode == eKeyHyphen)
  {
  cEgo.SetWalkSpeed(cEgo.WalkSpeedX - 1,  cEgo.WalkSpeedY -1);
  }
}

tzachs

There's a problem with that, because AFAIK there's a limitation in AGS that says you can't set the walkspeed of a character while he is walking.
I don't know of an easy way to make it to work... you can do it so that only if the character is not moving his walkspeed will change by changing ethan's code like this:
Code: ags

 function on_key_press(eKeyCode keycode) 
{
if (keycode == eKeyPlus && !cEgo.Moving)
  {
  cEgo.SetWalkSpeed(cEgo.WalkSpeedX + 1, cEgo.WalkSpeedY + 1); 
  }
  if (keycode == eKeyHyphen && !cEgo.Moving)
  {
  cEgo.SetWalkSpeed(cEgo.WalkSpeedX - 1,  cEgo.WalkSpeedY -1);
  }
}

Another thing you can do (but it can be quite irritating for the user) is to stop the character from moving and then change it's walkspeed, like this:
Code: ags

function on_key_press(eKeyCode keycode) 
{
if (keycode == eKeyPlus)
  {
  cEgo.StopMoving();
  cEgo.SetWalkSpeed(cEgo.WalkSpeedX + 1, cEgo.WalkSpeedY + 1); 
  }
  if (keycode == eKeyHyphen)
  {
  cEgo.StopMoving();
  cEgo.SetWalkSpeed(cEgo.WalkSpeedX - 1,  cEgo.WalkSpeedY -1);
  }
}

Ethan D

#3
I never knew that, is there a way to get what the current x and y coordinates are that the character is walking to.  If so you could add that in right after the change in speed and the pause would be hardly noticeable if it is noticeable at all.

I can't seem to find anything though.

EDIT:  Try this:

First add this into the on left mouse click section of the global script

Code: ags

if (mouse.Mode == eModeWalkto)
    {
      variable = mouse.x
      variable2 = mouse.y
    }

Then add to the original change speed script

Code: ags

function on_key_press(eKeyCode keycode) 
{
if (keycode == eKeyPlus)
  {
  cEgo.StopMoving();
  cEgo.SetWalkSpeed(cEgo.WalkSpeedX + 1, cEgo.WalkSpeedY + 1); 
  cEgo.Walk(Variable, Variable2);
  }
  if (keycode == eKeyHyphen)
  {
  cEgo.StopMoving();
  cEgo.SetWalkSpeed(cEgo.WalkSpeedX - 1,  cEgo.WalkSpeedY -1);
  cEgo.Walk(Variable,Variable2);
  }
}


As long as a mouse click caused the initial movement this should work just fine.

tzachs

Not that I know of...
You can write an extender method for walk that will save the target x&y and then use it, but you'll have to remember using it in the entire game, and it can get complicated...

jamesreg

I fixed it so that the character stops moving to avoid the not allowed while walking error
but now there is another problem if you press + or - to many times and slow it down to much or speed it up to much
there is a limit to this as well and it will crash the game when exceded is there a way to make it stop before that point

Ethan D

This should work for the minus.

if (keycode == eKeyHyphen && cEgo.WalkSpeedX != 1)

I don't think there is a maximum walk speed but if you want to set it it would work the same way

jamesreg

Quote from: Ethan Damschroder on Mon 15/02/2010 20:58:56
This should work for the minus.

if (keycode == eKeyHyphen && cEgo.WalkSpeedX != 1)

I don't think there is a maximum walk speed but if you want to set it it would work the same way

do I put this in the same script? and other then the cego name does it need be edit any ?

tzachs

Just replace it with the

if (keycode == eKeyHyphen)

in the previous script...

SMF spam blocked by CleanTalk