Why is it adding me a random pixel on the screen?
I'm making the snake game and I got to the part where there are (for now) 3 asterisks that make the snake. When I move from vertical to horizontal and from horizontal to vertical it adds another asterisk
And for some reason just adds another *
to the row of *
s in the same place every time
For now my code is:
IDEAL
MODEL small
STACK 100h
DATASEG
; --------------------------
; Your variables here
; --------------------------
saveal db, ' ' ;used in line 223-233
app dw 0 ;place of the apple
st_am dw 3
stars dw 0, 0, 0 ;places of the *
CODESEG
proc black
body:
mov [es:si], ax
add si, 2
cmp si, 25*80*2
jnz body
ret
endp black
proc up
mov di, 80*2
cmp si, di
jb not_move_up
cmp si, [app]
jnz move_up
call apple
move_up:
call delete
mov di, [stars+2]
mov [stars+4], di
mov di, [stars]
mov [stars+2], di
sub di, 80*2
mov ah, 156
mov al, '*'
mov [es:di], ax
mov [stars], si
sub si, 80*2
mov ah, 156
mov al, '*'
mov [es:si], ax
not_move_up:
ret
endp up
proc down
mov di, (24*80*2)-1
cmp si, di
jg not_move_down
cmp si, [offset app]
jnz move_down
call apple
move_down:
call delete
mov di, [stars+2]
mov [stars+4], di
mov di, [stars]
mov [stars+2], di
add di, 80*2
mov ah, 156
mov al, '*'
mov [es:di], ax
mov [stars], si
add si, 80*2
mov ah, 156
mov al, '*'
mov [es:si], ax
not_move_down:
ret
endp down
proc left
mov dx, 0
mov bx, si
mov ax, si
mov si, 80*2
div si
mov si, bx
cmp dx,0
jz not_move_left
cmp si, [offset app]
jnz move_left
call apple
move_left:
call delete
mov di, [stars+2]
mov [stars+4], di
mov di, [stars]
mov [stars+2], di
mov ah, 156
mov al, '*'
mov [es:di], ax
mov [stars], si
sub si, 2
mov ah, 156
mov al, '*'
mov [es:si], ax
not_move_left:
ret
endp left
proc right
mov dx, 0
mov bx, si
mov ax, si
mov si, 80*2
div si
mov si, bx
cmp dx,158
jz not_move_right
cmp si, [app]
jnz move_right
call apple
move_right:
call delete
mov di, [stars+2]
mov [stars+4], di
mov di, [stars]
mov [stars+2], di
mov ah, 156
mov al, '*'
mov [es:di], ax
mov [stars], si
add si, 2
mov ah, 156
mov al, '*'
mov [es:si], ax
not_move_right:
ret
endp right
proc apple
mov ax, 40h
mov es, ax
mov ax, [es:6ch]
and ax, 0000001111111110b
mov di,ax
mov [offset app], di
mov ax, 0b800h
mov es, ax
mov al, '@'
mov ah, 154
mov [es:di], ax
ret
endp apple
proc delete
mov bx, offset stars
mov di, [st_am]
dec di
shl di, 1
mov di, [bx+di]
mov ax, 0b800h
mov es, ax
mov al, ' '
mov ah, 0
mov [es:di], ax
ret
endp delete
start:
mov ax, @data
mov ds, ax
; --------------------------
; Your code here
; --------------------------
mov ax, 0b800h
mov es, ax
mov si,0
mov al, ' '
mov ah, 0
call black
mov bx, offset stars
mov si, ((12*80+40)*2)-2
mov al, '*'
mov ah, 156
mov [es:si], ax
mov [bx], si
mov si, (12*80+40)*2
mov al, '*'
mov ah, 156
mov [es:si], ax
mov [bx+2], si
mov si, ((12*80+40)*2)+2
mov al, '*'
mov ah, 156
mov [es:si], ax
mov [bx+4], si
mov si, ((12*80+40)*2)-2
call apple
yesOrno:
mov ah, 1h
int 21h
mov [byte ptr saveal], al
cmp [byte ptr saveal], 'w'
jz w
cmp [byte ptr saveal], 'a'
jz a
cmp [byte ptr saveal], 's'
jz s
cmp [byte ptr saveal], 'd'
jz d
cmp [byte ptr saveal], 'q'
jmp exit
w:
call up
jmp yesOrno
s:
call down
jmp yesOrno
a:
call left
jmp yesOrno
d:
call right
jmp yesOrno
exit:
mov ax, 4c00h
int 21h
END start
I tried to think myself, but I couldn't think of something.
So sorry for asking a lot.
Comments
Post a Comment