How would you do pac-man?????

OK, here’s what I got done after an hour and a half. (If I’d remembered about the tile flip feature in my own editor in time I could have saved some bother. :p) No sound, or ghosts…hey, the AI in the original took months to program. :wink: I slightly hacked the character controller from one of the demos in SpriteTile to save time. Attached is the project, you’ll need SpriteTile though. (And when adding SpriteTile, hook up the TileManager in Plugins/SpriteTile/Resources first, if it doesn’t work automatically.)

WebGL

2790763--202585--pacman.png

Behind the scenes in SpriteTile, an array is used to represent the level. Movement basically consists of going from one tile to the next, and checking the contents. Walls are marked as colliders, so it’s more or less just this:

if (Tile.GetCollider (mapPos + dir)) // see if collider tile exists at current position + attempted direction

The move function in the PacMan script is this (the dir and characterWasMoving variables are because of the character controller script but aren’t used for this game):

function StartMove (dir : Int2, mapPos : Int2, characterWasMoving : boolean) {
    var tile : TileInfo = Tile.GetTile (mapPos);
    if (tile.tile == TileType.Dot) {
        gameControl.AddScore (10);
        Tile.DeleteTile (mapPos);
    }
    else if (tile.tile == TileType.Pill) {
        gameControl.AddScore (50);
        Tile.DeleteTile (mapPos);
    }
}

Presumably you’d add an appropriate PowerPillEaten() function when adding ghosts.

–Eric

Edit: tweaked project to use tile flipping, since it was bugging me. :stuck_out_tongue:

2790763–202356–PacManClone.zip (643 KB)

4 Likes