Checking for keypresses

Blitz3D Forums/Blitz3D Beginners Area/Checking for keypresses

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi there Goatless.

As author of Celestial Rift, I should point out that it was my first ever stab at coding a game in Blitz and version 1.35 at that! So, what I mean is that some of the things I did in that code may well not be the best or even the correct way of doing things. :)

The idea of the FlushKeys() after some of the keypresses was so that the bit of code that was called on the keypress wasn't called more than once, i.e.:

Rift: Is the user pressing fire?
Blitz: YES
Rift: Okay, do this. Then forget that the user is pressing that key until I ask you the question again next loop.

In hindsight, it doesn't really work as well as it should. Now I'd go with a flag and counter system, i.e.:

If KeyDown(KEY_FIRE) = True Then
	If Flag_KeyFire = False Then
		;Do player firing logic
		Flag_KeyFire = True
		Counter_KeyFire = 0
	End If
Else
	Flag_KeyFire = False
End If

If Flag_KeyFire = False Then
	Counter_KeyFire = Counter_KeyFire + 1
	If Counter_KeyFire = 60 Then
		Flag_KeyFire = True
	End If
End If


In this new code, if the player holds down FIRE then it will release a bullet every 60 game frames. Alternatively the player may get a higher firing rate by bashing the key repeatedly.

As for the use of If vs Select, in my opinion If is much more flexible for use in more wacky key combo pressing logic.

Feel free to ask for any more clarifications on my younger self's programming style. ;)