How do I make a temporary power-up?

  • Hello, I'm having an issue sorting out the logic with making a power-up for my game. Basically, when the player collects the power-up, a bar is filled that slowly empties. What I want to have happen is, while the bar is not empty (i.e. has a width greater than zero), the player has 1 point added to one of their stats. I'd like to do it this way so that the bonus does not stack if they collect the same power-up multiple times, therefore it only applies once while true.

    This seems like it would be pretty simple but it's turning out to be kind of hard to wrap my head around, namely because I don't know how to do truly temporary additions to variables- as in, not using two different events to add the bonus stat point and then subtract it again when the bonus runs out. If that's the only reasonable way, feel free to let me know how to do that, but I'd like if there were a more elegant solution that only took one event.

  • You can keep your player stats in an array, when you pick up the power up, increment the array cell value corresponding with the picked up, power up, after the duration is over just decrement the array call back the default value. Just don't forget to set the array values into the player instance variables ( or where ever you keep your player stats) on layout load out, and when you pick up the power up.

    Using array is the best choice I think because you can easily modify the values whenever you like especially if you have an ingame shop, also array can be saved as Json so you can save the variable modifications even after the game is closed.

  • That does sound like a good idea since the player will be able to save the game etc, but what do you mean by incrementing and decrementing the cell values? Do you just mean making an event that sets it to "(whatever it's at)+1" upon picking up the power-up and then another for "(whatever it's at)-1" when it wears off?

  • Yeah, like that, but you can add any value (does not need to be explicitly 1) depending on how you structured the player stats and how strong the power up is, just don't forget to reset the same value back to normal when the power up ends.

  • Got it, thank you. Would you happen to have any organization tips? Because this

    is kind of a mess and hard to keep track of. Also, how do I make these values initialize to these only once, ever, instead of every time the player visits the layout?

  • Have a sprite appear, wait x seconds, destroy it. You can have it on a timer (variable if it works or every x second) it appears.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You will have to initialize the stats At least once to the player when the game loads. You can call it every time on start of layout, or call it only once on a specific layer (main menu as an example).

    There is no way to organize the array in construct 2, they will always look like a mess in the events, you will have to remember what each cell does. I usually open a word or exel document and I write my array there, and set a short description to what each cell does so I don't forget.

  • Ahh, that's a bummer, but oh well. Thank you very much for the help, it proved super useful.

  • You are welcome

    Good luck with your game.

  • You can make a temporary power up. Have it created, when the player collides with it something happens, an effect that's temporary.

    On Collision with Power Up.

    Destroy Power Up

    Effect starts

    Wait x seconds

    Effect ends.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)