Using Keydown for firing without slowdown....?
Blitz3D Forums/Blitz3D Programming/Using Keydown for firing without slowdown....?
| ||
Basically, I want to use the keydown command - not keyhit - for a game, but I don't want a constant stream of bullets: || || || I want something more like this: || || || But still without using the keyhit function, because I think it's annoying when you have to keep 'button bashing' the fire button. Has anyone got any ideas? |
| ||
use a timer.. Beginning of game.. Global Gametimer# Global FireTimer# In main loop Gametimer#=Millisecs() Then before you fire a bullet with keydown If keydown(whatever) then If firetimer#<gametimer# then Firetimer#=gametimer#+200 ; thats 200 ms between shots Firebullet_here() endif endif |
| ||
Thanks a lot! :D |
| ||
Altough RifRaf has given a very good advice here, I would add another method, which uses two variables, one for fire pause, and the other as a flag which should be decreased in the main loop:Global fire_pause = 50 Global enable_fire = fire_pause ;the game main loop while not keydown(1) ;quits with ESC ;always decrease the fire pause if enable_fire > 0 then enable_fire = enable_fire - 1 endif if keydown(fire_button) ;pressed fire ? if enable_fire = 0 then ;enabled to fire ? fire_your_bullet() ;fire ! enable_fire = fire_pause ;reset the fire flag endif ;. ;. wend ;end of the main loop During the game, if you want to modify the pause between the shoots - for example when the player gets some bonus - you may decrease the value of the fire_pause variable, and then the player shoots will be faster. Hope this has sense for you, Sergio. |
| ||
Thanks, this is a great way of doing it too. |
| ||
Just make sure your project has frame-skippin' in it, or else RifRaf's method (which I use as well) can cause some cheatin' moments on slower PC's.... |