0

I need to make a small game in assembly for school. For now, I just have a green rectangle that moves on the screen inside a white outline. The thing is, I want to draw a heart on the screen (using a function that paints 1's in a mat) but if I draw the heart I can't move the rectangle. Can anyone please help me? (Also, I am new to the site so sorry for making all of this question messy.)

The code: by using this mat:

heart db 1,1,0,1,1
      db 1,1,0,1,1
      db 0,1,1,1,0
      db 0,0,1,0,0

And this function:

proc Sprite_Figure
push bp
mov bp, sp
push ax
push bx
push cx
push dx
push si
push es
push di
    
    mov ax, 0a000h
    mov es, ax
    xor ax, ax
    sub [byte ptr bp+6], 7
    sub [byte ptr bp+8], 8 ; result is 8 up and 7 left. Given cord is middle of the card
    mov di, [bp+6]
    
    mov si, [bp+4] ; sprite offset
    mov cx, [bp+14] ; number of lines   
    loop1:
        mov dx, [bp+12] ; size of one line
        loop2:
            push dx
            xor dx, dx
            cmp [byte ptr si], 0
            je continue
            
            print:
            mov bx, [bp+8] ; current row    
            
            mov ax, 320
            mul bx
            mov bx, ax ; calculation to get location of pixel on screen
            add bx, [bp+6] ; x
            
            mov ax, [bp+10] ; color
            mov [es:bx], al ; color location, es val is 0A000h
            
            
            continue:
            pop dx
            inc si ; next element in array  
            dec dx
            inc [byte ptr bp+6] ; right by one
            
            cmp dx, 0
            jne loop2
        
        
        inc [byte ptr bp+8] ; one line down
        mov [bp+6], di ; reset x
        dec cx
        cmp cx, 0
        jne loop1
pop di
pop es
pop si
pop dx
pop cx
pop bx
pop ax
pop bp
ret 12
endp Sprite_Figure

I make the heart.

In order to make the cube, I use this code:

proc DisplayDot
    mov al, [color]
    mov bl, 0
    
    mov cx, [x]
    mov dx, [y]
    
    mov ah, 0Ch
    int 10h

    ret
endp DisplayDot


proc DisplayLine
    mov cx, [startX]
    mov [x], cx
    
DisplayDotLoop:
    call DisplayDot
    inc [x]
    
    mov cx, [endX]
    inc cx
    cmp [x], cx
    
    jne DisplayDotLoop

    ret
endp DisplayLine


proc DisplayRect
    mov dx, [startY]
    mov [y], dx
    
DisplayLineLoop:
    call DisplayLine
    inc [y]
    
    mov dx, [endY]
    inc dx
    cmp [y], dx
    
    jne DisplayLineLoop

    ret
endp DisplayRect

And this is one of the four move procedures for the cube:

proc MoveUp
    cmp [startY], 15
    je EndMoveUp

    mov [color], 0
    call DisplayRect

    sub [startY], 10
    sub [endY], 10
    
    mov [color], 0Ah
    
    call DisplayRect
    
EndMoveUp:  
    ret
endp MoveUp
ecm
  • 2,583
  • 4
  • 21
  • 29
starfi
  • 1
  • 1
  • 2
    take a look at [What is the best way to move an object on the screen?](https://stackoverflow.com/a/29579522/2521214) for some inspiration and cross check – Spektre Jun 04 '22 at 09:50
  • "if I draw the heart I can't move the rectangle" What exactly does this mean? You can always create 4 more additional movement procedures for the *heart* (*MoveUpHeart* vs *MoveUpRect*, ...) And if the *heart* is painted on top of the painted rectangle, then just draw it together with your *DisplayRect*. – Sep Roland Jun 05 '22 at 15:11
  • You need to better explain what it is that you are trying to create. We can only guess now! – Sep Roland Jun 05 '22 at 15:12
  • The heart is supposed to display at the screen, and later on be erased/redrawn. The rectangle usually moves around the screen with the arrows but once I draw the heart it doesn't work anymore. I think it has something to do with graphic/text modes because I can see the command line I entered on the top right of the screen but I am really not sure about it – starfi Jun 06 '22 at 17:03
  • What screen mode are you in? – puppydrum64 Dec 20 '22 at 16:42

0 Answers0