Need help with a game

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

hello, I know I’ve been asking a lot from you guys, do you think you can help me with this.

  • when the energy bar reaches zero you die
  • when the plane dies you go to the next frame

I also managed to get the regeneration from the jerry cans to work but it just needs to be set on a limit so it doesn’t go over 100.

Part C3-24-2021_17-44-41.wick (152.4 KB)

Thank you.

I added 2 lines ot the update script of the plane to make it go to the next frame when the energy bar reaches zero

if(this.energy<=0)
gotoNextFrame();

Here’s the project:
Part C3-24-2021_18-33-11.wick (152.5 KB)

Let me know if this is what you needed?

1 Like

Yup, Thank you so much.
And also the jerry cans so the regeneration doesn’t pass 100. If I keep collecting jerry cans it will add up and keep adding up, I just want it too add up to 100 then stop.

Just one more question how do I make the score appear on the 3rd frame?

You can make the score appear on same three using the same code you had on frame 2:

scoreCounter.setText("Score " + project.score)

(You’ll just need to have a text object named “scoreCounter” on frame 3 for this to work)

Try this: Part C3-24-2021_18-51-20.wick (152.7 KB)

1 Like

yup, that’s it, Thank you for helping me, I really appreciate it.

1 Like

Hello again, sorry to bother you, for the game when I die and I go to back to main menu, and I click play the game is still running, like it doesn’t reset, do you think you can help me with this?

Thank you.

Part C3-26-2021_17-03-37.wick (352.3 KB)

I’m always happy to help, here’s the file:
Part C3-26-2021_17-22-04.wick (352.3 KB)

I added this in the default script of the objects that get cloned:

if(!this.isClone)
for (var eachClone of this.clones){
    eachClone.remove();
}

This way, all of their clones get removed when entering the frame.

Also, the health did reset, but the scaleX of the bar only reset when the plane was damaged, so I added this in the update script of the plane:

energyBar.scaleX = this.energy/this.max;

Let me know if it works :+1:

Yup, it works, thank you. I really appreciate it

1 Like