Be a Supporter!

As2 Hittest And Variable Help

  • 298 Views
  • 2 Replies
New Topic Respond to this Topic
FortressRubbish
FortressRubbish
  • Member since: Jan. 31, 2009
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
As2 Hittest And Variable Help 2009-03-25 14:22:10 Reply

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.

http://spamtheweb.com/ul/upload/2503...e loaderewd.php

Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to As2 Hittest And Variable Help 2009-03-25 15:03:44 Reply

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.
Forum Stats
Member
Level 46
Blank Slate
Response to As2 Hittest And Variable Help 2009-03-25 15:11:52 Reply

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);
	}
}

- - Flash - Music - Images - -

BBS Signature