As2 Hittest And Variable Help
- FortressRubbish
-
FortressRubbish
- Member since: Jan. 31, 2009
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
Okay, so I'm developing my first solo game.
I've got code so that you have 10 lives.
but while the enemy is touching you you lose them equal to the framerate.
onClipEvent(enterFrame){
if (_root.player.hitTest(this)){
_root.lives --;
}
}
how do I make it so you can only lose one life per hit?
Also, I've been trying to code temporary invulnerability when the player is hurt, so they have time to recover. I have no idea how to implement this haha. Can anyone shine some light in this direction on that? I'd REALLY appreciate any help I can get, as I'm very new to all this coding business.
Here's a demo of the game if you'd like to play it to get a feel for what I'm talking about.
- Sam
-
Sam
- Member since: Oct. 1, 2005
- Offline.
-
- Forum Stats
- Moderator
- Level 19
- Programmer
onClipEvent(load){
i=0
}
onClipEvent(enterFrame){
if (_root.player.hitTest(this)){
if(i<1){
_root.lives --;
i++
} else {
i=0
}
}
} - Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
On MC:
onClipEvent(enterFrame){
if(_root.player.hitTest(this)){
_root.GOTHIT();
}
}
On main timeline:
invulnerable=0; //BOOLEAN
invTime=1.5; //NUMBER OF SECONDS' INVULNERABILITY
function GOTHIT(){
if(!invulnerable){
invulnerable=1;
lives--;
clearTimeout(fff);
fff=setTimeout(function(){invulnerable=0;},invTime*1000);
}
} 

