Page 1 of 1

enemy AI

PostPosted: Sun Dec 30, 2012 9:04 pm
by BogdansB
hey
im making a gladiator game where you fight against a gladiator enemy. so i made the enemy move to the player in random period of times. now i want when the enemy strikes with his sword (create actor sword) the enemy moves away from the player and when the sword disapears (strike ends) he normaly moves.

how can i move the enemy from the player away?

Re: enemy AI

PostPosted: Sun Dec 30, 2012 9:20 pm
by Hblade
First, make a variable called direct then do the following:

One way you could do this is to make a timer. Then when the timer is finished, have a piece of code like this:
Code: Select all
direct=rand(2);

If I remember correctly, rand(2) mightcreate a random of 0 and 1 (I could be wrong on that, if you don't experience a pause for the gladiator, change the 2 to 3). Now on Draw Actor of the gladiator, do this:
Code: Select all
switch(direct)
{
    case 0:
        xvelocity=-5;
        ChangeAnimation("Event Actor", "Walk Left", NO_CHANGE); //this code wont work you have to do it manually. make sure its set at NO_CHANGE and not forward
    break;
    case 1:
        xvelocity=5;
        ChangeAnimation(...); //walk right
    break;
    case 2:
        xvelocity=0;
        //have him stop motion here. you can
        //use animindex to determin what animation
        //he's in then use that to change his animation
        //to stopped.
    break;
}


That should allow him to move randomly about the stage. If you want him to locate the player, you'd do this:
Code: Select all
if(x<player.x) {
xvelocity=5;
}

This will make him go right if the player is to the right of him.
Code: Select all
if(x>player.x) {
xvelocity=-5;
}

This will make him go left if the player is to the left of him.

Re: enemy AI

PostPosted: Sat Jan 05, 2013 6:00 pm
by BogdansB
thank you

Re: enemy AI

PostPosted: Sat Jan 05, 2013 7:00 pm
by Hblade
your welcome :)