Welcome Guest [Log In] [Register]
Welcome to Brackenwood. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Game Fine Tuning; Just a few bugs...
Topic Started: Mar 12 2006, 09:35 AM (156 Views)
BonzaiRob
Member Avatar
The Demon Plasterer
Sickman Fight!

This is my basic, uh, engine for a fighting game. Pretty basic at the moment - controls (left, right, jump, attack) are ADWF for player 1 (blue) and Left, Right, Up and Control for P2 (red).

Each stickman is 12 frames - LR idle, LR run, LR punch, centre jump, LR jump, LR kick, and explode. The code in each is this:
Code:
 
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
 facing = 0;
} else if (Key.isDown(Key.RIGHT)) {
 facing = 1;
}
}
onClipEvent (keyUp) {
if (facing == 0) {
 this.gotoAndStop(2);
} else {
 this.gotoAndStop(1);
}
}
onClipEvent (load) {
// Set the move speed
moveSpeed = 20;
facing = 1;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
 if (!jumping) {
  this._x += moveSpeed;
  this.gotoAndStop(4);
  if (Key.isDown(Key.CONTROL)) {
   this.gotoAndStop(4);
  }
 } else {
  this._x += moveSpeed;
  this.gotoAndStop(7);
 }
 // Move Right
} else if (Key.isDown(Key.LEFT)) {
 if (!jumping) {
  this._x -= moveSpeed;
  this.gotoAndStop(3);
  if (Key.isDown(Key.CONTROL)) {
   this.gotoAndStop(3);
  }
 } else {
  this._x -= moveSpeed;
  this.gotoAndStop(6);
 }
 // Move Left
}
}
onClipEvent (load) {
jumping = false;
jSpeed = 0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP) && !jumping) {
 jumping = true;
 jSpeed = 10;
 this.gotoAndStop(5);
}
if (jumping) {
 if (Key.isDown(Key.LEFT) or Key.isDown(Key.RIGHT)) {
 } else {
  this.gotoAndStop(5);
 }
 this._y -= jSpeed;
 jSpeed--;
 if (this.hitTest(_root.ground)) {
  jumping = false;
  jSpeed = 0;
  if (facing == 0) {
   this.gotoAndStop(2);
  } else {
   this.gotoAndStop(1);
  }
 }
}
}
onClipEvent (enterFrame) {
if (this._x<20) {
 this._x += 10;
} else if (this._x>530) {
 this._x -= 10;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.CONTROL)) {
 if (jumping == true) {
  if (facing == 0) {
   this.gotoAndStop(11);
  } else if (facing == 1) {
   this.gotoAndStop(10);
  }
 } else if (jumping == false) {
  if (facing == 0) {
   this.gotoAndStop(9);
  } else if (facing == 1) {
   this.gotoAndStop(8);
  }
 }
}
}


And the code for P2's health bar (mirrored for P1):
Code:
 
onClipEvent (enterFrame) {
//punch and kick are small MCs within the animations.
if (_root.player1.punch11.punch1.hitTest(_root.player2) or _root.player1.punch12.punch1.hitTest(_root.player2)) {
//the bar is masked, so it looks like it goes down.
 this._x = this._x-30;
}
if (_root.player1.kick11.kick1.hitTest(_root.player2) or _root.player1.kick12.kick1.hitTest(_root.player2)) {
 this._x = this._x-50;
}
if (this._x<=-250) {
//the exploded frame, when the bar is all gone
 _root.player2.gotoAndStop(12);
}
}


As you will notice if you play it, when one of them dies, if ANY controls are used, they get up, and then explode again when the key is up. They can also move about and jump, but not attack.
I can think or two ways around this, but neither have worked - the first was to put the stickman as he is now in one frame of a new parent MC and nteh explosion in the next frame, but unfortunately now the place they explode is fixed (so if you die as P2 on the left and side, you are telelported back to the starting point).
The other way is to add an 'exploded' variable, as a boolean, and set it to false at the start (I did this in the frame's AS). I then set it so that when they run out of health (above "_root.player2.gotoAndStop(12);") their exploded variable changes to true. Then, I added "if (_root.exploded=false){" in front of all of the Key.isDown clip events. THIS one made them explode at the start.

So.. can anyone think of another way around this? Is there a way to, hm, change it to a Graphic instead of an MC when it explodes?

(BTW, anyone who needs a platformer code, feel free to use it, you just need an MC instance named ground).
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
I think this is the cause of your woes:

Quote:
 
if (this._x<=-250) {
//the exploded frame, when the bar is all gone
_root.player2.gotoAndStop(12);
}


Add a line in there that resets the health when they die, and see if that fixes it.

-edit

Unless you want them to stay dead... then you would delete all code on the player when they die. Something like this:
Quote:
 
if (this._x<=-250) {
//the exploded frame, when the bar is all gone
_root.player2.gotoAndStop(12);
delete(_root.player2.onEnterFrame);
delete(_root.player2.onKeyDown);
delete(_root.player2.onKeyUp);
delete(_root.player2.onLoad);
}

Then again... I don't know if you can delete code when you put it on movie clips...
Offline Profile Quote Post Goto Top
 
BonzaiRob
Member Avatar
The Demon Plasterer
Yeah, I do want them to stay dead (for now, it's simpler to hit refresh to play again). I tried your code in the bar, and also in the AS of frame 12, and neither worked, but thanks :D
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Actionscript · Next Topic »
Add Reply