Need help with a game

for this script here, do I put it under the plane in the default tab?
this.energy = 100;
this.max = 100;

this.takeDamage = function(damage)
{
this.energy -= damage;

if(this.energy <= 0){
    this.energy = 0;
}

this.energyBar.scaleX = this.energy/this.max;
this.play();

}

Yes, you can do that… (well, no… unless you have the energyBar inside the plane clip which I don’t think so…)

oh thats true, I dont have it in there

Can I do the health with text, so like

Health: 100

so it works like a score but opposite
every time the player gets hit it loses 25 health or something?

1 Like

Of course, It is your app, you do with it as you please. :slightly_smiling_face:

ok
Ill name the text “healthCounter”

and for the code do I put

healthCounter.setText("Health: " + project.health)

would that be right?

1 Like

That should work as long as you are storing the airplane energy at project.health

Alright thank you.

Sorry one more question for the pig would I put

if (typeof player !== ‘undefined’){
if (this.hitTest(player))
project.health -= 25;
}

healthCounter.setText("Health: " + project.health)

Do you plan to remove the player at some point? I’m not sure why you are evaluating player against undefined…

yeah I want the player to be removed when the health reaches zero

I would add an empty frame inside player instead… like frame 2 will be empty… so if you want to add restart functionality to the game you will still have the player clip around… and then… instead of comparing against undefined… you will be comparing player.currentFrameNumber == 1

Oh ok, I will do that, thank you

Would you know how the energy bar can be connected to the plane but separated. so not both of them are in the same clip but separate clips.

and then when the pig collides the plane loses health.

-Thank you

Yes, Just as you are describing it…
You can call project.health from almost anywhere within the project.

so the energy bar code
this one
this.energy = 100;
this.max = 100;

this.takeDamage = function(damage)
{
this.energy -= damage;

if(this.energy <= 0){
    this.energy = 0;
}

this.energyBar.scaleX = this.energy/this.max;
this.play();

}

I put under default of the player (plane), is that correct?

Part C3-19-2021_10-56-34.wick (79.8 KB)

here is the file, I can finally post it.

Sorry if I randomly jumped in this thread
I checked the file and found where the problem was.

you reffered to the health bar as “this.energyBar” when you should’ve referred to it as just “energyBar”

And in the plane’s update script, you removed the plane once it hit the flying pigs, when you probably should’ve tried using the “this.takeDamage()” function instead.

I set the damage to 10 (you can change that from the plane’s update script)

Here’s a file with these fixes
Part C3-19-2021_11-32-56.wick (79.9 KB)

1 Like

Thank you, I appreciate it.
I will keep the fixes this helped me out so much, thank you.

1 Like

More than welcome, I love when people reply adding value, but not when people reply to just say “I dont know”

2 Likes

Thank you too Jovanny and everybody here, I appreciate it.

1 Like