User prompt
Add an object that uses 5 different assets and swaps through them ever 1/4th of a second. Make it only spawn once and make it move around and give you 1000-2000 points. DONT do anything on startgame
User prompt
Add cherries that give you a bunch of points
User prompt
The player spawns in the wall on level 4
User prompt
Make more content
User prompt
Add a lot more content
User prompt
Make a second Pacman sprite that Pacman changes to every half second
User prompt
Pacman spawns in the wall in maze 2
User prompt
Make maze 2 significantly different
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'MAZE[row][col]')' in or related to this line: 'return MAZE[row][col] === 1;' Line Number: 460
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var cell = MAZE[row][col];' Line Number: 329
User prompt
Make a second maze that spawns when you click maze 2
User prompt
Add a maze selection screen button in the corner that shows 2 buttons; maze 1, maze 2
User prompt
Add a maze selection screen button in the corner
User prompt
Fix it
User prompt
Move Pacman back to his original position
User prompt
Still kills me
User prompt
Spawn Pacman before maze is selected, but wait to spawn the ghosts
User prompt
It is still auto killing me
User prompt
It kills me automatically because Pacman isn’t spawning
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var cell = MAZE[row][col];' Line Number: 233
User prompt
Move it up
User prompt
Move it to the left
User prompt
Move it to the left And the text
User prompt
Move it to the left
User prompt
More
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Ghost class var Ghost = Container.expand(function () { var self = Container.call(this); self.colorId = 'ghost_red'; // default, will be set on init self.frightened = false; self.dir = { x: 0, y: 0 }; self.speed = 7; self.gridX = 0; self.gridY = 0; self.scatterTarget = { x: 0, y: 0 }; // for future AI self.mode = 'chase'; // 'chase', 'scatter', 'frightened' self.frightTimer = 0; self.attach = function (colorId) { self.colorId = colorId; self.removeChildren(); var ghostGfx = self.attachAsset(colorId, { anchorX: 0.5, anchorY: 0.5 }); }; self.setFrightened = function (on) { self.frightened = on; self.removeChildren(); if (on) { self.attachAsset('ghost_fright', { anchorX: 0.5, anchorY: 0.5 }); } else { self.attachAsset(self.colorId, { anchorX: 0.5, anchorY: 0.5 }); } }; self.update = function () { self.x += self.dir.x * self.speed; self.y += self.dir.y * self.speed; }; return self; }); // Pacman class var Pacman = Container.expand(function () { var self = Container.call(this); var pacmanGfx = self.attachAsset('pacman', { anchorX: 0.5, anchorY: 0.5 }); self.radius = pacmanGfx.width / 2; self.dir = { x: 1, y: 0 }; // Start moving right self.nextDir = { x: 1, y: 0 }; self.speed = 8; // pixels per tick self.gridX = 0; self.gridY = 0; self.moving = true; self.update = function () { if (!self.moving) return; // Move Pacman self.x += self.dir.x * self.speed; self.y += self.dir.y * self.speed; }; return self; }); // Pellet class var Pellet = Container.expand(function () { var self = Container.call(this); self.isPower = false; self.attach = function (isPower) { self.isPower = isPower; self.removeChildren(); if (isPower) { self.attachAsset('powerpellet', { anchorX: 0.5, anchorY: 0.5 }); } else { self.attachAsset('pellet', { anchorX: 0.5, anchorY: 0.5 }); } }; return self; }); // Wall class var Wall = Container.expand(function () { var self = Container.call(this); self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // 19x23 grid (classic Pacman aspect, fits 2048x2732 well) // 0: empty, 1: wall, 2: pellet, 3: power pellet // --- Maze Layout --- // Pacman (yellow circle) // Pellet (small white dot) // Power Pellet (bigger blue dot) // Wall (blue box) // Ghosts (four colors) // Frightened ghost (white) var MAZE_ROWS = 23; var MAZE_COLS = 19; var CELL_SIZE = 112; // 19*112=2128, 23*112=2576, fits in 2048x2732 with margin var MAZE_OFFSET_X = (2048 - MAZE_COLS * CELL_SIZE) / 2; var MAZE_OFFSET_Y = (2732 - MAZE_ROWS * CELL_SIZE) / 2 + 40; // --- Multiple Mazes for More Content --- var MAZES = []; // Maze 1 (original) MAZES[0] = [ // Open up top row for pellets: add pellets (2) and open up more wall spaces for access [1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 1], [1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1], [1, 3, 1, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 1, 3, 1, 1], [1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1], [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1], // Open up middle (row 9, col 0, 9,10,11, 18) [0, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, 0], [0, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 0], // Open up center of row 11 (row 11, col 9) [1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1], // Open up middle (row 15, col 0, 9, 18) [0, 3, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 3, 0], // Open up bottom center (row 16, col 0, 9, 18) [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 0], [0, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 2, 0], [0, 2, 1, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 1, 2, 2, 0], // Open up (column 10, row 17) [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 0, 1, 2, 2, 2, 2, 2, 2, 1], // Open up bottom center (row 21, col 9) [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], // Open up bottom row (row 22, col 9) [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]]; // Remove wall below ghost spawn (row 12, col 9) to allow escape MAZES[0][12][9] = 0; // Widen the gap below ghost spawn (row 13, cols 8, 9, 10) MAZES[0][13][8] = 0; MAZES[0][13][9] = 0; MAZES[0][13][10] = 0; // Maze 2 (new, more content, different layout) MAZES[1] = [[1, 3, 2, 2, 2, 1, 2, 2, 2, 0, 2, 2, 2, 1, 2, 2, 2, 3, 1], [1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1], [1, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 1], [1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1], [0, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0], [0, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 0], [1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1], [0, 3, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 3, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 0], [0, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 2, 0], [0, 2, 1, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 1, 2, 2, 0], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 0, 1, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]]; // Remove wall below ghost spawn (row 12, col 9) to allow escape MAZES[1][12][9] = 0; // Widen the gap below ghost spawn (row 13, cols 8, 9, 10) MAZES[1][13][8] = 0; MAZES[1][13][9] = 0; MAZES[1][13][10] = 0; // Current maze index var currentMazeIndex = 0; var MAZE = MAZES[currentMazeIndex]; // --- Game State --- var pellets = []; var walls = []; var ghosts = []; var pacman = null; var score = 0; var pelletsLeft = 0; var frightTicks = 0; var frightActive = false; var frightDuration = 360; // 6 seconds at 60fps var swipeStart = null; var dragNode = null; var lastGameOver = false; // --- Score Display --- var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // --- Maze Selection Button --- // Place a button in the top-right corner, avoiding the top-left 100x100 area var mazeBtn = new Text2('🧩', { size: 100, fill: "#fff" }); mazeBtn.anchor.set(1, 0); // right-top mazeBtn.x = 0; // Will be positioned by LK.gui mazeBtn.y = 0; mazeBtn.interactive = true; mazeBtn.buttonMode = true; mazeBtn._isMazeBtn = true; // Mark for event filtering // Add to GUI topRight (safe from menu) LK.gui.topRight.addChild(mazeBtn); // Button handler: cycle maze and restart game mazeBtn.down = function (x, y, obj) { // Cycle to next maze currentMazeIndex = (currentMazeIndex + 1) % MAZES.length; MAZE = MAZES[currentMazeIndex]; startGame(); }; // --- Maze Build --- function buildMaze() { // Clear previous for (var i = 0; i < pellets.length; ++i) pellets[i].destroy(); for (var i = 0; i < walls.length; ++i) walls[i].destroy(); pellets = []; walls = []; pelletsLeft = 0; for (var row = 0; row < MAZE_ROWS; ++row) { for (var col = 0; col < MAZE_COLS; ++col) { var cell = MAZE[row][col]; var x = MAZE_OFFSET_X + col * CELL_SIZE + CELL_SIZE / 2; var y = MAZE_OFFSET_Y + row * CELL_SIZE + CELL_SIZE / 2; if (cell === 1) { var wall = new Wall(); wall.x = x; wall.y = y; game.addChild(wall); walls.push(wall); } else if (cell === 2 || cell === 3) { // Prevent pellets from spawning at ghost spawn locations (center of maze) // Ghosts spawn at (row 11, col 9), (row 11, col 8), (row 11, col 10), (row 12, col 9) var isGhostSpawn = row === 11 && (col === 8 || col === 9 || col === 10) || row === 12 && col === 9; if (!isGhostSpawn) { var pellet = new Pellet(); pellet.x = x; pellet.y = y; pellet.attach(cell === 3); game.addChild(pellet); pellets.push(pellet); pelletsLeft++; } } } } } // --- Pacman Init --- function spawnPacman() { if (pacman) pacman.destroy(); pacman = new Pacman(); // Start position: center of maze, row 15, col 9 pacman.gridX = 9; pacman.gridY = 15; pacman.x = MAZE_OFFSET_X + pacman.gridX * CELL_SIZE + CELL_SIZE / 2; pacman.y = MAZE_OFFSET_Y + pacman.gridY * CELL_SIZE + CELL_SIZE / 2; pacman.dir = { x: 1, y: 0 }; pacman.nextDir = { x: 1, y: 0 }; pacman.moving = true; game.addChild(pacman); } // --- Ghosts Init --- function spawnGhosts() { // Remove old ghosts for (var i = 0; i < ghosts.length; ++i) ghosts[i].destroy(); ghosts = []; // Four ghosts, different colors, start in center var ghostColors = ['ghost_red', 'ghost_pink', 'ghost_blue', 'ghost_orange']; var ghostStarts = [{ col: 9, row: 11 }, { col: 8, row: 11 }, { col: 10, row: 11 }, { col: 9, row: 12 }]; for (var i = 0; i < 4; ++i) { var ghost = new Ghost(); ghost.attach(ghostColors[i]); ghost.gridX = ghostStarts[i].col; ghost.gridY = ghostStarts[i].row; ghost.x = MAZE_OFFSET_X + ghost.gridX * CELL_SIZE + CELL_SIZE / 2; ghost.y = MAZE_OFFSET_Y + ghost.gridY * CELL_SIZE + CELL_SIZE / 2; // Initial direction: up or left/right if (i === 0) ghost.dir = { x: 0, y: -1 };else if (i === 1) ghost.dir = { x: -1, y: 0 };else if (i === 2) ghost.dir = { x: 1, y: 0 };else ghost.dir = { x: 0, y: 1 }; ghost.frightened = false; ghosts.push(ghost); game.addChild(ghost); } } // --- Utility: Grid <-> Pixel --- function posToGrid(x, y) { var col = Math.floor((x - MAZE_OFFSET_X) / CELL_SIZE); var row = Math.floor((y - MAZE_OFFSET_Y) / CELL_SIZE); return { col: col, row: row }; } function gridToPos(col, row) { return { x: MAZE_OFFSET_X + col * CELL_SIZE + CELL_SIZE / 2, y: MAZE_OFFSET_Y + row * CELL_SIZE + CELL_SIZE / 2 }; } function isWall(col, row) { if (col < 0 || col >= MAZE_COLS || row < 0 || row >= MAZE_ROWS) return true; return MAZE[row][col] === 1; } // --- Pacman Movement & Input --- function canMove(col, row, dir) { var nextCol = col + dir.x; var nextRow = row + dir.y; return !isWall(nextCol, nextRow); } function updatePacmanDirection() { var grid = posToGrid(pacman.x, pacman.y); // Snap to center of cell var center = gridToPos(grid.col, grid.row); var dx = Math.abs(pacman.x - center.x); var dy = Math.abs(pacman.y - center.y); if (dx < 4 && dy < 4) { // At center, can change direction if (canMove(grid.col, grid.row, pacman.nextDir)) { pacman.dir = { x: pacman.nextDir.x, y: pacman.nextDir.y }; } // If can't move in current dir, stop if (!canMove(grid.col, grid.row, pacman.dir)) { pacman.moving = false; } else { pacman.moving = true; } // Snap to center pacman.x = center.x; pacman.y = center.y; } } // --- Ghost Movement (Random for MVP, smarter later) --- function getValidGhostDirs(ghost) { var grid = posToGrid(ghost.x, ghost.y); var dirs = [{ x: 1, y: 0 }, { x: -1, y: 0 }, { x: 0, y: 1 }, { x: 0, y: -1 }]; var valid = []; for (var i = 0; i < dirs.length; ++i) { var d = dirs[i]; // Don't reverse direction if (ghost.dir.x === -d.x && ghost.dir.y === -d.y) continue; if (!isWall(grid.col + d.x, grid.row + d.y)) valid.push(d); } return valid; } function updateGhostDirection(ghost) { var grid = posToGrid(ghost.x, ghost.y); var center = gridToPos(grid.col, grid.row); var dx = Math.abs(ghost.x - center.x); var dy = Math.abs(ghost.y - center.y); if (dx < 4 && dy < 4) { // At center, pick new direction var valid = getValidGhostDirs(ghost); if (valid.length === 0) { ghost.dir = { x: -ghost.dir.x, y: -ghost.dir.y }; } else { // MVP: random direction var idx = Math.floor(Math.random() * valid.length); ghost.dir = { x: valid[idx].x, y: valid[idx].y }; } // Snap to center ghost.x = center.x; ghost.y = center.y; } } // --- Pellet Eating --- function checkPelletEat() { for (var i = pellets.length - 1; i >= 0; --i) { var pellet = pellets[i]; var dx = pacman.x - pellet.x; var dy = pacman.y - pellet.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 48) { // Eat pellet if (pellet.isPower) { frightTicks = frightDuration; frightActive = true; for (var g = 0; g < ghosts.length; ++g) { ghosts[g].setFrightened(true); } } pellet.destroy(); pellets.splice(i, 1); pelletsLeft--; score += pellet.isPower ? 50 : 10; scoreTxt.setText(score); LK.setScore(score); if (pelletsLeft === 0) { // Switch to next maze if available, else loop back to first currentMazeIndex = (currentMazeIndex + 1) % MAZES.length; MAZE = MAZES[currentMazeIndex]; LK.showYouWin(); } } } } // --- Ghost Collisions --- function checkGhostCollisions() { for (var i = 0; i < ghosts.length; ++i) { var ghost = ghosts[i]; var dx = pacman.x - ghost.x; var dy = pacman.y - ghost.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 60) { if (frightActive && ghost.frightened && ghost.visible !== false) { // Eat ghost: make invisible, respawn after fright ends ghost.visible = false; score += 200; scoreTxt.setText(score); LK.setScore(score); } else if (!frightActive && ghost.visible !== false) { // Pacman dies if (!lastGameOver) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); lastGameOver = true; } } } } } // --- Frightened Mode Timer --- function updateFrightened() { if (frightActive) { frightTicks--; if (frightTicks <= 0) { frightActive = false; for (var g = 0; g < ghosts.length; ++g) { ghosts[g].setFrightened(false); // If ghost was eaten (invisible), respawn at home if (ghosts[g].visible === false) { var home = gridToPos(9, 11); ghosts[g].x = home.x; ghosts[g].y = home.y; ghosts[g].dir = { x: 0, y: -1 }; ghosts[g].visible = true; // Reset ghost movement to grid center to avoid phasing through walls ghosts[g].gridX = 9; ghosts[g].gridY = 11; } } } } } // --- Input: Swipe to set direction --- function getSwipeDir(start, end) { var dx = end.x - start.x; var dy = end.y - start.y; if (Math.abs(dx) > Math.abs(dy)) { if (dx > 32) return { x: 1, y: 0 }; if (dx < -32) return { x: -1, y: 0 }; } else { if (dy > 32) return { x: 0, y: 1 }; if (dy < -32) return { x: 0, y: -1 }; } return null; } game.down = function (x, y, obj) { swipeStart = { x: x, y: y }; dragNode = pacman; }; game.move = function (x, y, obj) { if (!swipeStart) return; var swipeEnd = { x: x, y: y }; var dir = getSwipeDir(swipeStart, swipeEnd); if (dir) { pacman.nextDir = dir; swipeStart = null; } }; game.up = function (x, y, obj) { swipeStart = null; dragNode = null; }; // --- Game Update Loop --- game.update = function () { if (!pacman) return; lastGameOver = false; updatePacmanDirection(); pacman.update(); for (var i = 0; i < ghosts.length; ++i) { updateGhostDirection(ghosts[i]); ghosts[i].update(); } checkPelletEat(); checkGhostCollisions(); updateFrightened(); }; // --- Game Start --- function startGame() { score = 0; LK.setScore(0); scoreTxt.setText('0'); currentMazeIndex = 0; MAZE = MAZES[currentMazeIndex]; buildMaze(); spawnPacman(); spawnGhosts(); frightTicks = 0; frightActive = false; lastGameOver = false; } startGame();
===================================================================
--- original.js
+++ change.js
@@ -121,17 +121,17 @@
/****
* Game Code
****/
-// Frightened ghost (white)
-// Ghosts (four colors)
-// Wall (blue box)
-// Power Pellet (bigger blue dot)
-// Pellet (small white dot)
-// Pacman (yellow circle)
-// --- Maze Layout ---
-// 0: empty, 1: wall, 2: pellet, 3: power pellet
// 19x23 grid (classic Pacman aspect, fits 2048x2732 well)
+// 0: empty, 1: wall, 2: pellet, 3: power pellet
+// --- Maze Layout ---
+// Pacman (yellow circle)
+// Pellet (small white dot)
+// Power Pellet (bigger blue dot)
+// Wall (blue box)
+// Ghosts (four colors)
+// Frightened ghost (white)
var MAZE_ROWS = 23;
var MAZE_COLS = 19;
var CELL_SIZE = 112; // 19*112=2128, 23*112=2576, fits in 2048x2732 with margin
var MAZE_OFFSET_X = (2048 - MAZE_COLS * CELL_SIZE) / 2;
@@ -169,16 +169,8 @@
// Widen the gap below ghost spawn (row 13, cols 8, 9, 10)
MAZES[1][13][8] = 0;
MAZES[1][13][9] = 0;
MAZES[1][13][10] = 0;
-// Maze 3 (even more content, new layout)
-MAZES[2] = [[1, 3, 2, 2, 2, 1, 2, 2, 2, 0, 2, 2, 2, 1, 2, 2, 2, 3, 1], [1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1], [1, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 1], [1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1], [0, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0], [0, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 0], [1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1], [0, 3, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 3, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 0], [0, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 2, 0], [0, 2, 1, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 1, 2, 2, 0], [1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 0, 1, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]];
-// Remove wall below ghost spawn (row 12, col 9) to allow escape
-MAZES[2][12][9] = 0;
-// Widen the gap below ghost spawn (row 13, cols 8, 9, 10)
-MAZES[2][13][8] = 0;
-MAZES[2][13][9] = 0;
-MAZES[2][13][10] = 0;
// Current maze index
var currentMazeIndex = 0;
var MAZE = MAZES[currentMazeIndex];
// --- Game State ---
@@ -200,19 +192,38 @@
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
+// --- Maze Selection Button ---
+// Place a button in the top-right corner, avoiding the top-left 100x100 area
+var mazeBtn = new Text2('🧩', {
+ size: 100,
+ fill: "#fff"
+});
+mazeBtn.anchor.set(1, 0); // right-top
+mazeBtn.x = 0; // Will be positioned by LK.gui
+mazeBtn.y = 0;
+mazeBtn.interactive = true;
+mazeBtn.buttonMode = true;
+mazeBtn._isMazeBtn = true; // Mark for event filtering
+// Add to GUI topRight (safe from menu)
+LK.gui.topRight.addChild(mazeBtn);
+// Button handler: cycle maze and restart game
+mazeBtn.down = function (x, y, obj) {
+ // Cycle to next maze
+ currentMazeIndex = (currentMazeIndex + 1) % MAZES.length;
+ MAZE = MAZES[currentMazeIndex];
+ startGame();
+};
// --- Maze Build ---
function buildMaze() {
// Clear previous
for (var i = 0; i < pellets.length; ++i) pellets[i].destroy();
for (var i = 0; i < walls.length; ++i) walls[i].destroy();
pellets = [];
walls = [];
pelletsLeft = 0;
- if (!MAZE || !Array.isArray(MAZE)) return;
for (var row = 0; row < MAZE_ROWS; ++row) {
- if (!MAZE[row] || !Array.isArray(MAZE[row])) continue;
for (var col = 0; col < MAZE_COLS; ++col) {
var cell = MAZE[row][col];
var x = MAZE_OFFSET_X + col * CELL_SIZE + CELL_SIZE / 2;
var y = MAZE_OFFSET_Y + row * CELL_SIZE + CELL_SIZE / 2;
@@ -242,12 +253,11 @@
// --- Pacman Init ---
function spawnPacman() {
if (pacman) pacman.destroy();
pacman = new Pacman();
- // Start position: center of maze, row 11, col 9 (just below ghost house, always on screen)
- // Move Pacman back to his original position
+ // Start position: center of maze, row 15, col 9
pacman.gridX = 9;
- pacman.gridY = 11;
+ pacman.gridY = 15;
pacman.x = MAZE_OFFSET_X + pacman.gridX * CELL_SIZE + CELL_SIZE / 2;
pacman.y = MAZE_OFFSET_Y + pacman.gridY * CELL_SIZE + CELL_SIZE / 2;
pacman.dir = {
x: 1,
@@ -258,11 +268,8 @@
y: 0
};
pacman.moving = true;
game.addChild(pacman);
- // Reset lastGameOver and ensure Pacman is visible and positioned
- lastGameOver = false;
- pacman.visible = true;
}
// --- Ghosts Init ---
function spawnGhosts() {
// Remove old ghosts
@@ -444,17 +451,8 @@
// --- Ghost Collisions ---
function checkGhostCollisions() {
for (var i = 0; i < ghosts.length; ++i) {
var ghost = ghosts[i];
- // If Pacman is not visible (not spawned), skip collision check
- if (!pacman || pacman.visible === false) continue;
- // If Pacman is not on screen, skip collision check
- if (typeof pacman.x !== "number" || typeof pacman.y !== "number") continue;
- // Extra: Only check collision if Pacman is at his original spawn position or has moved at least once
- // (prevents collision before Pacman is placed)
- if (typeof pacman.gridX !== "number" || typeof pacman.gridY !== "number") continue;
- // If Pacman is at (0,0), likely not spawned yet
- if (pacman.x === 0 && pacman.y === 0) continue;
var dx = pacman.x - ghost.x;
var dy = pacman.y - ghost.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 60) {
@@ -464,10 +462,10 @@
score += 200;
scoreTxt.setText(score);
LK.setScore(score);
} else if (!frightActive && ghost.visible !== false) {
- // Pacman dies, but only if Pacman is visible and spawned
- if (!lastGameOver && pacman && pacman.visible !== false) {
+ // Pacman dies
+ if (!lastGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
lastGameOver = true;
}
@@ -539,9 +537,9 @@
x: x,
y: y
};
var dir = getSwipeDir(swipeStart, swipeEnd);
- if (dir && pacman) {
+ if (dir) {
pacman.nextDir = dir;
swipeStart = null;
}
};
@@ -551,8 +549,9 @@
};
// --- Game Update Loop ---
game.update = function () {
if (!pacman) return;
+ lastGameOver = false;
updatePacmanDirection();
pacman.update();
for (var i = 0; i < ghosts.length; ++i) {
updateGhostDirection(ghosts[i]);
@@ -561,94 +560,19 @@
checkPelletEat();
checkGhostCollisions();
updateFrightened();
};
-// --- Maze Selection Screen ---
-var mazeSelectButtons = [];
-function showMazeSelect() {
- // Remove any previous buttons
- for (var i = 0; i < mazeSelectButtons.length; ++i) {
- mazeSelectButtons[i].destroy();
- }
- mazeSelectButtons = [];
- // Title
- var title = new Text2("Select Maze", {
- size: 140,
- fill: "#fff"
- });
- title.anchor.set(0.5, 0);
- title.x = 200; // Move title even further to the left
- title.y = 200; // Move title up
- LK.gui.top.addChild(title);
- mazeSelectButtons.push(title);
- // Create a button for each maze
- var btnW = 600;
- var btnH = 200;
- var spacing = 80;
- var totalH = MAZES.length * btnH + (MAZES.length - 1) * spacing;
- // Move buttons up as well, just below the title
- var startY = 350 + btnH / 2 + spacing; // 350px from top, below title, always visible
- for (var i = 0; i < MAZES.length; ++i) {
- (function (idx) {
- var btn = new Container();
- // Button background
- var bg = LK.getAsset('wall', {
- anchorX: 0.5,
- anchorY: 0.5,
- width: btnW,
- height: btnH
- });
- btn.addChild(bg);
- // Button label
- var label = new Text2("Maze " + (idx + 1), {
- size: 100,
- fill: "#fff"
- });
- label.anchor.set(0.5, 0.5);
- label.x = 0;
- label.y = 0;
- btn.addChild(label);
- // Position
- btn.x = 200; // Move even further to the left side, but not too close to the edge
- btn.y = startY + i * (btnH + spacing);
- // Touch handler
- btn.down = function (x, y, obj) {
- // Remove all buttons
- for (var j = 0; j < mazeSelectButtons.length; ++j) {
- mazeSelectButtons[j].destroy();
- }
- mazeSelectButtons = [];
- // Set maze and start game
- currentMazeIndex = idx;
- MAZE = MAZES[currentMazeIndex];
- startGame(true);
- };
- LK.gui.center.addChild(btn);
- mazeSelectButtons.push(btn);
- })(i);
- }
-}
// --- Game Start ---
-function startGame(fromSelect) {
+function startGame() {
score = 0;
LK.setScore(0);
scoreTxt.setText('0');
- if (!fromSelect) {
- // Only show maze select if not coming from selection
- // Spawn Pacman before maze is selected, but wait to spawn ghosts until after maze selection
- spawnPacman();
- showMazeSelect();
- // Start the game immediately after showing maze select (for initial spawn)
- startGame(true);
- return;
- }
+ currentMazeIndex = 0;
+ MAZE = MAZES[currentMazeIndex];
buildMaze();
- // Ensure Pacman and ghosts are spawned after maze is built
- if (!pacman) {
- spawnPacman();
- }
+ spawnPacman();
spawnGhosts();
frightTicks = 0;
frightActive = false;
lastGameOver = false;
}
-showMazeSelect();
\ No newline at end of file
+startGame();
\ No newline at end of file
Pacman red ghost. In-Game asset. 2d. High contrast. No shadows
Pacman pink ghost. In-Game asset. 2d. High contrast. No shadows
Pacman blue ghost. In-Game asset. 2d. High contrast. No shadows
Pacman orange ghost. In-Game asset. 2d. High contrast. No shadows
Pacman dark blue ghost with plain white eyes. In-Game asset. 2d. High contrast. No shadows
Pacman with mouth closed pixilated . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Pacman. In-Game asset. 2d. High contrast. shadows. Outline. Pixilated
Pacman with mouth opened pixilated . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Pacman cherry. In-Game asset. 2d. High contrast. No shadows
Pixilated ice cream. In-Game asset. 2d. High contrast. No shadows
Pixilated pizza. In-Game asset. 2d. High contrast. No shadows