From 4575c548d92e4d4cfe31daea482821ebe4bfadc0 Mon Sep 17 00:00:00 2001 From: Scaratek <153395462+Scaratech@users.noreply.github.com> Date: Tue, 5 Nov 2024 20:21:05 -0500 Subject: [PATCH 1/2] Sprig App - Bomb --- games/Bomb.js | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 games/Bomb.js diff --git a/games/Bomb.js b/games/Bomb.js new file mode 100644 index 0000000000..f6fc802da9 --- /dev/null +++ b/games/Bomb.js @@ -0,0 +1,151 @@ +/* +@title: Bomb +@author: Scaratek +@addedOn: 2024-00-00 +*/ + +const player = "p"; +const bomb = "b"; + +setLegend( + [ player, bitmap` +................ +................ +................ +....H......H.... +....H......H.... +................ +..H..........H.. +..H..........H.. +...HHHHHHHHHH... +................ +................ +................ +................ +................ +................ +................` ], + [ bomb, bitmap` +................ +................ +................ +...LLLLLLLLLL... +...L11111111L... +...L11111111L... +...L13111131L... +...L11111111L... +...L13111131L... +...L11333311L... +...L11111111L... +...L11111111L... +...LLLLLLLLLL... +................ +................ +................` ] +) + +setSolids([ player, bomb ]) + +let level = 0 +const levels = [ + map` +p. +..` +] + +setMap(levels[level]) + +setPushables({ + [ player ]: [] +}) + +let playerX = 3; +let playerY = 3; +let bombX = 3; +let bombY = 6; +let score = 0; + +const removeAllSprites = () => { + getAll().forEach(sprite => { + sprite.remove(); + }); +}; + +const removeAllTexts = () => { + getAll().forEach(sprite => { + if (sprite.type === "text") sprite.remove(); + }); +}; + +const end = (win) => { + clearText(); + if (win) { + addText(`You win! Your score: ${score}`, { x: 5, y: 7, color: color`3` }); + } else { + addText(`Game Over! Your score: ${score}`, { x: 5, y: 7, color: color`2` }); + } +}; + +const redraw = () => { + removeAllSprites(); + removeAllTexts(); + + addSprite(playerX, playerY, player); + addSprite(bombX, bombY, bomb); + + addText(`Score: ${score}`, { x: 1, y: 1, color: color`1` }); +}; +onInput("s", () => { + playerY += 1; + movePlayerAndCheck(); + redraw(); +}); + +onInput("w", () => { + playerY -= 1; + movePlayerAndCheck(); + redraw(); +}); + +onInput("a", () => { + playerX -= 1; + movePlayerAndCheck(); + redraw(); +}); + +onInput("d", () => { + playerX += 1; + movePlayerAndCheck(); + redraw(); +}); + +const movePlayerAndCheck = () => { + if (playerX === bombX && playerY === bombY) { + end(false); + return; + } + + let newBombX = bombX; + let newBombY = bombY; + + const randomTile = Math.floor(Math.random() * 4); + + switch (randomTile) { + case 0: newBombY = Math.min(bombY + 1, height() - 1); break; + case 1: newBombY = Math.max(bombY - 1, 0); break; + case 2: newBombX = Math.min(bombX + 1, width() - 1); break; + case 3: newBombX = Math.max(bombX - 1, 0); break; + } + + console.log("New Bomb Position X, Y:", newBombX, newBombY); + console.log("Grid Width, Height:", width(), height()); + + if (newBombX >= 0 && newBombX < width() && newBombY >= 0 && newBombY < height()) { + bombX = newBombX; + bombY = newBombY; + } else { + console.log("Bomb moving out of bounds!"); + } + + score++; +}; From 49cac73b66197db21237043f4750d7d6ba190bd5 Mon Sep 17 00:00:00 2001 From: Gus Ruben <95830851+gusruben@users.noreply.github.com> Date: Wed, 6 Nov 2024 21:16:10 -0500 Subject: [PATCH 2/2] Add tags to metadata --- games/Bomb.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/games/Bomb.js b/games/Bomb.js index f6fc802da9..892336ca50 100644 --- a/games/Bomb.js +++ b/games/Bomb.js @@ -1,7 +1,8 @@ /* @title: Bomb @author: Scaratek -@addedOn: 2024-00-00 +@tags: [] +@addedOn: 2024-11-6 */ const player = "p";