首先,我在windows os中使用MASM。 我正在尝试制作一个可由用户移动的动画角色“O”,我选择了A,W,S和D来移动它。代码工作正常,但是,边框闪烁+ O可以穿透它们。
知道怎么解决这个问题吗?我需要在某些边缘移动O,这意味着它不应超出我的寄宿生。
INCLUDE Irvine32.inc
Displayshape Macro
mov edx, offset shape
call writestring
endm
setcur macro dl, dh
local bottom, quit, xcor, ycor, row, col, shape
.data
xcor byte "Xcor is out of range",0
ycor byte "Ycor is out of range",0
.code
bottom:
.IF ( DL <0) || (DL > 79)
lea edx, xcor
call writestring
jmp quit
.ENDIF
.IF( DH<0) || ( DH> 24)
lea edx, ycor
call writestring
jmp quit
.ENDIF
call gotoxy
repeat 80
add dl, 1
mov eax, '*'
call writechar
endm
quit:
endm
.DATA
row db ?
col db ?
shape db 'O',0
.code
main PROC
second:
mov eax, white + (Blue*16)
call setTextcolor
call clrscr
mov eax, white + (blue * 16)
call setTextColor
mov dh, 15
mov dl, 30
call gotoxy
mov row, dh
mov col, dl
displayshape
call moveit
call crlf
exit ; exit to operating system
main ENDP
moveit proc
mov eax, white + ( blue * 16 )
call setTextcolor
Get_key:
call readchar
cmp al, 'w'
je moveup
cmp al, 's'
je movedown
cmp al, 'a'
je moveleft
cmp al, 'd'
je moveright
jmp exit1
moveup:
call clrscr
mov dl, 0
mov dh, 20
setcur dl, dh
mov dl, 0
mov dh, 0
mov dh, 2
setcur dl, dh
mov dh, row
sub dh, 1
mov dl, col
call gotoxy
mov row, dh
mov col, dl
Displayshape
jmp get_key
movedown:
call clrscr
mov dl, 0
mov dh, 20
setcur dl, dh
mov dl, 0
mov dh, 0
mov dh, 2
setcur dl, dh
mov dh, row
add dh, 1 ; move down needs incrementation
mov dl, col
call gotoxy
mov row, dh
mov col, dl
Displayshape
jmp get_key
moveright:
call clrscr
mov dl, 0
mov dh, 20
setcur dl, dh
mov dl, 0
mov dh, 0
mov dh, 2
setcur dl, dh
mov dl, col
add dl, 2
mov dh, row
call gotoxy
mov row, dh
mov col, dl
Displayshape
jmp get_key
moveleft:
call clrscr
mov dl, 0
mov dh, 20
setcur dl, dh
mov dl, 0
mov dh, 0
mov dh, 2
setcur dl, dh
mov dl, col
sub dl, 2
mov dh, row
call gotoxy
mov row, dh
mov col, dl
Displayshape
jmp get_key
exit1:
ret
moveit endp
END main
答案 0 :(得分:0)
我在方法中使用了if语句到边距
,例如:.if(dl> 77)
它有效!