Highlighted

Virtual Pet Health Bar (AS3) Codes

New Here ,
Jul 20, 2019

Copy link to clipboard

Copied

Hi, I'm asking for help for my Virtual Pet Heath Bar in Animate CC (Actionscript 3)

Thank you in Advance

*My problem I want to add a function that declares health to automatically decreases.

*I want also to increase the status with the current HP.

here's are my codes:

var maxHP:int = 100;

var currentHP:int= maxHP;

var percentHP:Number = currentHP / maxHP;

var healthPercent: Number=100;

var health: Number = 1;

function updateHealthBar():void

{

  percentHP = currentHP / maxHP;

  lifeBar3.barColor3.scaleX = percentHP;

  health=health+10;

  trace(health);

  healthPercent=health/100;

  trace(healthPercent);

  lifeBar1.barColor1.scaleX=healthPercent;

}

play_btn.addEventListener(MouseEvent.CLICK, decreaseClicked);

function decreaseButtonClicked(e:MouseEvent):void

{

  currentHP -= 10;

  if(currentHP <= 0)

  {

  currentHP = 0;

  gotoAndPlay ("takebath");

  }

  updateHealthBar();

}

TOPICS
Discussions

Views

152

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Virtual Pet Health Bar (AS3) Codes

New Here ,
Jul 20, 2019

Copy link to clipboard

Copied

Hi, I'm asking for help for my Virtual Pet Heath Bar in Animate CC (Actionscript 3)

Thank you in Advance

*My problem I want to add a function that declares health to automatically decreases.

*I want also to increase the status with the current HP.

here's are my codes:

var maxHP:int = 100;

var currentHP:int= maxHP;

var percentHP:Number = currentHP / maxHP;

var healthPercent: Number=100;

var health: Number = 1;

function updateHealthBar():void

{

  percentHP = currentHP / maxHP;

  lifeBar3.barColor3.scaleX = percentHP;

  health=health+10;

  trace(health);

  healthPercent=health/100;

  trace(healthPercent);

  lifeBar1.barColor1.scaleX=healthPercent;

}

play_btn.addEventListener(MouseEvent.CLICK, decreaseClicked);

function decreaseButtonClicked(e:MouseEvent):void

{

  currentHP -= 10;

  if(currentHP <= 0)

  {

  currentHP = 0;

  gotoAndPlay ("takebath");

  }

  updateHealthBar();

}

TOPICS
Discussions

Views

153

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 20, 2019 0
Adobe Community Professional ,
Jul 20, 2019

Copy link to clipboard

Copied

Hi.

Your code lowers the size of one bar and rises the size of the other.

I didn't get exactly what you want to achieve... Can you explain in another way?

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 20, 2019 0
Adobe Community Professional ,
Jul 20, 2019

Copy link to clipboard

Copied

Oh... Another thing.

Your event handler function is not named correctly.

When you add the event listener, you called it decreaseClicked.

But then you declared it with the name decreaseButtonClicked.

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 20, 2019 1
New Here ,
Jul 24, 2019

Copy link to clipboard

Copied

I'm looking for a health bar that automatically decreases and after you click the button it minus the current HP. Thank you and another thing when the bar is empty it will declare game over frame.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0
Adobe Community Professional ,
Jul 24, 2019

Copy link to clipboard

Copied

Hi again.

Should your health bar decrease automatically over time or just when the button is clicked?

And another thing that is confusing me... Do you have different bars for health and for HP?

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0
New Here ,
Jul 24, 2019

Copy link to clipboard

Copied

Oh, No I don't have, that is my problem I want my health bar to decrease over time but I don't have a code with that yet.

Here are my current code.

playApple.visible = true;

//playApple.addEventListener(MouseEvent.CLICK, toApple);

var maxHP:int = 100;

var currentHP:int= maxHP;

var percentHP:Number = currentHP / maxHP;

var healthPercent: Number=100;

var health: Number = 1;

function updateHealthBar():void

{

  percentHP = currentHP / maxHP;

  lifeBar3.barColor3.scaleX = percentHP;

  health=health+10;

  trace(health);

  healthPercent=health/100;

  trace(healthPercent);

  lifeBar1.barColor1.scaleX=healthPercent;

}

playApple.addEventListener(MouseEvent.CLICK, attackButtonClicked);

function attackButtonClicked(e:MouseEvent):void

{

  currentHP -= 10;

  if(currentHP <= 0)

  {

  currentHP = 0;

  gotoAndPlay ("takebath");

  

  }

  updateHealthBar();

}

playOrange.visible = true;

//playApple.addEventListener(MouseEvent.CLICK, toApple);

var maxHP1:int = 100;

var currentHP1:int = maxHP1;

var percentHP1:Number = currentHP1 / maxHP1;

var health1: Number = 1;

var healthPercent1: Number=100;

function updateHealthBar1():void

{

  percentHP1 = currentHP1 / maxHP1;

  lifeBar3.barColor3.scaleX = percentHP1;

  health1=health1+10;

  trace(health1);

  healthPercent1=health1/100;

  trace(healthPercent1);

  lifeBar1.barColor1.scaleX=healthPercent1;

}

playOrange.addEventListener(MouseEvent.CLICK, attackButtonClicked1);

function attackButtonClicked1(e:MouseEvent):void

{

  currentHP1 -= 10;

  if(currentHP1 <= 0)

  {

  currentHP1 = 0;

  gotoAndPlay ("takebath");

  }

  updateHealthBar1();

}

playBanna2.visible = true;

//playApple.addEventListener(MouseEvent.CLICK, toApple);

var maxHP2:int = 100;

var currentHP2:int = maxHP2;

var percentHP2:Number = currentHP2 / maxHP2;

var health2: Number = 1;

var healthPercent2: Number=100;

function updateHealthBar2():void

{

  percentHP2 = currentHP2 / maxHP2;

  lifeBar3.barColor3.scaleX = percentHP2;

  health2=health2+10;

  trace(health2);

  healthPercent2=health2/100;

  trace(healthPercent2);

  lifeBar1.barColor1.scaleX=healthPercent2;

}

playBanna2.addEventListener(MouseEvent.CLICK, attackButtonClicked2);

function attackButtonClicked2(e:MouseEvent):void

{

  currentHP2 -= 10;

  if(currentHP2 <= 0)

  {

  currentHP2 = 0;

  gotoAndPlay ("takebath");

  }

  updateHealthBar2();

}

playBone.visible = true;

//playApple.addEventListener(MouseEvent.CLICK, toApple);

var maxHP3:int = 60;

var currentHP3:int = maxHP3;

var percentHP3:Number = currentHP3 / maxHP3;

var health4: Number = 1;

var healthPercent4: Number=100;

function updateHealthBar3():void

{

  percentHP3 = currentHP3 / maxHP3;

  lifeBar3.barColor3.scaleX = percentHP3;

  health4=health4+10;

  trace(health4);

  healthPercent4=health4/100;

  trace(healthPercent4);

  lifeBar1.barColor1.scaleX=healthPercent4;

}

playBone.addEventListener(MouseEvent.CLICK, attackButtonClicked3);

function attackButtonClicked3(e:MouseEvent):void

{

  currentHP3 -= 15;

  if(currentHP3 <= 0)

  {

  currentHP3 = 0;

  gotoAndPlay ("takebath");

  }

  updateHealthBar3();

}

playBurger.visible = true;

//playApple.addEventListener(MouseEvent.CLICK, toApple);

var maxHP4:int = 100;

var currentHP4:int = maxHP4;

var percentHP4:Number = currentHP4 / maxHP4;

var health5: Number = 1;

var healthPercent5: Number=100;

function updateHealthBar4():void

{

  percentHP4 = currentHP4 / maxHP4;

  lifeBar3.barColor3.scaleX = percentHP4;

  health5=health5+10;

  trace(health5);

  healthPercent5=health5/100;

  trace(healthPercent5);

  lifeBar1.barColor1.scaleX=healthPercent5;

}

playBurger.addEventListener(MouseEvent.CLICK, attackButtonClicked4);

function attackButtonClicked4(e:MouseEvent):void

{

  currentHP4 -= 20;

  if(currentHP4 <= 0)

  {

  currentHP4 = 0;

  gotoAndPlay ("takebath");

  }

  updateHealthBar4();

}

playDogfood.visible = true;

//playApple.addEventListener(MouseEvent.CLICK, toApple);

var maxHP5:int = 100;

var currentHP5:int = maxHP5;

var percentHP5:Number = currentHP5 / maxHP5;

var health6: Number = 1;

var healthPercent6: Number=100;

function updateHealthBar5():void

{

  percentHP5 = currentHP5 / maxHP5;

  lifeBar3.barColor3.scaleX = percentHP5;

  health6=health6+10;

  trace(health6);

  healthPercent6=health6/100;

  trace(healthPercent6);

  lifeBar1.barColor1.scaleX=healthPercent6;

}

playDogfood.addEventListener(MouseEvent.CLICK, attackButtonClicked5);

function attackButtonClicked5(e:MouseEvent):void

{

  currentHP5 -= 30;

  if(currentHP5 <= 0)

  {

  currentHP5 = 0;

  gotoAndPlay ("takebath");

  }

  updateHealthBar5();

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0