Be a Supporter!

Invincibility frames and hurting

  • 290 Views
  • 3 Replies
New Topic Respond to this Topic
RyuXKen
RyuXKen
  • Member since: Nov. 8, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Invincibility frames and hurting May. 4th, 2012 @ 06:08 AM Reply

Hey guys, so I'm working on an action platformer game and my biggest hurdle right now is hit detection. I have the code for things, but none of the code gets carried out in the if statement unless its "_root.nextFrame();"

Maybe you guys could shed some light on the situation?

My biggest problem right now is when something hits the player, Things happen, because I'm using the trace function and I'm receiving outputs. However when I want the player getting hit to affect something else, thats where things get weird.
It also doesn't let me play the getting hurt and invincibility animation. I have ryu throwing fireballs, but while the fireballs pass through the player it registers 3 times. so Hearts decrease from 3 - 0 in one shot, which is why I'm assuming getting hurt and invincibility is important. (I'm using hearts cause I'm bad with life bars.)
I feel like my main issues come from declaring variables in the main timeline, vs in movie clips. and vice versa.

This code is in my "player" movie clip, along with his movement code and gravity.

//FIREBALLSCRIPT
//_root.invincibility -=1;
if (this.hitTest(_root.eryu.fireball) /*&& _root.invincibility < 1)*/){
//_root.heart -= 1;
//_root.prevFrame();
_root.player.gotoAndStop(7);
//_root.invincibility += 40;
}
//Lifebar script?
if (_root.heart <= 2) {
_root.lifebar.gotoAndPlay("two");
}
if (_root.heart <= 1){
_root.lifebar.gotoAndPlay("one");
}
I declared _root.heart and _root.invincibility in the first frame, on the timeline.

Any help is greatly appreciated, and yeah, I know I'm going to be flamed for using AS2!

RyuXKen
RyuXKen
  • Member since: Nov. 8, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Invincibility frames and hurting May. 4th, 2012 @ 05:06 PM Reply

Bump of hope?

RyuXKen
RyuXKen
  • Member since: Nov. 8, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Invincibility frames and hurting May. 5th, 2012 @ 02:57 PM Reply

At 5/5/12 07:10 AM, ClockworkSpace wrote: Couldn't you make a single heart worth 3 hits?

Gasp, you're a genius! However I'm concerned about other projectiles or hurtboxes that might last longer than the fireball.
because it subtracts for however long the player is touching that object :/

not sure how to get around this.

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Invincibility frames and hurting May. 5th, 2012 @ 04:03 PM Reply

Ok, so you want to create hit invisibly so once you get it by a fireball you're invisible for X frames? This is how I would do it, including functions to simplify.

//_fireball is the fireball _player is the player.

onEnterFrame = function() //Start enterframe
{
	if (_fireball.hitTest(_player)) { hitPlayer(5, 10); } // Check if the player is getting hit by a fireball, if so run the hit function

	if (_player.invincibleFrames > 0) { _player.invincibleFrames--; } // Remove one frame of invincibility if there's any left
}


function hitPlayer(damage:Number, hitInvincibility:Number) // Function to handle damage, need damgae and invincibility parameters
{
	if (_player.invincibleFrames > 0) return; // If the player has invincibile frames left then end the function without computing damage
	
	_player.health -= damage; // Hurt the player
	if (_player.health <= 0) { _player.die(); } // If he has less then 0 health kill him
	
	_player.invincibleFrames += hitInvincibility; // An some hit invincibility.
}

Complete with comments, helps?

Also I wouldn't write "if (_fireball.hitTest(_player))" I'd obvious use some kind of loop to search for any attacks hitting the player and hitPlayer() accordingly.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature