; Define constants
PACMAN_X equ 10
PACMAN_Y equ 10
GHOST_X equ 20
GHOST_Y equ 20
DOTS equ 10
; Define data section
section .data
dots_remaining dw DOTS
pacman_x dw PACMAN_X
pacman_y dw PACMAN_Y
ghost_x dw GHOST_X
ghost_y dw GHOST_Y
; Define code section
section .text
global _start
_start:
; Initialize screen
call clear_screen
call draw_pacman
call draw_ghost
call draw_dots
game_loop:
; Move Pac-Man
call move_pacman
; Check for collision with ghost
call check_collision
; Check for victory
call check_victory
; Wait for key press and handle input
call handle_input
jmp game_loop
; Clear the screen
clear_screen:
mov ah, 0
mov al, 3
int 10h
ret
; Draw Pac-Man at current position
draw_pacman:
mov ah, 0ch
mov al, 00001111b
mov cx, [pacman_x]
mov dx, [pacman_y]
int 10h
ret
; Draw ghost at current position
draw_ghost:
mov ah, 0ch
mov al, 00001100b
mov cx, [ghost_x]
mov dx, [ghost_y]
int 10h
ret
; Draw dots on screen
draw_dots:
mov ah, 0ch
mov al, 00001111b
mov cx, 5
mov dx, 5
dots_loop:
int 10h
add cx, 10
dec word [dots_remaining]
cmp [dots_remaining], 0
jne dots_loop
ret
; Move Pac-Man based on user input
move_pacman:
; Get user input
mov ah, 0
int 16h
cmp al, 'w'
je move_up
cmp al, 's'
je move_down
cmp al, 'a'
je move_left
cmp al, 'd'
je move_right
ret
move_up:
sub word [pacman_y], 1
call draw_pacman
ret
move_down:
add word [pacman_y], 1
call draw_pacman
ret
move_left:
sub word [pacman_x], 1
call draw_pacman
ret
move_right:
add word [pacman_x], 1
call draw_pacman
ret
; Check for collision between Pac-Man and ghost
check_collision:
cmp [pacman_x], [ghost_x]
je collision_x
cmp [pacman_y], [ghost_y]
je collision_y
ret
collision_x:
cmp word [pacman_y], [ghost_y]
je game_over
ret
collision_y:
cmp word [pacman_x], [ghost_x]
je game_over
ret
; Check for victory condition
check_v
; Check if all dots have been eaten
check_victory:
cmp [dots_remaining], 0
jne continue_game
; Victory screen
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, victory_message
int 21h
jmp end_game
continue_game:
ret
; Handle user input
handle_input:
; Check if key has been pressed
mov ah, 1
int 16h
jz no_input
; Handle input
cmp al, 'q'
je end_game
jmp no_input
no_input:
ret
; Game over screen
game_over:
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, game_over_message
int 21h
jmp end_game
; End the game
end_game:
mov ah, 4ch
mov al, 0
int 21h
; Define messages
victory_message db 'You won!', 0
game_over_message db 'Game over.', 0
; Define constants
PACMAN_X equ 10
PACMAN_Y equ 10
GHOST_X equ 20
GHOST_Y equ 20
DOTS equ 10
; Define data section
section .data
dots_remaining dw DOTS
pacman_x dw PACMAN_X
pacman_y dw PACMAN_Y
ghost_x dw GHOST_X
ghost_y dw GHOST_Y
; Define code section
section .text
global _start
_start:
; Initialize screen
call clear_screen
call draw_pacman
call draw_ghost
call draw_dots
game_loop:
; Move Pac-Man
call move_pacman
; Check for collision with ghost
call check_collision
; Check for victory
call check_victory
; Wait for key press and handle input
call handle_input
jmp game_loop
; Clear the screen
clear_screen:
mov ah, 0
mov al, 3
int 10h
ret
; Draw Pac-Man at current position
draw_pacman:
mov ah, 0ch
mov al, 00001111b
mov cx, [pacman_x]
mov dx, [pacman_y]
int 10h
ret
; Draw ghost at current position
draw_ghost:
mov ah, 0ch
mov al, 00001100b
mov cx, [ghost_x]
mov dx, [ghost_y]
int 10h
ret
; Draw dots on screen
draw_dots:
mov ah, 0ch
mov al, 00001111b
mov cx, 5
mov dx, 5
dots_loop:
int 10h
add cx, 10
dec word [dots_remaining]
cmp [dots_remaining], 0
jne dots_loop
ret
; Move Pac-Man based on user input
move_pacman:
; Get user input
mov ah, 0
int 16h
cmp al, 'w'
je move_up
cmp al, 's'
je move_down
cmp al, 'a'
je move_left
cmp al, 'd'
je move_right
ret
move_up:
sub word [pacman_y], 1
call draw_pacman
ret
move_down:
add word [pacman_y], 1
call draw_pacman
ret
move_left:
sub word [pacman_x], 1
call draw_pacman
ret
move_right:
add word [pacman_x], 1
call draw_pacman
ret
; Check for collision between Pac-Man and ghost
check_collision:
cmp [pacman_x], [ghost_x]
je collision_x
cmp [pacman_y], [ghost_y]
je collision_y
ret
collision_x:
cmp word [pacman_y], [ghost_y]
je game_over
ret
collision_y:
cmp word [pacman_x], [ghost_x]
je game_over
ret
; Check for victory condition
check_victory:
cmp [dots_remaining], 0
jne continue_game
; Victory screen
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, victory_message
int 21h
jmp end_game
continue_game:
ret
; Handle user input
handle_input:
; Check if key has been pressed
mov ah, 1
int 16h
jz no_input
; Handle input
cmp al, 'q'
je end_game
jmp no_input
no_input:
ret
; Game over screen
game_over:
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, game_over_message
int 21h
jmp end_game
; End the game
end_game:
mov ah, 4ch
mov al, 0
int 21h
; Define messages
victory_message db 'You won!', 0
game_over_message db 'Game over.', 0
; Define constants
PACMAN_X equ 10
PACMAN_Y equ 10
GHOST_X equ 20
GHOST_Y equ 20
DOTS equ 10
; Define data section
section .data
dots_remaining dw DOTS
pacman_x dw PACMAN_X
pacman_y dw PACMAN_Y
ghost_x dw GHOST_X
ghost_y dw GHOST_Y
; Define code section
section .text
global _start
_start:
; Initialize screen
call clear_screen
call draw_pacman
call draw_ghost
call draw_dots
game_loop:
; Move Pac-Man
call move_pacman
; Clear the screen
clear_screen:
mov ah, 0
mov al, 3
int 10h
ret
; Draw Pac-Man at current position
draw_pacman:
mov ah, 0ch
mov al, 00001111b
mov cx, [pacman_x]
mov dx, [pacman_y]
int 10h
ret
; Draw ghost at current position
draw_ghost:
mov ah, 0ch
mov al, 00001100b
mov cx, [ghost_x]
mov dx, [ghost_y]
int 10h
ret
; Draw dots on screen
draw_dots:
mov ah, 0ch
mov al, 00001111b
mov cx, 5
mov dx, 5
dots_loop:
int 10h
add cx, 10
dec word [dots_remaining]
cmp [dots_remaining], 0
jne dots_loop
ret
; Move Pac-Man based on user input
move_pacman:
; Get user input
mov ah, 0
int 16h
cmp al, 'w'
je move_up
cmp al, 's'
je move_down
cmp al, 'a'
je move_left
cmp al, 'd'
je move_right
ret
move_up:
sub word [pacman_y], 1
call draw_pacman
ret
move_down:
add word [pacman_y], 1
call draw_pacman
ret
move_left:
sub word [pacman_x], 1
call draw_pacman
ret
move_right:
add word [pacman_x], 1
call draw_pacman
ret
; Check for collision between Pac-Man and ghost
check_collision:
cmp [pacman_x], [ghost_x]
je collision_x
cmp [pacman_y], [ghost_y]
je collision_y
ret
collision_x:
cmp word [pacman_y], [ghost_y]
je game_over
ret
collision_y:
cmp word [pacman_x], [ghost_x]
je game_over
ret
; Check for victory condition
check_v
; Check if all dots have been eaten
check_victory:
cmp [dots_remaining], 0
jne continue_game
; Victory screen
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, victory_message
int 21h
jmp end_game
continue_game:
ret
; Handle user input
handle_input:
; Check if key has been pressed
mov ah, 1
int 16h
jz no_input
; Handle input
cmp al, 'q'
je end_game
jmp no_input
no_input:
ret
; Game over screen
game_over:
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, game_over_message
int 21h
jmp end_game
; End the game
end_game:
mov ah, 4ch
mov al, 0
int 21h
; Define messages
victory_message db 'You won!', 0
game_over_message db 'Game over.', 0
; Define constants
PACMAN_X equ 10
PACMAN_Y equ 10
GHOST_X equ 20
GHOST_Y equ 20
DOTS equ 10
; Define data section
section .data
dots_remaining dw DOTS
pacman_x dw PACMAN_X
pacman_y dw PACMAN_Y
ghost_x dw GHOST_X
ghost_y dw GHOST_Y
; Define code section
section .text
global _start
_start:
; Initialize screen
call clear_screen
call draw_pacman
call draw_ghost
call draw_dots
game_loop:
; Move Pac-Man
call move_pacman
; Clear the screen
clear_screen:
mov ah, 0
mov al, 3
int 10h
ret
; Draw Pac-Man at current position
draw_pacman:
mov ah, 0ch
mov al, 00001111b
mov cx, [pacman_x]
mov dx, [pacman_y]
int 10h
ret
; Draw ghost at current position
draw_ghost:
mov ah, 0ch
mov al, 00001100b
mov cx, [ghost_x]
mov dx, [ghost_y]
int 10h
ret
; Draw dots on screen
draw_dots:
mov ah, 0ch
mov al, 00001111b
mov cx, 5
mov dx, 5
dots_loop:
int 10h
add cx, 10
dec word [dots_remaining]
cmp [dots_remaining], 0
jne dots_loop
ret
; Move Pac-Man based on user input
move_pacman:
; Get user input
mov ah, 0
int 16h
cmp al, 'w'
je move_up
cmp al, 's'
je move_down
cmp al, 'a'
je move_left
cmp al, 'd'
je move_right
ret
move_up:
sub word [pacman_y], 1
call draw_pacman
ret
move_down:
add word [pacman_y], 1
call draw_pacman
ret
move_left:
sub word [pacman_x], 1
call draw_pacman
ret
move_right:
add word [pacman_x], 1
call draw_pacman
ret
; Check for collision between Pac-Man and ghost
check_collision:
cmp [pacman_x], [ghost_x]
je collision_x
cmp [pacman_y], [ghost_y]
je collision_y
ret
collision_x:
cmp word [pacman_y], [ghost_y]
je game_over
ret
collision_y:
cmp word [pacman_x], [ghost_x]
je game_over
ret
; Check for victory condition
check_victory:
cmp [dots_remaining], 0
jne continue_game
; Victory screen
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, victory_message
int 21h
jmp end_game
continue_game:
ret
; Handle user input
handle_input:
; Check if key has been pressed
mov ah, 1
int 16h
jz no_input
; Handle input
cmp al, 'q'
je end_game
jmp no_input
no_input:
ret
; Game over screen
game_over:
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, game_over_message
int 21h
jmp end_game
; End the game
end_game:
mov ah, 4ch
mov al, 0
int 21h
; Define messages
victory_message db 'You won!', 0
game_over_message db 'Game over.', 0