i have this code
.model small
.data
var db '@', '$'
delaytime db 10
total db 0
col db 40
row db 12
.stack 100h
.code
delay proc
mov ah, 00
int 1Ah
mov bx, dx
jmp_delay:
int 1Ah
sub dx, bx
cmp dl, delaytime
jl jmp_delay
ret
delay endp
lefty proc
dec col
cmp col, 0
jle sn
leftyie:
mov dl , col
mov dh , row
xor bh, bh
mov ah, 02h
int 10h
ret
sn:
mov col, 79
jmp leftyie
lefty endp
righty proc
inc col
cmp col,79
jg zero
rightyie:
mov dl,col
mov dh,row
xor bh, bh
mov ah, 02h
int 10h
ret
zero:
mov col,0
jmp rightyie
righty endp
upy proc
dec row
cmp row, 0
jl upzero
uptie:
mov dl,col
mov dh,row
xor bh, bh
mov ah, 02h
ret
upzero:
mov row,24
jmp uptie
upy endp
downy proc
inc row
cmp row, 24
jg gozero
downty:
mov dl,col
mov dh,row
xor bh, bh
mov ah, 02h
int 10h
ret
gozero:
mov row,0
jmp downty
downy endp
video proc
mov al, 03h ;set video mode
mov ah, 00h
int 10h
ret
video endp
start proc
;starting coordinates
mov dh, 12 ;row
mov dl, 40 ;column
xor bh, bh
mov ah, 02h
int 10h
ret
start endp
dashclear proc
mov ax, 0600h
mov bh, 07h
xor cx, cx
mov dx, 184fh
int 10h
ret
dashclear endp
getchar proc
mov ah, 00h
int 16h
ret
getchar endp
main proc
mov ax, @data
mov ds, ax
call video
call start
mov dx, offset var
mov ah, 09h
int 21h
mov cx, 3200h ;stop cursor blinking
mov ah, 01h
int 10h
call start
getinput:
call getchar ;get character
direct_change:
cmp ah, 72
je w
cmp ah, 80
je s
cmp ah, 75
je a
cmp ah, 77
je d
cmp al, 119
je w
cmp al, 115
je s
cmp al, 97
je a
cmp al, 100
je d
cmp al, 119
jne rak
cmp al, 115
jne rak
cmp al, 97
jne rak
cmp al, 100
jne rak
a:
call delay
call dashclear
call lefty
mov dx, offset var
mov ah, 09h
int 21h
jmp a
s:
call delay
call dashclear
call downy
mov dx, offset var
mov ah, 09h
int 21h
jmp s
d:
call delay
call dashclear
call righty
mov dx, offset var
mov ah, 09h
int 21h
jmp d
w:
call delay
call dashclear
call upy
int 10h
mov dx, offset var
mov ah, 09h
int 21h
jmp w
rak:
jmp getinput
main endp
end main
when i pressed character w , a, s, d in go to a specific direction
and it goes to that direction all the way like in the snake game
so how do i change direction while my character is moving? i think it is in my delay proc
my idea is
when i dont press w a s d key within the time limit then it should continue otherwise it should change direction
any idea on how to do this?