How to complete a Walk without eBlock

Started by Sydrik, Sat 13/11/2010 15:20:04

Previous topic - Next topic

Sydrik

cZombie is currently at x-y coordinates (100, 50). I want him to walk to (500, 50) and then do an animation.

Thus I do this (assuming the View is properly set):

Code: ags
cZombie.Walk(500, 50, eBlock);
cZombie.Animate(3, 1);


However, I need the player to STILL be able to click around while cZombie is walking. With eBlock up, that's not going to happen as the game will wait for the walking to be done first.

If I do this:

Code: ags
cZombie.Walk(500, 50, eNoBlock);
cZombie.Animate(3, 1);


cZombie doesn't walk a step, and his animation begins immediately.

Is there a way to make cZombie make his required journey, at the same time, let the player still click around (like stab him) before he makes that animation?

Note: I cannot use regions for cZombie to walk there and only execute his animation after stepping on it, because there are going to be many more zombies in the room, and they are supposed to make random distances (and directions).

Thanks!

Matti

#1
Either check if cZombie is at the target coordinates and THEN do the animation or set a variable when he starts walking and check the variable when he isn't walking anymore. I think the latter would be the way to go as it could happen that he isn't stopping at the exact target coordinates.

Edit:

Code: ags

cZombie.Walk(500, 50, eNoBlock);
ZombieAni = true;


Code: ags

if (!cZombie.Moving && ZombieAni){
  ZombieAni = false;
  cZombie.Animate(3, 1);
}

Khris

Yep, and it case this isn't obvious, the code to do that should go into the room's repeatedly_execute event / function.

Sydrik


Sydrik

Quote from: Khris on Sat 13/11/2010 15:35:35
Yep, and it case this isn't obvious, the code to do that should go into the room's repeatedly_execute event / function.

Oh dear. Another problem creeps up. cZombie's animation also has to be eBlock to watch the entire sequence. I need to still be able to click around (or stab the zombie!!) while the animation is still in progress.

Putting it in repeatedly_execute will let us only see the first frame of the loop as it refreshes real quickly without blocking.

Appreciate your advise how to get around this.

Khris

You have to code this in a way that the animation is only started once.

Characters have an .Animating property, e.g. this would work:

Code: ags
  if (!cZombie.Animating) cZombie.Animate(...);


This will of course restart the animation as soon as it is finished because then cZombie.Animating is reset to false.
I'd use a variable for each zombie to store their state. E.g. a state of 0 means the zombie does nothing, 1 means he's walking somewhere, etc.

Sydrik


SMF spam blocked by CleanTalk