I have to make a tron like game with two players where one player moves with wasd keys and the other with arrow keys.
I have the following logic in the keyboard handling
move_players proc
check_plyr1:
mov ah, 01h ; check for input
int 16h
jz move_end ; if no input is jump to check plyr2
mov ah,00h
int 16h ; get key from buffer
cmp ah, 1eh ; 'a' is pressed
je move_plyr1_left
; and the other keys
jmp check_plyr2
move_plyr1_left:
call plyr1_trace ; places its previous position
mov ax, [plyr1X]
dec ax
mov [plyr1X], ax
call plyr1_check ;checks collision
call plyr1_draw ; draws actual position
jmp check_plyr2
plyr1_check:
mov ah,0Dh
mov cx,[plyr1X]
mov dx,[plyr1Y]
int 10H ; AL = COLOR
cmp al, 0h
jne plyr1_lost ; endgame scene
ret
check_plyr2:
cmp ah, 75 ; 'left arrow' is pressed
je move_plyr2_left
;and the other keys
jmp move_end
move_plyr2_left:
call plyr2_trace ; places its previous position
mov ax, [plyr2X]
dec ax
mov [plyr2X], ax
call plyr2_check ;checks collision
;call plyr2_draw ; draws actual position
jmp move_end
plyr2_check:
mov ah,0Dh
mov cx,[plyr2X]
mov dx,[plyr2Y]
int 10H ; AL = COLOR
cmp al, 0h
jne plyr2_lost ; end scene
ret
move_end:
ret
move_players ENDP
the problem is that I press the 'a' button and hold it then it starts to go to the left. Then I press and hold the left arrow without releasing 'a' key. The player1 (controlled by the wasd) stops and only player2 (controlled by arrows move). At this point if I release and press 'a' again then player1 move only again How can I make them move at the same time?
I tried to implement a system where I keep a record of the last key pressed and ignore it if it pressed again but didn't helped only halted the movement of the first player controlled.
I also tried to separate the two inputs in two procedures but that had the same result.