How do you delay the inputs of KeyDown?
Blitz3D Forums/Blitz3D Programming/How do you delay the inputs of KeyDown?
| ||
As in if to fire bullets so it isn't a constant stream of bullet. |
| ||
You set a firing rate in your bullet attribute or some sort of updateprojectile routine in your main loop. |
| ||
do you have a example of that |
| ||
One possible way is to add a 'cooldown' timer after you fire a bullet, and not allow you to fire another one until it is reset back to zero -- just subtract one on each flip |
| ||
For each gun (which shoots bullets...) have one variable to store a millisecond value (integer) When the gun shoots a bullet, store the millisecond value in this variable Gun_LastShootMs% = Millisecs() When an ai or a player is trying to fire a gun, check if the current millisecond value is equal or superior to LastShootMs + TimeMs (the time you want in milliseconds) if( GunActivated = true ) NowMs% = millisecs() If( NowMs - LastShootMs => 1000 ) ;(1000ms correspond to 1s) ;shoot a bullet ! endif endif |
| ||
Typically I use a variable i call firedelay. I store a positive value in it of a particular size after firing and decrement it each frame until it reaches zero. That way i then only fire a bullet if firedelay is zero. You can do much more than this though. For example in my spaceship game i have a cooldown timer, a powerdrain value, an ammunition limit and a time to lock variable which all contribute to the different firing mechanisms of ship weapons. |
| ||
I tend to use a standard of tickrates so all time-dependant features refer to a number of ticks. This means that the number of millisecs() calls is minimal and if the game state is paused, these cooldowns etc. can't be exploited or break. |