Gas Meter/ Power Meter question

Hey guys, hope you guys can help me on this one.

So I'm making an endless runner type of game and my game consists of an actor (which is a plane) and it has to collect coins, dodge enemies, but also has to collect gas tanks flying by or else you will run out of gas. I have a "gas meter" in which as each second goes on, the width of the bar is decreases by one pixel. Eventually, when the bar is gone, the plane falls to the ground.

Problem: So when I collect the gas tanks flying by, I increase the integer of the bar by 50 (The bar is 100 pixels in width). What happens is the bar grows past the 100 pixel mark and I have too much gas.
What I want to happen is when the plane collides with the gas tank it makes the gas meter "full" (back to 100 pixels, and no more than 100 pixels). I've tried looking to create something to "reset" the actor when it starts the scene, but can't manage to figure it out.

If anyone could help, it would be greatly appreciated!

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Change attribute game.gas to min(game.gas+50,100). The min() function returns the smaller of two values. So if game.gas+50 goes over 100, it will still change game.gas to 100.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RPMGamesRPMGames Member Posts: 21

    Works perfectly now! Thank you so much. I had no clue about inserting the min(game.x+x,x) function in there manually. I will definitely remember this as it will come in handy in the future! Thanks again!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You're welcome!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.