Skip to main content
Known Participant
September 16, 2010
Question

Having trouble with a game

  • September 16, 2010
  • 1 reply
  • 507 views

I'm having trouble trying to get the enemy character in a game to attack once and then over again. Right now it's not going through the whole attack animation. If anyone has any ideas that would be great. the site is here:

http://billzgames.comule.com/

and heres the code

//in an enemy attack function-

if (Math.abs(this.x - thePlayerX) < 80 && Math.abs(this.y - thePlayerY) < 20) {

EnemySpeed = 0;

if(Math.round(Math.random()*enemyHitDiff) == 1)

{

attack = true;

enemyFight();

}else attack = false;

private function enemyFight(){

if ((attack == true)&&(faceLeft == true)) {

animstep += 1;

if (animstep > attackLeftAnimation.length-1) {

animstep = 0;

}

gotoAndPlay(attackLeftAnimation[(animstep)]);

if(attackLeftAnimation[(animstep)]>14){

attack = false;

}

}else if ((attack == true)&&(faceRight == true)) {

animstep += 1;

if (animstep > attackRightAnimation.length) {

animstep = 0;

}

gotoAndPlay(attackRightAnimation[(animstep)]);

if(attackRightAnimation[(animstep)]>14){

attack = false;

}

}

}

Thank you

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
September 16, 2010

Having your code all spread out like that makes it difficult to read... But based on what is shown, it almost appears as if you have all of that code nested into a conditional statement.  Is that the case?  I would not nest a function definition in there.

From what I can make out, by itself that code will only execute once, so are you doing anything to make it execute "over again"?

Known Participant
September 16, 2010

Yes the first function is called in an onEnterFrame function.