Handle simultaneous keys pressed
Posted: Tue Feb 20, 2018 1:29 pm
Hi there!
My son and I want to create a little car racing game. If I press the "arrow up" key the car should drive "forwards" and if LEFT oder RIGHT is pressed (simultaneously) the car should rotate accordingly. So I tried this:
The car (to be more precise: the track) moves correctly when I press UP oder DOWN (moveTrack() is called). When I hold UP/DOWN key and additionally press LEFT or RIGHT this new key press is not recognized, which means just moveTrack() is called but not rotateCar() additionally.
What is the best way to this situation?
Thanks in advance!
My son and I want to create a little car racing game. If I press the "arrow up" key the car should drive "forwards" and if LEFT oder RIGHT is pressed (simultaneously) the car should rotate accordingly. So I tried this:
Code: Select all
...
Function rotateCar(direction)
DebugPrint("rotateCar")
EndFunction
Function moveTrack(speed)
DebugPrint("moveTrack")
EndFunction
Function p_HandlerFunc(msg)
Switch(msg.action)
Case "OnKeyDown":
If msg.key = "LEFT" Then rotateCar("left")
If msg.key = "RIGHT" Then rotateCar("right")
If msg.key = "UP" Then moveTrack(1)
If msg.key = "DOWN" Then moveTrack(-1)
EndSwitch
EndFunction
Repeat
WaitEvent
Forever
What is the best way to this situation?
Thanks in advance!