How shaiderm16/pac-man-game works
Main Components
• Game Engine/Core Loop: At the heart of the program, the engine manages the game cycle, which includes processing user input, updating game states (e.g., moving Pac-Man, moving ghosts, collision detection), and rendering changes to the map.
• Input Handling: Represents key presses (W, A, S, D, and Q) that trigger movement or game-state commands.
• Entity Management:
• Pac-Man: Tracked via its coordinates (pacmanX, pacmanY) and associated flags for tracking visited positions.
• Ghosts: Handled as structures (the Ghost struct) with their own positions and movement logic.
• Pellets & Walls: Represented on the map by designated characters and managed via functions like initialisePellets.
• Scoring and Lifespan Mechanics: Global variables like score and lives are changed via functions like incrementScore and decrementLive.
• Persistence: Save and Load capabilities (implemented with saveGame and loadGame) to store and retrieve the game state.
Component Relationships and Interactions
• Input (keyboard events) feeds into the Game Engine, which directs how the state is updated.
• The Game Engine uses its Internal Logic module to call functions that move entities (both Pac-Man and ghosts) and update the game map.
• Updated game states interact with the Rendering module, which displays the current board to the player.
• Entity interactions (like collisions) affect game state changes (e.g., decrementing lives when Pac-Man meets a ghost, or incrementing score when collecting pellets).
• The Persistence module (Save/Load) interacts with the game state, allowing the game to be paused and restored.
Architectural Patterns/Design Principles
• Procedural Programming: The project is implemented in a procedural C programming style with clearly separated functions for different behaviors.
• Modularity (within a single source file): Although all code resides in one C file (pacman.c), logically it can be separated into discrete responsibilities (initialization, input processing, state updates, rendering, and persistence).
• State Management: Uses global state variables for score, lives, and entity positions to control game flow.
What
• Main Components:
• Input Handling (keyboard controls)
• Game Engine / Core Loop
• Game State Management (global variables such as score, lives, pacmanX & pacmanY, ghost positions)
• Rendering/Display Module (displayMap and setTextColor usage)
• Persistence/State Storage (saveGame and loadGame)
• For example, input triggers actions in the Game Engine, which then updates the map, adjusts entity positions, and invokes rendering, as well as optionally saving state.