Complex input checking.

BlitzMax Forums/BlitzMax Beginners Area/Complex input checking.

Ryan Burnside(Posted 2008) [#1]
I'm working on a game that uses only 2 buttons. This is for a competition so I'm very restricted.

I need to code the following.

if buttons a and b are both released
preform action x

else ' the following actions will not be done if both buttons are pressed
     
     if button a is down and button b is up
           preform action a
     endif

     If button b is down and button a is up
           preform action b
     endif
endif


So if both buttons are down action x is done and the single button down test are never done. However if only one button is down then choose the right action for the button that is pressed. I need a way to check for buttons being released rather than buttons down and if buttons a and b are released then the single button pressed checks should not be executed.


Brucey(Posted 2008) [#2]

b1 = MouseDown(1)
b2 = MouseDown(2)

If Not b1 Or b2 Then
 ' do action x
Else If b1 And Not b2 Then
    ' preform action a
Else If b2 And Not b1 Then
    ' preform action a
End If

' or

buttons = MouseDown(1) * 1 | MouseDown(2) * 2

If Not buttons Then
 ' do action x
Else If buttons & 1 Then
    ' preform action a
Else If buttons & 2 Then
    ' preform action a
End If



Ryan Burnside(Posted 2008) [#3]
That was really close but buggy let me see if I can't explain the game a bit better.

You have two buttons the left key and the right key. If you hold left the player goes left, if you hold right the player goes right. However if you Hit then Release both buttons, the player shoots_a_beam() and does NOT move at all. Hitting and releasing both buttons means that the player wants to shoot the beam and not move. It is important that the beam shooting action happens only on the release of the button combination so the beam will not be executed with every step that the buttons are down.

The player holds only left, the ship moves left. The player holds only right the ship moves right. The player hits both buttons and a beam is fired only upon the release of the two held buttons.

to say it differently
left down= move left
right down = move right
left and right "tapped"=shoot beam

By tap I mean a full press and release. Ofcourse, executing any one of these outcomes will void the other two options. You cannot move while firing the beam for example.

Sorry for the former confusion.


Brucey(Posted 2008) [#4]
How's about...
SuperStrict

Graphics 640,480

Local oldButtons:Int, buttons:Int

Local leftKey:Int = key_z
Local rightKey:Int = key_x

SetColor(255, 255, 255)

While Not KeyDown(key_escape)

	Cls

	buttons = KeyDown(leftKey) * 1 | KeyDown(rightKey) * 2
	
	If Not buttons Then
		If oldButtons = 3 Then
			DrawText "ZAP !", 100, 100
			DebugLog "Zap !"
		End If
	Else If buttons = 1  Then
	   DrawText "Moving Left", 100, 100
	Else If buttons = 2 Then
	   DrawText "Moving Right", 100, 100
	End If

	oldButtons = buttons
	
	Flip
	
Wend



Jesse(Posted 2008) [#5]
I modified brucey's code some what. I think this is what you want:


[edited]


Ryan Burnside(Posted 2008) [#6]
Thank you so much guys. I really appreciate it!

Amazing how something so simple can bloat into lines of code.