From 7d88d35e0e0f88dad6a36deedea7a26fc13da04f Mon Sep 17 00:00:00 2001 From: evah-s39 Date: Sun, 24 Aug 2025 00:21:50 +0400 Subject: [PATCH 1/4] Add files via upload --- games/Reverse Pac-Man.js | 382 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 games/Reverse Pac-Man.js diff --git a/games/Reverse Pac-Man.js b/games/Reverse Pac-Man.js new file mode 100644 index 0000000000..5b243f0973 --- /dev/null +++ b/games/Reverse Pac-Man.js @@ -0,0 +1,382 @@ +/* +@title: Reverse Pac-Man +@author: Evah Shaji +@addedOn: 2025-08-23 +First time? Check out the tutorial game: +https://sprig.hackclub.com/gallery/getting_started + +Reverse Pac-Man - You are the ghost! Chase and catch all the Pac-Men! +Controls: WASD to move +Goal: Catch all yellow Pac-Men within the time limit +*/ + +const player = "p" +const wall = "w" +const pacman = "m" +const dot = "d" +const empty = "e" + +setLegend( + [ player, bitmap` +................ +.....000000..... +...0033333300... +..003333333300.. +.00333000333300. +.03333000333330. +.03330000033330. +.03333333333330. +.03330000033330. +.03330000033330. +.00333333333300. +..003333333300.. +...0033333300... +.....000000..... +................ +................` ], + [ wall, bitmap` +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000` ], + [ pacman, bitmap` +................ +................ +................ +...666666666.... +..66666666666... +.6666666666666.. +.6666666666666.. +666600666666666. +666666666666666. +666666666666666. +.6666666666666.. +.6666666666666.. +..66666666666... +...666666666.... +................ +................` ], + [ dot, bitmap` +................ +................ +................ +................ +................ +................ +......6666...... +......6666...... +......6666...... +......6666...... +................ +................ +................ +................ +................ +................` ], + [ empty, bitmap` +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................` ] +) + +setSolids([player, wall]) + +let level = 0 +let score = 0 +let timeLeft = 60 +let gameRunning = true +let pacmenPositions = [] +let pacmenMoveTimer = 0 + +const levels = [ + map` +wwwwwwwwwwwwwwww +w.d.d.d.d.d.d.dw +wd.w.w.w.w.w.w.w +w.d.d.d.d.d.d.dw +w.w.w.w.w.w.w.dw +w.d.d.d.d.d.d.dw +wd.w.w.w.w.w.w.w +w.d.d.d.d.d.d.dw +w.w.w.w.w.w.w.dw +w.d.d.d.d.d.d.dw +wd.w.w.w.w.w.w.w +w.d.d.d.d.d.d.dw +w.w.w.w.w.w.w.dw +wm.d.d.p.d.d.m.w +wwwwwwwwwwwwwwww`, + + map` +wwwwwwwwwwwwwwww +wm.............w +w.ww.wwwwww.ww.w +w..............w +w.ww.w.ww.w.ww.w +w....w.dd.w....w +wwww.wwddww.wwww +w..w.d.dd.d.w..w +www..ddpdd..wwww +w..w.d.dd.d.w..w +wwww.wwddww.wwww +w....w.dd.w....w +w.ww.w.ww.w.ww.w +w..............w +w.ww.wwwwww.ww.w +wm.............w +wwwwwwwwwwwwwwww`, + + map` +wwwwwwwwwwwwwwww +w.d.d.d.d.d.d.dw +wd.w.w.w.w.w.w.w +w.d.d.d.d.d.d.dw +w.w.w.w.w.w.w.dw +wm....d.d....m.w +w.w.w.w.w.w.w.dw +w.d.d.d.p.d.d.dw +wd.w.w.w.w.w.w.w +wm....d.d....mw +w.w.w.w.w.w.w.dw +w.d.d.d.d.d.d.dw +wd.w.w.w.w.w.w.w +w.d.d.d.d.d.d.dw +wwwwwwwwwwwwwwww` +] + +setMap(levels[level]) + +// Initialize Pac-Men positions +function initPacMen() { + pacmenPositions = [] + const pacmans = getAll(pacman) + for (let p of pacmans) { + pacmenPositions.push({ + x: p.x, + y: p.y, + dx: Math.random() < 0.5 ? -1 : 1, + dy: 0 + }) + } +} + +initPacMen() + +// Timer function +function updateTimer() { + if (!gameRunning) return + + if (timeLeft > 0) { + timeLeft-- + clearText() + addText(`Score: ${score}`, { x: 1, y: 1, color: color`6` }) + addText(`Time: ${timeLeft}s`, { x: 1, y: 2, color: color`3` }) + addText(`Pac-Men: ${getAll(pacman).length}`, { x: 1, y: 3, color: color`6` }) + + setTimeout(updateTimer, 1000) + } else { + gameOver() + } +} + +// Start timer +updateTimer() + +// Move Pac-Men AI +function movePacMen() { + if (!gameRunning) return + + const pacmans = getAll(pacman) + + for (let i = 0; i < pacmans.length; i++) { + const p = pacmans[i] + const pos = pacmenPositions[i] + if (!pos) continue + + // Try to move in current direction + let newX = p.x + pos.dx + let newY = p.y + pos.dy + + // Check if move is valid (not into wall) + const tileAtNewPos = getTile(newX, newY) + const hasWall = tileAtNewPos.some(sprite => sprite.type === wall) + + if (hasWall || newX < 0 || newX >= width() || newY < 0 || newY >= height()) { + // Hit wall, change direction randomly + const directions = [ + { dx: 1, dy: 0 }, // right + { dx: -1, dy: 0 }, // left + { dx: 0, dy: 1 }, // down + { dx: 0, dy: -1 } // up + ] + + // Try different directions until we find a valid one + let validDirectionFound = false + for (let attempts = 0; attempts < 4; attempts++) { + const dir = directions[Math.floor(Math.random() * 4)] + newX = p.x + dir.dx + newY = p.y + dir.dy + + const testTile = getTile(newX, newY) + const testHasWall = testTile.some(sprite => sprite.type === wall) + + if (!testHasWall && newX >= 0 && newX < width() && newY >= 0 && newY < height()) { + pos.dx = dir.dx + pos.dy = dir.dy + validDirectionFound = true + break + } + } + + if (!validDirectionFound) { + continue // Skip this pac-man this turn + } + } + + // Move the pac-man + p.x = newX + p.y = newY + } + + setTimeout(movePacMen, 300) // Move every 300ms +} + +// Start Pac-Men movement +movePacMen() + +// Player movement +onInput("s", () => { + if (!gameRunning) return + getFirst(player).y += 1 + checkCollision() +}) + +onInput("w", () => { + if (!gameRunning) return + getFirst(player).y -= 1 + checkCollision() +}) + +onInput("a", () => { + if (!gameRunning) return + getFirst(player).x -= 1 + checkCollision() +}) + +onInput("d", () => { + if (!gameRunning) return + getFirst(player).x += 1 + checkCollision() +}) + +// Check collision with Pac-Men +function checkCollision() { + const playerSprite = getFirst(player) + const pacmans = getAll(pacman) + + for (let p of pacmans) { + if (playerSprite.x === p.x && playerSprite.y === p.y) { + p.remove() + score += 100 + + // Remove from tracking array + for (let i = 0; i < pacmenPositions.length; i++) { + if (pacmenPositions[i] && + pacmans.indexOf(p) === i) { + pacmenPositions.splice(i, 1) + break + } + } + + // Check if all caught + if (getAll(pacman).length === 0) { + nextLevel() + } + break + } + } + + // Update display + clearText() + addText(`Score: ${score}`, { x: 1, y: 1, color: color`6` }) + addText(`Time: ${timeLeft}s`, { x: 1, y: 2, color: color`3` }) + addText(`Pac-Men: ${getAll(pacman).length}`, { x: 1, y: 3, color: color`6` }) +} + +// Next level +function nextLevel() { + level++ + if (level < levels.length) { + setMap(levels[level]) + initPacMen() + timeLeft += 30 // Bonus time for completing level + clearText() + addText(`Level ${level + 1}!`, { x: 6, y: 7, color: color`4` }) + addText(`+30 seconds!`, { x: 5, y: 8, color: color`4` }) + + setTimeout(() => { + clearText() + }, 2000) + } else { + // Victory! + gameRunning = false + clearText() + addText(`YOU WIN!`, { x: 6, y: 6, color: color`4` }) + addText(`Final Score: ${score}`, { x: 3, y: 8, color: color`6` }) + addText(`Press J to restart`, { x: 2, y: 10, color: color`2` }) + } +} + +// Game over +function gameOver() { + gameRunning = false + clearText() + addText(`GAME OVER!`, { x: 5, y: 6, color: color`3` }) + addText(`Score: ${score}`, { x: 6, y: 8, color: color`6` }) + addText(`Press J to restart`, { x: 2, y: 10, color: color`2` }) +} + +// Restart game +onInput("j", () => { + level = 0 + score = 0 + timeLeft = 60 + gameRunning = true + setMap(levels[level]) + initPacMen() + movePacMen() + updateTimer() + clearText() +}) + +// Initial display +clearText() +addText(`Score: ${score}`, { x: 1, y: 1, color: color`6` }) +addText(`Time: ${timeLeft}s`, { x: 1, y: 2, color: color`3` }) +addText(`Pac-Men: ${getAll(pacman).length}`, { x: 1, y: 3, color: color`6` }) +addText(`Catch all Pac-Men!`, { x: 2, y: 14, color: color`4` }) +addText(`WASD to move`, { x: 4, y: 15, color: color`2` }) \ No newline at end of file From 201d92a863015c17d4b28db671035f7ae6f40d01 Mon Sep 17 00:00:00 2001 From: evah-s39 Date: Wed, 24 Sep 2025 21:52:20 +0400 Subject: [PATCH 2/4] Update Reverse Pac-Man.js updates missing fields in metadata --- games/Reverse Pac-Man.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/games/Reverse Pac-Man.js b/games/Reverse Pac-Man.js index 5b243f0973..48526da8b8 100644 --- a/games/Reverse Pac-Man.js +++ b/games/Reverse Pac-Man.js @@ -1,13 +1,8 @@ /* @title: Reverse Pac-Man @author: Evah Shaji -@addedOn: 2025-08-23 -First time? Check out the tutorial game: -https://sprig.hackclub.com/gallery/getting_started - -Reverse Pac-Man - You are the ghost! Chase and catch all the Pac-Men! -Controls: WASD to move -Goal: Catch all yellow Pac-Men within the time limit +@tags: [game, arcade, retro, pacman, chase] +@addedOn: 2025-08-03 */ const player = "p" @@ -379,4 +374,4 @@ addText(`Score: ${score}`, { x: 1, y: 1, color: color`6` }) addText(`Time: ${timeLeft}s`, { x: 1, y: 2, color: color`3` }) addText(`Pac-Men: ${getAll(pacman).length}`, { x: 1, y: 3, color: color`6` }) addText(`Catch all Pac-Men!`, { x: 2, y: 14, color: color`4` }) -addText(`WASD to move`, { x: 4, y: 15, color: color`2` }) \ No newline at end of file +addText(`WASD to move`, { x: 4, y: 15, color: color`2` }) From be2c40674056b34b8259600a40fe70ca9c168c6c Mon Sep 17 00:00:00 2001 From: evah-s39 Date: Wed, 24 Sep 2025 21:53:30 +0400 Subject: [PATCH 3/4] Update Reverse Pac-Man.js added @description --- games/Reverse Pac-Man.js | 1 + 1 file changed, 1 insertion(+) diff --git a/games/Reverse Pac-Man.js b/games/Reverse Pac-Man.js index 48526da8b8..484390acc2 100644 --- a/games/Reverse Pac-Man.js +++ b/games/Reverse Pac-Man.js @@ -2,6 +2,7 @@ @title: Reverse Pac-Man @author: Evah Shaji @tags: [game, arcade, retro, pacman, chase] +@description: A flipped twist on the classic arcade game—play as the ghost and hunt down Pac-Man while he scrambles for survival. @addedOn: 2025-08-03 */ From c8cafca2236f13b7101bca4de0cc337428998f2c Mon Sep 17 00:00:00 2001 From: evah-s39 Date: Fri, 26 Sep 2025 06:39:48 +0400 Subject: [PATCH 4/4] Rename Reverse Pac-Man.js to Reverse_Pac-Man.js Rename file to remove space in filename --- games/{Reverse Pac-Man.js => Reverse_Pac-Man.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename games/{Reverse Pac-Man.js => Reverse_Pac-Man.js} (100%) diff --git a/games/Reverse Pac-Man.js b/games/Reverse_Pac-Man.js similarity index 100% rename from games/Reverse Pac-Man.js rename to games/Reverse_Pac-Man.js