;ChoongHong Oh

TITLE PGM11 :C_ENEMY & ENDING
        EXTRN NO_C_ENE : BYTE, GRAPHIC_C_ENE : BYTE
        EXTRN AUX_Y : WORD
        PUBLIC MOVE_C_ENEMY
        PUBLIC ENDING

.MODEL SMALL
IF1
        INCLUDE G_MACRO.ASM
ENDIF
.CODE

DRAW_C_ENE PROC
;this procedure draws a climbing knight on the ladder at (568, AUX_Y)
;by using the right macro according to the graphic number
;input:AUX_Y is the Y-coordinate of a climbing knight

        CMP GRAPHIC_C_ENE, 0   ;if the graphic number is 0
        JE GRA_0
        JMP GRA_1
GRA_0:
        C_KNIGHT1 AUX_Y        ;draw C_ENE using macro C_KINGHT1
        JMP DONE
GRA_1:                         ;the graphic number is 1
        C_KNIGHT2 AUX_Y        ;draw C_ENE using macro C_KINGHT2
DONE:
        RET
DRAW_C_ENE ENDP

MOVE_C_ENEMY PROC
;this procedure updates all the climbing knights and the graphic number
;by calling DRAW_C_ENE procedure, having AUX_Y as a parameter

        ERASE_C_KNIGHT 384    ;erase C_ENE at the bottom of LADDER
        MOV AUX_Y, 384
        CALL DRAW_C_ENE       ;draw C_ENE at the bottom of LADDER
        CMP NO_C_ENE, 2       ;if there are two C_ENE
        JGE C2                ;then, draw 2nd C_ENE
        JMP DONE_             ;else, it is done
C2:
        ERASE_C_KNIGHT 324    ;erase C_ENE at the 2nd position
        MOV AUX_Y, 324
        CALL DRAW_C_ENE       ;draw C_ENE at the position
        CMP NO_C_ENE, 3       ;if there are three C_ENE,
        JGE C3                ;then draw 3rd C_ENE
        JMP DONE_             ;else, it is done
C3:
        ERASE_C_KNIGHT 264    ;erase C_ENE at the 3rd position
        MOV AUX_Y, 264
        CALL DRAW_C_ENE       ;draw C_ENE at the position
        CMP NO_C_ENE, 4       ;if there are four C_ENE,
        JGE C4                  ;then, draw the last C_ENE
        JMP DONE_             ;else, it is done
C4:
        ERASE_C_KNIGHT 204    ;erase C_ENE at the top of LADDER
        MOV AUX_Y, 204        
        CALL DRAW_C_ENE       ;draw C_ENE at the top of LADDER
DONE_:        
        CMP GRAPHIC_C_ENE, 1   ;if the graphic number is 1
        JE  GRA_C0             ;then, make it 0
        ADD GRAPHIC_C_ENE, 1   ;else, make the graphic number = 1
        JMP EXIT
GRA_C0:
        SUB GRAPHIC_C_ENE, 1   ;make the graphic number = 0
EXIT:
        RET
MOVE_C_ENEMY ENDP


ENDING PROC
;this procedure draws some graphics and displays 'GAME OVER'
;when the game is over

        SAVE_REGS <AX, BX, CX, DX>
;draw graphics using macros
        ENDING_ENEMY 528, 128
        ERASE_ELE
        DRAW_ELE 368
        FIRE
        DRAW_MOON 1100b
        DRAW_TREES 1100b
        MOV AH, 02     ;set cursor
        MOV BH, 0      ;page 0
        MOV DH, 15     ;row 15
        MOV DL, 36     ;column 36
        INT 10h
        MOV AH, 0Eh    ;write character function
        MOV BL, 1111b  ;white color
;type GAME OVER
        MOV AL, 'G'
        INT 10h
        MOV AL, 'A'
        INT 10h
        MOV AL, 'M'
        INT 10h
        MOV AL, 'E'
        INT 10h
        MOV AL, ' '
        INT 10h
        MOV AL, 'O'
        INT 10h
        MOV AL, 'V'
        INT 10h
        MOV AL, 'E'
        INT 10h
        MOV AL, 'R'
        INT 10h
        RESTORE_REGS <DX, CX, BX, AX>
        RET
ENDING ENDP
        END
