enemy AI

Talk about making games.

enemy AI

Postby BogdansB » Sun Dec 30, 2012 9:04 pm

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?
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: enemy AI

Postby Hblade » Sun Dec 30, 2012 9:20 pm

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.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: enemy AI

Postby BogdansB » Sat Jan 05, 2013 6:00 pm

thank you
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: enemy AI

Postby Hblade » Sat Jan 05, 2013 7:00 pm

your welcome :)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest