How do I set up a timed power-up?

0 favourites
  • 6 posts
From the Asset Store
75 power-up sound effects; bonus and notification sounds, fanfares, harp glissandi, stabs, clock ticks, etc.
  • Hello,

    I recently got into Construct 2 and am enjoying it so far. I've gone through the shooter tutorial and am now continuing with the tutorial code, adding in various things to learn more about Construct 2.

    One of the things I've added is a gun power-up which will enable the player to shoot at full auto for 5 seconds. Currently, I am generating it a specific location every 6 seconds (I'll randomize the location later...makes it easier to debug at the moment). The power-up sprite will only generate if there is not one already on the map. I've gotten the full auto feature to work as well when the player collides with the power-up sprite.

    However, I cannot figure out how to limit the full-auto feature to work for only 5 seconds. I've tried a few different things, but, the primary bug is that, while it works great the first time, when the full-auto ends and the player attempts to immediately pick up another full-auto power-up, it will not trigger...I have the code attached. The power-up events are all at the bottom of Event Sheet 1.

  • Here's one option. Could also have the timer set/reset your variable if you prefer.

  • Wow, cool, thanks, it works perfectly. So that I can understand the coding better, what was the issue with the previous code? I know it had something to do with the Wait action, but I am not sure what. Thanks again!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You're setting hasPowerup to "false" every 5 seconds, possibly even after they just got the powerup. I don't like global Wait actions for this kind of thing. Some people get good mileage with System: Every x seconds for cooldown periods like this (which it kind of is). I just prefer setting a Timer as it keeps the behaviour with the object. There's also a 3rd party Cooldown add-on which I've used.

    edit: this one is better. There was no need for the complicated expression checking the timer values.

    [attachment=0:282wbhhf][/attachment:282wbhhf]

    edit 2: BTW I wouldn't use "true" and "false", it's very error prone. Use 0 and 1 or Boolean variables.

  • Ah, thank you for your help!!! The timer is quite useful.

  • Thank you,

    I gave a try to using Timer behavior instead of Wait function and it works like a charm. Your .capx example is also very useful.

    I was aware of the theory behind Timer behaviors, but I didn't really give it a try.

    I thought using Wait functions was lot easier, and Timer behavior functions lot more complex.

    But well, I was wrong. Now I can say you definetely got a more stable code by using Timer functions instead of Wait ones. At least in that kind of situations where you want to play around with variables value for just a few seconds before any other events happen.

    I also figured out that using System variables instead of object variables (on the player character) fixed a few issues on my code.

    Again, thanks a lot.

    Kr,

    Antoine

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