读取简单游戏的彩色像素(不起作用)

时间:2015-10-20 02:23:02

标签: assembly tasm

我试图创造一个简单的游戏,坦克射击,并且块被摧毁,但我被困在摧毁块。在我的代码中,我尝试使用读取像素中断(int 10h / ah = 0Dh)。但每当我开枪时,子弹都不会自动退出。我真的不知道为什么。但是当我尝试在没有读取像素的情况下进行拍摄时,只使用一个简单的计数器,子弹就完美地移因此可以安全地假设我的子弹工作正常。如果我尝试将读取像素合并到其中进行拍摄。什么都没发生,有人可以告诉我为什么吗?感谢

PS:我正在使用Tasm; Textpad;视窗。视频模式= 13h

这是我的宏:

drawSquare MACRO color,cy,cx,dy,dx
    mov ah,06
    mov al, 0
    mov bh,color
    mov ch,cy
    mov cl,cx
    mov dh,dy
    mov dl,dx
    int 10h
endm

clear_select MACRO x1, y1, x2, y2
   drawSquare 00h, y1, x1, y2, x2   
endm

;------------------------------------

 include macros.txt
.model small
.stack
.data
VideoSegment   EQU  0A000h

saveMode db ?

R db 0
G db 0
B db 63

time db 0
mSecs db 100

x1 dw 05
y1 dw 10
x2 dw 07
y2 dw 15

tankY1 db 08h
tankY2 db 0ah       
tankY3 db 07h       
tankY4 db 0bh   

shootY db 00h
shootX1 db 00h
shootX2 db 00h

lengths dw 0
count db 0
.code
main proc
    mov ax, @data 
mov ds, ax

    call SetVideoMode
    call SetScreenBackground       ;blue for the tank

    drawSquare 04h, 00h, 00h, 18h, 02h ; red for tank bg 
    call Tank

    drawSquare 04h, 01h, 20h, 18h, 25h ; blocks
;---------------------
    ;FOR THE TIMER
    mov ah, 1
    div mSecs

    mov dl, ah

    lea si, time
    mov [si], dl
 ;--------------------
    move:
    drawSquare 04h, 01h, 20h, 18h, 25h ; red for tank bg 

        mov ah, 07
        int 21h

        cmp al, "w"
        je up

        cmp al, "s"
        je down

        cmp al, 20h
        je shoot 
        jmp outC

        up:
            dec tankY1
            dec tankY2
            dec tankY3
            dec tankY4
            sub y1, 32

            call TankAll    
        jmp move

        down:
            inc tankY1
            inc tankY2
            inc tankY3      
            inc tankY4
            sub y1, 16

            call TankAll
        jmp move

        shoot:
            ;bullet to be in the same Y position of the tanks front
            mov al, tankY1
            mov shootY, al
            add shootY, 01h

            ;bullet length
            mov shootX1, 04h
            mov shootX2, 06h

            mov count, 20

            bullets:
                drawSquare 01h, shootY, shootX1, shootY, shootX2 ;bullet

                ;timer
                mov ah, 2ch
                int 21h

                ;if there is a change in the timer
                cmp [si], dl
                jne change
                jmp bullets

                change:
                    ;store back to time
                    mov [si], dl

                    clear_select shootX1, shootY, shootX2, shootY  ;clear bullet
                    inc shootX1 ;to move the bullet
                    inc shootX2 ;to move the bullet

                    ;read color pixel
                    mov ah, 0Dh
                    mov bh, 0
                    mov cx, word ptr [shootX1]
                    mov dx, word ptr [shootY]
                    int 10h

                    cmp al, 4
                    je outC
                    jmp bullets


                    comment!
                    ;specify number of bullet movements
                    cmp count, 0
                    je next

                    dec count
                    jmp bullets

                    next:!

        jmp move

    outC:

    or al, 30h

    ;print color value
    mov ah, 02
    mov dl, al
    int 21h

    call RestoreVideoMode

    mov ax, 4c00h
    int 21h
main endp

TankAll proc
    clear_select 00h, 00h, 02h, 18h
    drawSquare 04h, 00h, 00h, 18h, 02h ; red for tank bg 
    call Tank
    ret
TankAll endp

SetScreenBackground proc
    mov dx, 3c8h
    mov al, 0
    out dx, al

    mov dx, 3c9h
    mov al, R
    out dx, al

    mov al, G
    out dx, al

    mov al, B
    out dx, al
    ret
SetScreenBackground endp 

SetVideoMode proc
    mov ah, 0fh
    int 10h
    mov saveMode, al

    mov ah, 0
    mov al, 13h
    int 10h

    push 0A000h
    pop es
    ret
SetVideoMode endp

RestoreVideoMode proc
    mov ah, 10h
    int 16h

    mov ah, 0
    mov al, saveMode
    int 10h
    ret
RestoreVideoMode endp

Tank proc ;Cut not draw
    drawSquare 00h, 00h, 02h, tankY1, 02h
    drawSquare 00h, tankY2, 02h, 19h, 02h

    drawSquare 00h, 00h, 00h, tankY3, 01h
    drawSquare 00h, tankY4, 00h, 19h, 01h
    ret
Tank endp

end main

0 个答案:

没有答案