Im new to assembler.
Im trying to do an “Space Invaders” game, but encountered a problem.
Every time I print the main spaceship and the enemies, I erase the hole screen, and then print again in the next position, for it not to be too fast, added a delay function, but it began blinking.
I read somewhere that you can solve that by chaging the page you print while you are printing, and then change again, but I dont understand the concept well.
Print Function: (names are in spanish because its my mother tongue)
imprimeEnemigo proc
push cx
mov al, 219
mov cx, 1
call imprime
add dl, 1
mov al, 220
mov cx, 1
call imprime
add dl, 1
mov al, 219
mov cx, 1
call imprime
add dl, 1
mov al, 220
mov cx, 1
call imprime
add dl, 1
mov al, 219
mov cx, 1
call imprime
sub dh, 1
mov al, 220
mov cx, 1
call imprime
sub dl, 1
mov al, 219
mov cx, 1
call imprime
sub dl, 1
mov al, 220
mov cx, 1
call imprime
sub dl, 1
mov al, 219
mov cx, 1
call imprime
sub dl, 1
mov al, 220
mov cx, 1
call imprime
add dh, 2
add dl, 1
mov al, 223
mov cx, 1
call imprime
add dl, 2
mov al, 223
mov cx, 1
call imprime
pop cx
ret
imprimeEnemigo endp <—-This is for printing enemies
imprime proc
mov bh, 0 ;BH = Page Number
mov ah, 02h ;Set cursor position, con los parametros de dh y dl
int 10h
mov ah, 09h ;Write character and attribute at cursor position
int 10h
ret
imprime endp <---- Main print function with coursor positioning and printing (used also for the score and some other things)
This is how I clear my screen after each cycle:
mov ah, 0Fh
int 10h
mov ah, 0
int 10h
And this is how I print the main character
imprime_Jugador proc
mov al, 219
mov cx, 1
call imprime
sub dl, 1
mov al, 220
mov cx, 1
call imprime
add dl, 2
mov al, 220
mov cx, 1
call imprime
ret
imprime_Jugador endp
This is the delay function:
retardo proc
push ax
push bx
xor ax, ax
xor bx, bx
mov ax, cx
ret2:
dec ax
jz finDec
mov bx, cx
ret1:
dec bx
jnz ret1
jmp ret2
finDec:
pop bx
pop ax
ret
retardo endp
This is how the game looks like: https://i.sstatic.net/QMpkgGnZ.png
I tried many things, but didnt solve the problem at all, some reduced the blinking, but i want it to move smoothly through the screen
Nicolás is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.