How do you delay the inputs of KeyDown?

Blitz3D Forums/Blitz3D Programming/How do you delay the inputs of KeyDown?

RubyEnemy(Posted 2016) [#1]
As in if to fire bullets so it isn't a constant stream of bullet.


RustyKristi(Posted 2016) [#2]
You set a firing rate in your bullet attribute or some sort of updateprojectile routine in your main loop.


RubyEnemy(Posted 2016) [#3]
do you have a example of that


xlsior(Posted 2016) [#4]
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


RemiD(Posted 2016) [#5]
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



Matty(Posted 2016) [#6]
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.


_PJ_(Posted 2016) [#7]
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.