← Back to projects

pacman-asm

pac-man, in x86 assembly, with the Irvine library doing the console work.

A full Pac-Man clone: player movement, three ghosts, coins, fruit, wall-following, teleporting tunnels, win and lose states, and sound effects for coins, fruit, and death. All of it written as a long wall of MASM PROCs against the Irvine32 library, with no engine and no abstraction layer between the game loop and the console.

source

how a ghost catches you

There's no physics engine here, just direct register comparisons run every frame. Each ghost gets its own collisionCheck PROC that compares the player's grid position to the ghost's, byte by byte, and decrements a life counter on a match. It's the kind of code you only write once you understand exactly what a CPU is doing with your game state, because nothing is hidden from you.

collisionCheck PROC
    xor eax, eax
    xor ebx, ebx
    mov al, xPos
    cmp al, enemyXPos
    jne notCollidingwithenemy
    mov al, yPos
    cmp al, enemyYPos
    jne notCollidingwithenemy
    ; player is intersecting enemy
    dec lives
    mov al, lives
    cmp al, 0
    je gameoverscr1
    ret
    gameoverscr1:
    call gameisover
    notCollidingwithenemy:
    ret
collisionCheck ENDP
source.asm, collisionCheck

x86 Assembly (MASM), Irvine32