The Pacman game is a classic arcade-style game where the player controls a character that moves inside a maze, collects food pellets, and avoids enemies. The objective is to maximize the score by eating all the food while avoiding the ghost. The game ends when Pacman collides with the ghost.
Approach
The game maze is represented using a 2D character array.
Pacman (C) moves inside the maze using keyboard inputs.
Food pellets (.) are placed across the maze and increase the score when eaten.
A ghost (G) moves automatically and tries to chase Pacman.
Collision with walls is restricted, and collision with the ghost ends the game.
The screen is continuously updated to simulate motion.
Libraries Used
<stdio.h>: Used for input/output operations like printf.
<stdlib.h>: Used for functions like system().
<windows.h>: Used for cursor control, keyboard input, and delay functions.
Functions
setup(): Initializes game variables such as positions and score.
clearScreen(): Clears the console buffer efficiently to prevent flickering.
draw(): Displays the maze, Pacman, ghost, and score on the console.
input(): Handles real-time keyboard input using GetAsyncKeyState.
logic(): Updates food consumption, ghost movement, and collision detection.