Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-22-2012, 05:18 PM   #1
gamerjnb925
Registered User
 
Join Date: May 2012
Posts: 5
Default [AS3] health bar

i'm creating a game where enemies come at you and if they reach you you loose a heart (pretty obvious ik lol) but anyways if an enemy reaches me i can get the first heart to dissapear but if another enemy hits me the second heart doesnt dissapear no matter how many enemies hit you. I'll post my code for anyone who thinks they can help me. please and thank you

I'm using actions on the timeline too

if(heart3.visible == true){
var health:int = 3;
}
if(heart3.visible == false){
health = 2;
}
if(heart2.visible == false){
health = 1;
}


this.addEventListener(Event.ENTER_FRAME,hurt);
function hurt(event:Event){
if(enemyWater.x <= 110){
if(health == 3){
heart3.visible = false;
}else if(health == 2){
heart2.visible = false;
}else if(health == 1){
heart1.visible = false;
}
enemyWater.visible = false;
}else if(enemyWater.visible == false){
this.removeEventListener(Event.ENTER_FRAME,hurt);
}
}
this.addEventListener(Event.ENTER_FRAME,hurt1);
function hurt1(event:Event){
if(enemyFire.x <= 110){
if(health == 3){
heart3.visible = false;
}else if(health == 2){
heart2.visible = false;
}else if(health == 1){
heart1.visible = false;
}
enemyFire.visible = false;
}else if(enemyFire.visible == false){
this.removeEventListener(Event.ENTER_FRAME,hurt1);
}
}
this.addEventListener(Event.ENTER_FRAME,hurt2);
function hurt2(event:Event){
if(enemyEarth.x <= 110){
if(health == 3){
heart3.visible = false;
}else if(health == 2){
heart2.visible = false;
}else if(health == 1){
heart1.visible = false;
}
enemyEarth.visible = false;
}else if(enemyEarth.visible == false){
this.removeEventListener(Event.ENTER_FRAME,hurt2);
}
}
this.addEventListener(Event.ENTER_FRAME,hurt3);
function hurt3(event:Event){
if(enemyAir.x <= 110){
if(health == 3){
heart3.visible = false;
}else if(health == 2){
heart2.visible = false;
}else if(health == 1){
heart1.visible = false;
}
enemyAir.visible = false;
}else if(enemyAir.visible == false){
this.removeEventListener(Event.ENTER_FRAME,hurt3);
}
}
gamerjnb925 is offline   Reply With Quote
Old 05-22-2012, 07:06 PM   #2
fatalanth
Registered User
 
Join Date: May 2012
Posts: 5
Default

im making a shooter of a simmilar nature and i have thus far made an "energy bar" of a simmilar nature. Though instead of hearts I use a bar with a tween 100 frames long (for 100% energy)
and what ive done is taken a max energy variable and an energy variable, i multiply the energy variable by 100 then divide it by max energy making a percentage and then i call a gotoAndStop on that frame heres the code:
Code:
function EnterFrame(event:Event):void {
	barplacement = 100 * energy;
	barplacement = barplacement / MaxEnergy;
	energybar.gotoAndStop(barplacement);
obviously its not the full code but it is the important bit for this and again its not exactly what you want but you can make something of the same sort ex: a symbol of 5 hearts for 5 frames in each frame you remove 1 heartand then use a shorter version of that code like:

Code:
function EnterFrame(event:Event):void {
	heartCount = maxHearts - numberOfTimesHit;
             heartbar.gotoAndStop(heartCount);
thats my two cents worth
fatalanth is offline   Reply With Quote
Old 05-25-2012, 02:25 PM   #3
gamerjnb925
Registered User
 
Join Date: May 2012
Posts: 5
Default

thank you so much ill try to implement it in as best i can. good luck to you with your game
gamerjnb925 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:46 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.