PDA

View Full Version : health bar



binime
October 25th, 2004, 08:46 AM
hey! i have started to make a game, nothing to complicated. so far i am using two squares just to test it out. i have two dynamic text boxes, one for health and one for score. i also have a little bar which width is equal to the _root.health part. my code



_root.health = 100;
_root.score = 0;
if (_root.health<=0) {
gotoAndStop(2);
}
stop();



this code is on the first frame off my game. on one of my squares i have the following code (its just to test for the health and score btw)



onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN)) {
this._y += 5;
} else if (Key.isDown(Key.RIGHT)) {
this._x += 5;
}
if (this.hitTest(_root.box)) {
_root.box.removeMovieClip();
_root.score += 1000;
_root.health -= 30;
stop();
}
}


now i have made another frame so that my intention is if the health is less than or equal to 0 it will go to it, but it doesnt. can somebody please help me or point me in the right direction? any help would be much appreciated
~binime

Dr Warm
October 25th, 2004, 09:05 AM
does any of it work or does it just not go to the final screen, i suspect this is because ur code in the main timeline:



_root.health = 100;
_root.score = 0;
if (_root.health<=0) {
gotoAndStop(2);
}
stop();
</pre> only gets checked once at the start, so u should have



_root.health = 100;
_root.score = 0;
_root.onEnterFrame = function(){
if (_root.health<=0) {
gotoAndStop(2);
}
}
stop(); </pre> see if that works

binime
October 25th, 2004, 09:08 AM
thankyou! works fine now! it all did work apart from this and

_root.box.removeMovieClip();

thanks for the quick reply! now only the removeMovieClip doesnt work

Dr Warm
October 25th, 2004, 09:57 PM
now only the removeMovieClip doesnt work i 'm not sure but i thought u could only remove a movie clip when u attach it first, using attachMovie methed, otw have in the box(under a clip event):


[/php]if (this.hitTest(_root.square)) {
this.removeMovieClip();
}[php]
</pre>

binime
October 26th, 2004, 04:10 AM
i already had that code on the one square, but i tried with something else and it worked! :D thanks a load!