View Full Version : [AS2] Health Bar Codes
triforceguy1
12-08-2008, 06:18 PM
Hi,
Recently I've been working on a small game that uses a health bar. I have already got these codes:
//Heath Bar Actions
onClipEvent(enterFrame){
this._xscale=_root.HP_Text
if(_root.HP_Text <=0) {
_root.HP_Text=0
}
if(_root.HP_Text >=100){
_root.HP_Text=100
}
if(_root.HP_Text <=0){
nextFrame();
}
}
//Enemy Actions
onClipEvent(enterFrame){
if(_root.Character.hitTest(this)){
_root.HP_Text--
}
}
//Frame Actions
_root.HP_Text=100
But what I want to happen is when the health bar reaches zero it goes onto the next frame and when your character goes over a different object you go to another frame.. Does anyone know the code for that?
Thanks
Leon
triforceguy1
12-08-2008, 07:25 PM
I forgot to ask if anyone knows a code so that I can create walls the character can't go through.
drumn4life0789
12-08-2008, 09:54 PM
if bar = 0
gotoAndStop(Frame 2);
search hittest for wall collision
triforceguy1
12-08-2008, 10:36 PM
Unfortunately I'm kind of new to this, so could you please explain it in detail please, sorry.
Thanks
Leon
Hackor Pickel
12-09-2008, 04:48 PM
how are you moving the character?
i could help you with your walls.
triforceguy1
12-09-2008, 09:11 PM
Like this
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
_y -= 5;
}
if(Key.isDown(Key.DOWN)){
_y += 5;
}
if(Key.isDown(Key.RIGHT)){
_x += 5;
}
if(Key.isDown(Key.LEFT)){
_x -= 5;
}
}
Leon
Hackor Pickel
12-11-2008, 12:31 PM
oh ok, for the walls, use this,(consider that it's not the best code for walls.)
put this on your Wall's actions.
onClipEvent(enterframe){
if(this.hitTest(_root./*Player instance name*/)){
_root./*Player instance name*/._x -=5;//remove the /* and the */ when placing the player's instance name.
}
}
this is for a wall on the right of the player, pushing the player left when it hits the wall.
i don't want you learning nothing now do i?
i'm sure you can figure it out for the rest of the walls?
Hope i helped :D
triforceguy1
12-12-2008, 10:56 AM
Thanks Hackor Pickel, now all I need is the other two, go to next frame when character goes over a certain symbol and go to another frame when health bar reaches zero. Thanks again :)
Hackor Pickel
12-12-2008, 06:39 PM
no problem, glad to help :D
this is your code,
//Heath Bar Actions
onClipEvent(enterFrame){
this._xscale=_root.HP_Text
if(_root.HP_Text <=0) {
_root.HP_Text=0
}
if(_root.HP_Text >=100){
_root.HP_Text=100
}
if(_root.HP_Text <=0){/*the < character is the wrong way i think, i don't know, i just spotted something, not sure :P*/
nextFrame();
}
}
triforceguy1
12-12-2008, 07:03 PM
it's not working :(
Is it suppose to be under the health bar (it is at the moment)
Leon
Hackor Pickel
12-14-2008, 12:11 PM
i'm not sure, i've never done anything invovling health bars, i've had lives, like this:
}
}
if (_root.lives<=0) {
_root.gotoAndStop("survgameover");
this.removeMovieClip();
}
that's a part of a game i made, hope you can use it =]
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.