Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PACCRAFT poster

DEMO:

DEMO.mp4

Game Architecture: The Object-Oriented Engine

At its core, PACCRAFT relies on solid Object-Oriented Programming (OOP) principles, specifically utilizing a Component-Based Architecture paired with the Strategy Pattern. This ensures the codebase remains highly modular, preventing it from turning into a tangled mess of spaghetti code.

Think of this architecture like building a car. Instead of welding the engine permanently to the chassis, you build a standard chassis (the Entity), and then you drop in whichever engine you want (the MovementStrategy).

  • The Entities (The Chassis): We use inheritance to create a hierarchy of game objects. The base class holds universal data (X and Y coordinates, width, height, and an image). From there, we branch out. Walls and items don't need speed or direction, so they remain basic entities. Pacman and the Mobs extend this base class to include movement data.
  • The Strategies (The Engines): Instead of hardcoding AI directly into the mobs, we use a standard MovementStrategy parent class. We then create specific child classes for different behaviors (like random wandering or active targeting). When a mob is spawned, it is handed a specific strategy. When it's time to move, the mob simply asks its strategy which way to steer.
  • The Managers (The Pit Crew): Dedicated classes handle specific behind-the-scenes jobs. The CollisionManager processes all the overlapping math, and the SoundManager pre-loads and triggers audio clips.

Map, Spawning, and the Basics

The entire game world is generated from a simple 2D text array. Each character in the array acts as a blueprint for a 32x32 pixel tile on the screen.

  1. X builds a Wall.

  2. W builds a Ghost Barrier (blocking mobs but letting the player pass).

  3. B drops a high-value Bonus item.

  4. P spawns Pacman.

  5. z, s, b, c spawn the different Minecraft mobs.

  6. ' ' (Space) drops standard food.

When the game boots up, a loop reads this grid row by row, column by column. As it reads each letter, it creates the corresponding object and places it in the exact X and Y coordinate on the screen. It is a highly efficient way to design levels without needing a complex graphic editor.

Direction and Movement: The Input Buffer

Moving in a grid-based game can feel clunky if not handled correctly. If a player presses "Up" a fraction of a second before they actually reach an opening in the wall, a poorly coded game will ignore the input, and the player will walk right past the turn.

To fix this, PACCRAFT uses an Input Buffer (nextDirection).

Think of this like a train conductor approaching a junction. You radio the conductor and say, "Turn left at the next switch." The conductor acknowledges this and keeps driving straight until the left turn is physically available. In the game, when you press a key, Pacman saves that direction in his memory. Every frame, the game checks if that saved direction is clear of walls. The moment it is clear, Pacman automatically snaps into the turn. This makes the controls feel incredibly fluid and responsive.

The Collision System: Look-Ahead Logic

Most basic games handle collisions poorly: they let the character step forward, check if they are stuck inside a wall, and if so, teleport them backward. This causes visual stuttering and bugs. PACCRAFT uses Look-Ahead Collision.

Imagine walking through a dark room with your arm extended. Instead of slamming your face into a door and taking a step back, your hand hits the door first, telling your brain not to take the step at all. Before any entity in the game moves, it calculates its intended next X and Y coordinates. It then projects a virtual "bounding box" (a mathematical rectangle representing the entity's size) into that future space. If that future space overlaps with a wall's bounding box, the entity's velocity is ignored, and it stays exactly where it is.

The Mob Types: Artificial Intelligence

The enemies in PACCRAFT are not just moving randomly; they have distinct personalities and targeting systems based on the Pythagorean theorem (calculating the shortest straight-line distance between two points).

  1. The Zombie (z): The relentless tracker. It constantly calculates Pacman's exact current coordinates and chooses the path that brings it mathematically closer. It moves at pacman speed or slower speed.

  2. The Skeleton (s): The ambusher. Instead of walking toward where Pacman is, it calculates where Pacman is going. It projects a target 4 tiles ahead of Pacman's current trajectory and tries to cut him off. It also moves at pacman speed or slower speed.

  3. The Black Skeleton (b): The wild card. It moves at the same high speed as Pacman but chooses its path completely randomly at every intersection.

  4. The Creeper (c): The chaotic threat. It moves randomly at high speed, but if it catches you, it triggers an explosive audio event. To prevent mobs from getting stuck on corners, they are programmed to only make turning decisions when they are perfectly aligned with the grid intersections by checking if their current postion is completely divisible by tilesize.

Gameplay Mechanism: How to Play

The Objective:

You are Pacman. Your goal is to clear the labyrinth of all the standard food items while avoiding the hostile Minecraft mobs roaming the halls.

The Controls:

Use the Up, Down, Left, and Right Arrow Keys to navigate the maze. Thanks to the input buffer, you can hold down your next desired turn before you even reach the intersection for perfectly sharp corners.

Scoring and Survival:

  • Food: Each standard food item consumed adds 100 points to your score.
  • Lives: You begin with 5 lives (represented by hearts in the HUD). Touching a mob will instantly kill you, freezing the screen for 2 seconds before resetting everyone back to their starting spawn points.
  • The Tunnel: On the left and right sides of the map, there is a teleportation tunnel. Walking into it instantly transports you to the other side of the map. The mobs are blocked by invisible barriers and cannot use this tunnel.

The Bonus Mechanic:

Hidden in the maze are Bonus items. Eating one grants you 1000 points and triggers a "Level Up" sound. More importantly, it grants you 15 seconds of invincibility. During this window, the tables turn. If you collide with a mob while invincible, you destroy the mob, earning a massive 500 point bonus. The defeated mob is instantly sent back to its spawn point to regenerate. Clear the board of all standard food to trigger the WINNER! screen. Press ENTER to reset the maze and play again.

About

A Minecrat Pacman Game.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages