Files
Pacman-Project/pacman-project/constants.rkt
joren 9028dd031c Add ghost CPUs with original Pac-Man AI targeting
Implement four ghosts (Blinky, Pinky, Inky, Clyde) with authentic
Pac-Man AI: Blinky chases directly, Pinky targets 2 tiles ahead
(with original up-direction bug), Inky uses vector doubling from
Blinky, Clyde switches to scatter within 8-tile radius.

Includes chase/scatter mode cycling, ghost house exit with staggered
delays, directional sprite rendering with animation, and ghost-pacman
collision detection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 11:42:34 +01:00

291 lines
7.4 KiB
Racket

#lang r7rs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Constants ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; All configuration constants for the Pac-Man game. Prevents magic numbers
;; throughout the codebase and makes the game easily configurable.
(define-library (pacman-project constants)
(import (scheme base))
(export ;; Window
window-width-px
window-height-px
;; Maze grid
cell-size-px
maze-offset-y
maze-wall-shrink
;; Cell types
cell-type-coin
cell-type-wall
cell-type-empty
cell-type-key
cell-type-door
;; Coin rendering
coin-inset
coin-size
;; Sprites
sprite-scale-pacman
sprite-scale-key
sprite-scale-key-ui
sprite-scale-ghost
;; Movement
pacman-speed-ms
ghost-speed-ms
;; Ghost house
ghost-house-door-row
ghost-house-door-col-left
ghost-house-door-col-right
ghost-house-exit-row
ghost-house-exit-col
;; Ghost start positions
blinky-start-row
blinky-start-col
pinky-start-row
pinky-start-col
inky-start-row
inky-start-col
clyde-start-row
clyde-start-col
;; Ghost scatter corners
blinky-scatter-row
blinky-scatter-col
pinky-scatter-row
pinky-scatter-col
inky-scatter-row
inky-scatter-col
clyde-scatter-row
clyde-scatter-col
;; Ghost house exit delays (ms)
pinky-exit-delay
inky-exit-delay
clyde-exit-delay
;; Ghost mode durations (ms)
scatter-duration-1
chase-duration-1
scatter-duration-2
chase-duration-2
scatter-duration-3
;; Ghost AI
clyde-shy-distance
pinky-look-ahead
;; Animation
animation-interval-ms
;; Score
points-per-coin
;; Time limit
start-time-seconds
ms-per-second
time-bonus-per-coin
;; Key placement
max-placement-attempts
;; Rotation angles
rotation-right
rotation-left
rotation-up
rotation-down
;; Colors
color-background
color-wall
color-door
color-coin
color-text
color-title
color-header-bg
color-game-over
color-pause-bg
color-pause-text
;; UI layout
header-height
header-title-size
header-title-x
header-title-y
score-label-size
score-label-x
score-label-y
score-value-size
score-value-x
score-value-y
key-ui-x
key-ui-y
sidebar-x
sidebar-width
time-label-size
time-label-x
time-label-y
time-value-size
time-value-x
time-value-y
game-over-text-size
game-over-text-x
game-over-text-y
pause-text-size
pause-text-x
pause-text-y)
(begin
;; Window dimensions
(define window-width-px 1000)
(define window-height-px 830)
;; Maze grid configuration
(define cell-size-px 24)
(define maze-offset-y 97)
(define maze-wall-shrink 6)
;; Cell type encoding for the maze grid
(define cell-type-coin 0)
(define cell-type-wall 1)
(define cell-type-empty 2)
(define cell-type-key 3)
(define cell-type-door 4)
;; Coin rendering
(define coin-inset 9)
(define coin-size 6)
;; Sprite scale factors
(define sprite-scale-pacman 1.5)
(define sprite-scale-key 1.5)
(define sprite-scale-key-ui 3)
(define sprite-scale-ghost 1.5)
;; Movement speed: time between automatic movement ticks
(define pacman-speed-ms 200)
(define ghost-speed-ms 220)
;; Ghost house position (door and exit point above door)
(define ghost-house-door-row 12)
(define ghost-house-door-col-left 13)
(define ghost-house-door-col-right 14)
(define ghost-house-exit-row 11)
(define ghost-house-exit-col 14)
;; Ghost start positions
(define blinky-start-row 11)
(define blinky-start-col 14)
(define pinky-start-row 14)
(define pinky-start-col 13)
(define inky-start-row 14)
(define inky-start-col 11)
(define clyde-start-row 14)
(define clyde-start-col 16)
;; Ghost scatter target corners
(define blinky-scatter-row 0)
(define blinky-scatter-col 27)
(define pinky-scatter-row 0)
(define pinky-scatter-col 0)
(define inky-scatter-row 30)
(define inky-scatter-col 27)
(define clyde-scatter-row 30)
(define clyde-scatter-col 0)
;; Ghost house exit delays (ms) — staggered release
(define pinky-exit-delay 2000)
(define inky-exit-delay 5000)
(define clyde-exit-delay 8000)
;; Ghost mode durations (ms) — scatter/chase alternation
(define scatter-duration-1 7000)
(define chase-duration-1 20000)
(define scatter-duration-2 7000)
(define chase-duration-2 20000)
(define scatter-duration-3 5000)
;; Ghost AI parameters
(define clyde-shy-distance 8)
(define pinky-look-ahead 2)
;; Animation timing
(define animation-interval-ms 100)
;; Score configuration
(define points-per-coin 10)
;; Time limit configuration
(define start-time-seconds 60)
(define ms-per-second 1000)
(define time-bonus-per-coin 1)
;; Key placement
(define max-placement-attempts 1000)
;; Rotation angles (degrees)
(define rotation-right 0)
(define rotation-left 180)
(define rotation-up 90)
(define rotation-down -90)
;; Colors — arcade-style palette (standard Racket color names only)
(define color-background "black")
(define color-wall "medium blue")
(define color-door "hot pink")
(define color-coin "gold")
(define color-text "white")
(define color-title "yellow")
(define color-header-bg "dark slate gray")
(define color-game-over "red")
(define color-pause-bg "black")
(define color-pause-text "red")
;; UI layout — header bar at the top
(define header-height 90)
(define header-title-size 36)
(define header-title-x 250)
(define header-title-y 25)
;; Score display (left side of header)
(define score-label-size 20)
(define score-label-x 20)
(define score-label-y 25)
(define score-value-size 32)
(define score-value-x 20)
(define score-value-y 50)
;; Key UI indicator position
(define key-ui-x 600)
(define key-ui-y 30)
;; Sidebar (right of maze)
(define sidebar-x 672)
(define sidebar-width 4)
;; Time display (right sidebar area)
(define time-label-size 20)
(define time-label-x 700)
(define time-label-y 200)
(define time-value-size 40)
(define time-value-x 710)
(define time-value-y 240)
;; Game over overlay
(define game-over-text-size 48)
(define game-over-text-x 180)
(define game-over-text-y 380)
;; Pause overlay
(define pause-text-size 48)
(define pause-text-x 200)
(define pause-text-y 400)))