I currently have a turret that can fire projectiles. I can control the delay between shots (fireDelay), and I can control the time needed to reload the magazine of the gun(reloadDelay). I do the simple solution of, when the user tries to fire, see how long has passed since he last fired, and if it has been long enough, it fires again. Same for reloadDelay.
But now I wanted to make it so clicking fire once would fire 3 bullets, with delay between, akin to the Burst Fire Mode on an M-16, like FPS genres.
A simplified overview of what happens right now:
- User clicks mouse.
- The program enters the fire function().
- Fires a bullet if sufficient time has elapsed, and enough ammo remains.
- Exits the function, and only enters again when you try and fire again.
So how do you make it fire again in the future without step 1 happening. I have a messaging system built into the engine, so my current solution would be for the gun to fire a bullet, and add 2 messages to the message list with the fire delay attached, and the message manager would send the messages to the gun to fire when the message times had expired. I didn't like this though, because I thought the gun should not be sending itself messages in the future to fire, and that's not what the messaging system was meant for initially, although it does work. I'm just wondering if there is a better solution to implement this?