phinnycupcakes
12-23-2008, 06:49 AM
Hi. I'm making a platform like game based on this tutorial
http://www.kirupa.com/developer/mx2004/platform_game.htm
The thing is, with this tutorial, you die in one hit. I want it to be so that when you hit an enemy, you lose a life, and it sets you back a few units from the enemy.
Here is the code in question. It is attached to the enemy's movieclip code.
if (this.hitTest(_root.char) && !dead) {
// if this hits the character and is not dead
_root.char.jumping = false;
// characters jumping state is set false
_root.dead = true;
// _root.dead is set true
}
Really easy to fix, huh? I've tried this
if (this.hitTest(_root.char) && !dead) {
if(_root.health == 0)
_root.dead = true;
else
{
_root.char.jumping = false;
// characters jumping state is set false
_root.char._x -= this._x - 20;
// move him to the left a little bit
_root.health -= 20;
// subtract 20 health, effectively saying he got hit.
}
}
All that does is makes the character move back, but only for an instant, and then he's back to the enemy. Why does this happen? It's because the stage follows the character funny. (the illusion of a camera focusing on the character I guess..)
onClipEvent (enterFrame) {
//////////////////////
////Ammendment 2//
//////////////////
_x = Xpos-_root._x;
//sets the X pos to the starting X postition of this MC
_root.score._x = scoreX-_root._x;
//sets the scire MCs X pos to its starting point on the screen
_root.health._x = healthX-_root._x;
//sets the health MCs X pos to its starting point on the screen
if (!_root.ground.hitTest(this._x, this._y, true) && !jumping) {
// if NOT hitting X and Y postion with the ground and NOT jumping
this._y += 6;
// Y positon moves up 6
}
So how can I get around this so that the character jumps back, and not everything in _root follows him??
I was thinking of making Everything in _root move to the left, and having the enemy move the same amount to the right, thus canceling out him moving, but what THIS does is it screws up the number of steps he has taken (a key factor of making him move left and right). In fact, this would screw up pretty much EVERY enemy if their code is based on numbers of steps taken.. Enemies would be flying off screen and such.
someone help me out! =o
Just download the FLA file on the website I gave you, and fiddle around a bit.
I hope you guys can help me out!!!! =DDD
http://www.kirupa.com/developer/mx2004/platform_game.htm
The thing is, with this tutorial, you die in one hit. I want it to be so that when you hit an enemy, you lose a life, and it sets you back a few units from the enemy.
Here is the code in question. It is attached to the enemy's movieclip code.
if (this.hitTest(_root.char) && !dead) {
// if this hits the character and is not dead
_root.char.jumping = false;
// characters jumping state is set false
_root.dead = true;
// _root.dead is set true
}
Really easy to fix, huh? I've tried this
if (this.hitTest(_root.char) && !dead) {
if(_root.health == 0)
_root.dead = true;
else
{
_root.char.jumping = false;
// characters jumping state is set false
_root.char._x -= this._x - 20;
// move him to the left a little bit
_root.health -= 20;
// subtract 20 health, effectively saying he got hit.
}
}
All that does is makes the character move back, but only for an instant, and then he's back to the enemy. Why does this happen? It's because the stage follows the character funny. (the illusion of a camera focusing on the character I guess..)
onClipEvent (enterFrame) {
//////////////////////
////Ammendment 2//
//////////////////
_x = Xpos-_root._x;
//sets the X pos to the starting X postition of this MC
_root.score._x = scoreX-_root._x;
//sets the scire MCs X pos to its starting point on the screen
_root.health._x = healthX-_root._x;
//sets the health MCs X pos to its starting point on the screen
if (!_root.ground.hitTest(this._x, this._y, true) && !jumping) {
// if NOT hitting X and Y postion with the ground and NOT jumping
this._y += 6;
// Y positon moves up 6
}
So how can I get around this so that the character jumps back, and not everything in _root follows him??
I was thinking of making Everything in _root move to the left, and having the enemy move the same amount to the right, thus canceling out him moving, but what THIS does is it screws up the number of steps he has taken (a key factor of making him move left and right). In fact, this would screw up pretty much EVERY enemy if their code is based on numbers of steps taken.. Enemies would be flying off screen and such.
someone help me out! =o
Just download the FLA file on the website I gave you, and fiddle around a bit.
I hope you guys can help me out!!!! =DDD