Denying a keydown

Blitz3D Forums/Blitz3D Beginners Area/Denying a keydown

Happy Llama(Posted 2011) [#1]
I have a game in which you have a fixed amount of energy in which you can use to sprint. If the shift key is held down in unison with the forward arrow, the player sprints. Is there a way when energy=0 then the program will wait 10 seconds and ignore any key strokes from the shift key? Think of the sprint use in Call of Duty, If you sprint until you run out of energy you can't sprint for 5 seconds. But if your energy level does not reach 0, you don't have to wait for it to replenish. It's a little complicated but any comments will help. Thanks!


Matty(Posted 2011) [#2]
One way of doing it..there's many others..press 'space' to use energy.

Graphics 800,600,0,2
maxenergy = 100
energy = maxenergy
hasrecharged = 1
Repeat

Cls

If KeyDown(57) Then 
	If energy > 0 And hasrecharged = 1 Then 
		energy = energy - 1
		Text 0,0,"Running! This much energy left:"+energy
		If energy <= 0 Then 
			hasrecharged = 0
		EndIf 
	ElseIf hasrecharged = 0 
		If energy < maxenergy Then energy = energy + 1
		If energy = maxenergy Then hasrecharged = 1		
		Text 0,0,"Recharging! Please wait to refill. This much energy:"+energy
	EndIf 
Else
	If energy < maxenergy Then energy = energy + 1
	If energy = maxenergy Then hasrecharged = 1
	If hasrecharged = 0 Then 
		Text 0,0,"Recharging! Please wait to refill. This much energy:"+energy
	Else
		Text 0,0,"Recharging! This much energy:"+energy
	EndIf 
EndIf 




Flip 

Until KeyDown(1) 
End




Last edited 2011


Kryzon(Posted 2011) [#3]
Like Matty exemplified, it's not a matter of 'denying' a KeyDown; you have to just 'not do anything with it'.
If KeyHit(57) Then
	If [Condition] Then
		
		;Perform action.
	
	EndIf

	;No need for an additional blank Else or anything. If the condition isn't 
	;met, no action will be performed even if the key is being pressed.
EndIf