Behaviors - Plugins Infinite Pac-Man

Not favoritedFavorited Favorited 0 favourites
  • 1 posts
From the Asset Store
Fully animated top down men game asset character pack.
  • Hello everyone in the community!

    I want to share with you the technical heart of my current project: Infinite Pac-Man. The basic idea is straightforward: to create a Pac-Man game with procedurally generated, infinite mazes, but with updated music and mechanics. However, as a developer, I imposed an unbreakable golden rule on myself: the Artificial Intelligence and the feeling of control had to be 100% faithful to the original 1980 arcade game.

    I didn't want to use Construct's default Pathfinding or solid physics; I wanted to replicate the exact mathematics of the classic grid. And I confess that programming it entirely from scratch using the JavaScript SDK was a real headache.

    I spent days battling classic bugs like Gravity Wells (ghosts trapped in orbital loops) and the eye "vibration" (which, when colliding with walls in Eaten mode, would enter infinite spinning cycles). Through trial and error, I developed a grid-based movement system that doesn't use physics, but rather Euclidean distance calculations and logical movement rules.

    To ensure everything runs autonomously, cleanly, and without cluttering the event sheet, I created four technical tools. Here's what each one does:

    1. Behavior GhostMovement (The AI ​​Brain)

    This is the logic engine for the enemies. It doesn't use the solids or physics system, but instead evaluates the map using a strict grid system (32x32).

    Targeting System: Depending on its personality (Blinky, Pinky, Inky, Clyde) and current state (Chase, Scatter, Frightened, Eaten), the behavior calculates a target (X, Y) coordinate.

    Look-Ahead Pathfinding: At each tile center, the ghost scans the valid neighboring cells (filtering walls using the Tilemap ID). It calculates the distance from those cells to its target and chooses the shortest path, always blocking the possibility of a U-turn unless the cells change state.

    2. Pacman Movement Behavior (Player Control)

    Making Pac-Man move smoothly while remaining anchored to a grid requires technical precision.

    Input Queuing (Key Buffer): To achieve the famous cornering effect, the behavior registers the key pressed a fraction of a second before reaching an intersection. Upon reaching the exact center of the tile, it automatically applies the turn, preventing the player from getting stuck in corners.

    Grid Alignment: It keeps the sprite aligned to the X or Y axis while moving, checking in advance if the next tile is a walkable space (walkableID). If it's a wall, it stops the movement abruptly at the exact center of the cell.

    3. ArcadeGenerator Plugin (The Architect)

    This plugin builds the world. It is responsible for creating the environment in real time on a Tilemap object.

    Procedural Generation: Uses traversal algorithms to carve mazes, ensuring that there are always connected paths and zero dead ends.

    Bitmasking (Autotiling): Reads a numerical matrix and applies the correct visual tile based on the neighbors of each cell, automatically injecting corners and junctions.

    Fixed Central Structure: Reserves and draws the "Ghost House" in the exact center with its rigid walls and invisible door, guaranteeing that the respawn point is never corrupted.

    4. Behavioral Tilemap Spawner (The Villager)

    Once the maze is built, the level needs life. This behavior scans the terrain to place items (pills).

    Scanning and Generation: Traverses the main Tilemap looking for the Target Tile ID (the cell where the object should appear).

    Exclusion Filter: Allows linking a second Tilemap (the floor tilemap). If the ID matches the forbidden zone (like inside the house or on top of the walls), the Spawner simply doesn't create the object, preventing visual or logical errors.

    It's been a tremendous technical challenge programming this solo. The base engine is already rock solid, so now I need to focus on the power-ups, the infinite difficulty curve, and the audiovisual polish.

    Fun fact: If you listen closely to the "Waka Waka" sound effect Pac-Man makes when moving... it's not the one from the original arcade. It's Shakira's "Waka Waka"! It's a little personal touch I decided to include in the project to add some humor :D.

    Has anyone else tried battling pure grid-based AI in Construct? I'd love to read about your experiences or get answers to any questions about the code!

    Any feedback is super welcome.

    I went a little overboard with the code for the demo, though it's not much XD.

    DEMO:https://infinitepacman.netlify.app/

    And here's just a sneak peek at what's coming with the plugins I've been working on. It's just a matter of changing and adding a couple of behaviors to what's shown above, changing the controls, adding the camera, and voila! We've gone from a 2D game to a 3D game. Ta-da!

    DEMO 3D: https://pacmaninfinite3d.netlify.app/

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)