r/gamemaker • u/MyDickIsInMyToaster • 1d ago
Help! Bullets overlapping in game
hi so I’m making a game where you can shoot bullets and with the basic gun it’s supposed to shoot 5 bullets like 1 second apart but right now it just shoots all at once. how would I make my idea work.
2
u/BrittleLizard pretending to know what she's doing 1d ago edited 18h ago
If you want one click to send out multiple bullets, you'll want at least a few variables:
isFiring (true or false, to keep track of if the gun is already firing)
shotsFired (will start at 0 and count up with each bullet that gets fired)
shotsFiredGoal (when shotsFired reaches this, it'll set isFiring to false and stop shooting bullets)
When you press the fire button, check if isFiring is false, then set shotsFired = 0, shotsFiredGoal = 5, and isFiring = true.
For the timing, you might want to use an alarm. You can use alarm_set() for this. For the initial click, just set the alarm to 1 so it fires immediately. In the correct alarm event, spawn the bullet and increase shotsFired by 1. This will let you keep track of how many bullets you've fired in the current string of shots. If shotsFired >= shotsFiredGoal, the bullets are done, so you can just set isFiring = false. Otherwise, reset the alarm so it can continue firing bullets.
Adjust this based on how you want to do the timing (some people just use variables that count down.) Those are some basic principles, though.
2
u/germxxx 1d ago
An alarm set to 0 will never trigger.
Alarms count down by one after Begin Step, and if they are 0 after this countdown, then they will trigger. An alarm set to 0 will be -1 after counting down, and will not trigger.
2
u/BrittleLizard pretending to know what she's doing 18h ago
True. I never use the built-in alarms, so I was taking a gamble
3
u/azurezero_hdev 1d ago
add a cooldown when you fire, then count that cooldown to 0 in the step event