How do I fire up to 5 bullets on screen before reloading to fire up to 5 again?

0 favourites
  • 6 posts
From the Asset Store
A sound pack containing 132 laser gun sound effects, including mono and stereo versions of audio files.
  • Firstly, we'll interchange the terms "bullets" and "lasers" for the sake of explanation. It's a space game, so please bear with me.

    I want the ship to be able to fire lasers, which can last (currently) 0.5 seconds before destroying themselves if they don't collide with anything.

    Furthermore, I want a maximum number of lasers onscreen (call it a reload), and a "reload" time of 2 seconds if there are 5 lasers onscreen. In other words, if the first of five lasers is destroyed, I could fire another one, but no more than 5 onscreen. And if I fire 5, there is a reload time of 2 seconds.

    If the above wasn't clear enough, another example: I fire four lasers. I can fire 1 more and there are 5 and then there is a 2 second reload time, but if the first lasers is destroyed then I can fire 2, and so on. Fire - bullets on screen increase by 1; destroyed - bullets on screen decrease by 1.

    So this is what I have thus far, but it does not work as intended:

    Any ideas or pointers? Thanks, regards.

  • So, to clarify - as long as you keep the number of lasers on the screen below 5, you can fire a new laser at any time without any delay. But when there are 5 lasers, the gun becomes unavailable for 2 seconds. Is this correct?

    First, you can use PlayerBullet.count expression instead of BulletsOnScreen variable - this way you don't have to worry about updating this variable when a laser is created of destroyed.

    You can also use "Timer "Bullets" is running" condition instead of CanShoot variable.

    There is a mistake in your second event - "BulletsOnScreen>4" condition runs on every tick while it's true, so the timer is restarted again and again.

    I suggest you create a sub-event inside the event where the bullet is spawned. In that sub-event check if the PlayerBullet.count>4, and start the timer.

  • So, to clarify - as long as you keep the number of lasers on the screen below 5, you can fire a new laser at any time without any delay. But when there are 5 lasers, the gun becomes unavailable for 2 seconds. Is this correct?

    Hello! That is correct.

    First, you can use PlayerBullet.count expression instead of BulletsOnScreen variable - this way you don't have to worry about updating this variable when a laser is created of destroyed.

    You can also use "Timer "Bullets" is running" condition instead of CanShoot variable.

    There is a mistake in your second event - "BulletsOnScreen>4" condition runs on every tick while it's true, so the timer is restarted again and again.

    I suggest you create a sub-event inside the event where the bullet is spawned. In that sub-event check if the PlayerBullet.count>4, and start the timer.

    I'll try the suggestions above and provide results. Thanks much!

  • OK, fixed it! It's a mix of suggestions and first-timing, so forgive my mess:

    In the first image you can see I put in the three conditions: button pressed, the laser count is less than or equal to BulletsOnScreen (set to 4, so you can fire that last laser and get to 5), and the player can shoot (is not locked out).

    In the second image you can see that if there are 5 lasers (greater than 4, the value of BulletsOnScreen) we lock the firing out by setting CanShoot to 0 for 2 seconds, then unlock it by reverting CanShoot to 1.

    In this third image I just leave the movement and destroy after 1 second.

    Now that the concept works, I'll fine tune the times and the laser speed.

    Thanks for the help!

  • Why are you comparing BulletsOnScreen with Bullet.count? Bullet.count was supposed to replace BulletsOnScreen variable. So the condition should be something like Bullet.count>4

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Because I didn't pay attention! Now PlayerBullet.Count works well. Thanks!

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