[Solved] Bullet Limit (Number of Bullets on Screen)

Get help using Construct 2

Post » Sat Nov 09, 2013 10:38 pm

I want to have 4 Bullets (Projectiles) max on screen at one time. The Bullets destroy when it collides with any other object.

What is the best way to set a Bullet Limit?

My game is a Platform/Run 'n Gun.
Last edited by hypergalaxy on Wed Apr 02, 2014 3:42 pm, edited 1 time in total.
B
8
S
3
Posts: 21
Reputation: 751

Post » Sat Nov 09, 2013 10:47 pm

Use a variable bulletTOTAL to track the number of bullets
Each time you create/spawn a bullet add 1 to bulletTOTAL
Each time you destroy a bullet minus 1 from bulletTOTAL

Then use...

Event -> Compare variable bulletTOTAL < 4
Actions -> Create Bullet etc
B
8
S
3
G
1
Posts: 34
Reputation: 1,395

Post » Sat Nov 09, 2013 10:52 pm

The fun thing about Construct is that it keeps a count of the objects. First, make sure bullets are destroyed when out of layout.

Then keep track, of many objects are on the screen. I typically assign some kind of global variable. NumberOfBulletsOnScreen = 0

Now, when you press the space key (or fire key) count the number of objects on the screen. Number of bullets = bullets.Count

'.Count' is appended after the object name to get the total number of that objects on the screen.

For your conditions down "when space key is pressed (or whatever key is the fire key) AND NumberOfBulletsOnScreen < 0

and the actions would be

spawn new bullet
NumberofBulletsOnScreen = bullets.count

This will work because you will keep a constant track of the bullets on the screen every time you fire. The layout always starts it as 0 so it will always allow you to start firing. As you fire it will raise the number of bullets on the screen. When there are 4, it won't let you fire any more. But you need to make sure to keep track of the number of bullets on the screen when the bullets are destroyed too. So you need one more condition and action.

Condition:
Bullet-On Destroyed

Action:
NumberOfBulletsOnScreen = bullet.Count

That will lower the variable and reset it as bullets are destroyed.
Kurieus
Come visit and play Blast Box!
B
15
S
3
Posts: 205
Reputation: 1,349

Post » Sat Nov 09, 2013 10:53 pm

@Arontwose beat me to it with a simpler solution.
Kurieus
Come visit and play Blast Box!
B
15
S
3
Posts: 205
Reputation: 1,349

Post » Sun Nov 10, 2013 2:31 am

Even simpler,
Add this to the shooting event:

bullet.count < 4 (this is a "Compare two values" system event)
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Wed Nov 13, 2013 9:27 pm

Thanks everyone!
I ended up using what "7Soul" suggested.
B
8
S
3
Posts: 21
Reputation: 751


Return to How do I....?

Who is online

Users browsing this forum: Anonnymitet, leena222, tatogame and 21 guests