From 3f0f514a4d48fd1d1e7046bcde038a60e43ac811 Mon Sep 17 00:00:00 2001 From: Froggy1018 Date: Wed, 15 Oct 2025 19:56:48 +0900 Subject: [PATCH 1/4] Sprig App - Maze Game --- games/Maze-Game.js | 282 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 games/Maze-Game.js diff --git a/games/Maze-Game.js b/games/Maze-Game.js new file mode 100644 index 0000000000..c9c8340209 --- /dev/null +++ b/games/Maze-Game.js @@ -0,0 +1,282 @@ + const player="p" + const fly = "y" + const worm="e" + const wall= "w" + const wall2= "v" + const key = "k" + const door = "d" + const key2="f" + + +setLegend( + [ player, bitmap` +................ +................ +..DD...DD....... +.D44D.D44D...... +.4024D4024D..... +.400444004D..... +..4444444D...... +..433334D....... +..444444DD...... +...DDDDDD4D..... +...D44D4444D.... +...D44D4444D.... +...D44D44DD..... +................ +................ +................` ], + + [ fly, bitmap` +................ +................ +................ +................ +................ +....LLL..LLL.... +...LL1L..L1LL... +...L11000011L... +...LLL0000LLL... +......3003...... +......0000...... +................ +................ +................ +................ +................` ], + + [ worm, bitmap` +................ +................ +................ +................ +............CC.. +............CC.. +.....CCCC...CC.. +....CCCCCC..CC.. +....CC..CC..CC.. +...CCC..CCCCCC.. +..CCC....CCCC... +................ +................ +................ +................ +................` ], + + [ wall, bitmap` +DD.DD...4.D...4. +D.4.D..4..DD.44. +D.44D.44...D.4.. +D..4D.4....D.4.. +DD..D.44..DD.44. +.D.DD..4..DD..44 +.D.D.4..4..D...4 +.D.D44...4.D..44 +D4.D4....4.D.44. +D44.DD...4.D.4.. +DD4..D..4.DD.4.. +.DD..D..4.DD..4. +..D..D..4..D..44 +.D...D.4...DD..4 +.D..DD.4....D.44 +.D.DD..4....D.4.` ], + + [ wall2, bitmap` +4DD..44D.C.DDD.. +.DD.D44..4DDD... +4DD4344D..DDD.4C +.DD.D44.3..DDD44 +4DD...44D...DDD. +.DD4..D44...DDDD +.DD4...44....DDD +4DD....44D....DD +.DD4.3.44...3.DD +.DD..D444....DDD +4DD...44....DDD. +.DD4...44...DD.. +4DD....44D..4DD. +.DD....44..44DD. +.DD4...D44..44DD +4DD.....44D...DD` ], + + [ key, bitmap` +................ +.....66666F..... +....6666666F.... +....66FFF66F.... +....66FFF66F.... +....6666666F.... +.....66666F..... +......666F...... +......6666F..... +......66FFF..... +......6666F..... +......66FF...... +......6666F..... +......6666F..... +......66FF...... +......66F.......` ], + + [ door, bitmap` +......6666...... +.....66CC66..... +....66CCCC66.... +....6CCCCCC6.... +...66CCCCCC66... +...6CCCCCCCC6... +...6CCCCCCCC6... +...6CC6CC6CC6... +...6CC6CC6CC6... +...6CC6CC6CC6... +...6CCCCCCCC6... +...6CCCCCCCC6... +...6CCCCCCCC6... +...6CCCCCCCC6... +.LL6666666666LL. +.LLLLLLLLLLLLLL.` ], + + [ key2, bitmap` +................ +.....66666C..... +....6666666C.... +....66CCC66C.... +....66CCC66C.... +....6666666C.... +.....66666C..... +......666C...... +......6666C..... +......66CCC..... +......6666C..... +......66CC...... +......6666C..... +......6666C..... +......66CC...... +......66C.......` ] +) + +setSolids([player, wall, wall2, key]) + +let level = 0 +const levels = [ + map` +wwwwwwwww +w.......w +w.wwwww.w +w.w..ew.w +w.w.www.w +w.w.....w +wpwwwwwww` +] +levels.push(level) + +level = level + 1 +const newLevel1 = map` +wwwwewwww +wwww.wwww +wwww.wwww +e...p...y +wwww.wwww +wwww.wwww +wwwwywwww` + +levels.push(newLevel1) + +level = level + 1 +const newLevel2 = map` +wpwwwwwwwww +w.w...wywew +w.w.www.www +w...w.....w +w.www.ww.ww +w.wy...w.ww +w.wwww.w.ww +w...w..w.ww +www.w.ww.ww +wy....w...e +wwwwwwwwwww` + +levels.push(newLevel2) + +level = level + 1 +const newLevel3 = map` +wpwwwwwwwwwwwwwwwww +w.v..............fw +w.w.wvw.w.wvwvwvwvw +w...v...v.........w +w.wvw.wvwvwvwvw.w.w +w.vf..v.......vfv.w +w.wvwvw.wvwvw.wvw.w +w...v.......v.v...w +wvw.w.wvwvw.w.w.w.w +wf..v.v...v.v.v.v.w +wvw.w.w.w.w.w.w.w.w +w...v...v.vfv...vfw +w.wvwvwvw.wvwvwvwvw +w.......v.v.......w +wvwvw.w.w.w.wvwvw.w +w..kv.v.v...v...v.w +w.wvw.w.wvwvw.w.w.w +w.....v.......v.vde +wwwwwwwwwwwwwwwwwww` + +levels.push(newLevel3) +setMap(levels[level]) + + +setPushables({ + [ player ]: [] +}) + +onInput("w", () => { + getFirst(player).y -= 1 +}) + +onInput("s", () => { + getFirst(player).y += 1 +}) + +onInput("a", () => { + getFirst(player).x -= 1 +}) + +onInput("d", () => { + getFirst(player).x += 1 +}) + +onInput("j", () => { + level = 0; // Reset the level to the first level + setMap(levels[level]); // Set the map to the first level +}); + +let hasKey = false; + +afterInput(() => { + const goalsCovered = tilesWith(player, worm, door, key); + const playerSprite = getFirst(player); + + goalsCovered.forEach((goal) => { + if (goal.type === key) { + hasKey = true; + goal.remove(); } + else if (goal.type === door && hasKey) + {goal.remove();} + else if (goal.type === worm) + {level = level + 1; + if (level < levels.length) { + setMap(levels[level]); + } + else { + addText("you win!", { y: 4, color: color`0` }); + } + } + }); +}); + +function resetGame() { + level = 0; + setMap(levels[level]); + hasKey = false; +} + +document.querySelector("#run").addEventListener("click", resetGame); + From dc70f54e80a0abeba2a34ec512d0edf7ebd534df Mon Sep 17 00:00:00 2001 From: Froggy1018 Date: Wed, 22 Oct 2025 11:13:25 +0900 Subject: [PATCH 2/4] Added metadata to the top of the file --- games/{Maze-Game.js => Frog-Maze-Game.js} | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) rename games/{Maze-Game.js => Frog-Maze-Game.js} (97%) diff --git a/games/Maze-Game.js b/games/Frog-Maze-Game.js similarity index 97% rename from games/Maze-Game.js rename to games/Frog-Maze-Game.js index c9c8340209..3d309050e2 100644 --- a/games/Maze-Game.js +++ b/games/Frog-Maze-Game.js @@ -1,4 +1,14 @@ - const player="p" +/* +@title: Frog Maze game +@author: Froggy1018 +@description: Solve the maze +@tags: [Maze] +@addedOn: 2025-10-22 +*/ + + + + const player="p" const fly = "y" const worm="e" const wall= "w" From 6f87596908a8c020a6061737824196b924b06990 Mon Sep 17 00:00:00 2001 From: Froggy1018 Date: Sat, 25 Oct 2025 01:34:50 +0000 Subject: [PATCH 3/4] Deleted document.querySelector() --- games/Frog-Maze-Game.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/games/Frog-Maze-Game.js b/games/Frog-Maze-Game.js index 3d309050e2..e3fede38ca 100644 --- a/games/Frog-Maze-Game.js +++ b/games/Frog-Maze-Game.js @@ -287,6 +287,3 @@ function resetGame() { setMap(levels[level]); hasKey = false; } - -document.querySelector("#run").addEventListener("click", resetGame); - From 999019469add5711944c4f374bcdcb9b2e4495ed Mon Sep 17 00:00:00 2001 From: Froggy1018 Date: Tue, 28 Oct 2025 12:38:21 +0000 Subject: [PATCH 4/4] Made edits so that the level starts from 0 and the frog is able to get the worm and move to the next level --- games/Frog-Maze-Game.js | 73 +++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/games/Frog-Maze-Game.js b/games/Frog-Maze-Game.js index e3fede38ca..25810a1018 100644 --- a/games/Frog-Maze-Game.js +++ b/games/Frog-Maze-Game.js @@ -8,7 +8,7 @@ - const player="p" + const player="p" const fly = "y" const worm="e" const wall= "w" @@ -164,7 +164,7 @@ DD4..D..4.DD.4.. ......66C.......` ] ) -setSolids([player, wall, wall2, key]) +setSolids([player, wall, wall2, door]) let level = 0 const levels = [ @@ -175,24 +175,18 @@ w.wwwww.w w.w..ew.w w.w.www.w w.w.....w -wpwwwwwww` -] -levels.push(level) +wpwwwwwww`, -level = level + 1 -const newLevel1 = map` + map` wwwwewwww wwww.wwww wwww.wwww e...p...y wwww.wwww wwww.wwww -wwwwywwww` - -levels.push(newLevel1) +wwwwywwww`, -level = level + 1 -const newLevel2 = map` + map` wpwwwwwwwww w.w...wywew w.w.www.www @@ -203,12 +197,9 @@ w.wwww.w.ww w...w..w.ww www.w.ww.ww wy....w...e -wwwwwwwwwww` - -levels.push(newLevel2) +wwwwwwwwwww`, -level = level + 1 -const newLevel3 = map` + map` wpwwwwwwwwwwwwwwwww w.v..............fw w.w.wvw.w.wvwvwvwvw @@ -228,11 +219,10 @@ w..kv.v.v...v...v.w w.wvw.w.wvwvw.w.w.w w.....v.......v.vde wwwwwwwwwwwwwwwwwww` +] -levels.push(newLevel3) setMap(levels[level]) - setPushables({ [ player ]: [] }) @@ -261,29 +251,28 @@ onInput("j", () => { let hasKey = false; afterInput(() => { - const goalsCovered = tilesWith(player, worm, door, key); const playerSprite = getFirst(player); - - goalsCovered.forEach((goal) => { - if (goal.type === key) { - hasKey = true; - goal.remove(); } - else if (goal.type === door && hasKey) - {goal.remove();} - else if (goal.type === worm) - {level = level + 1; - if (level < levels.length) { - setMap(levels[level]); - } - else { - addText("you win!", { y: 4, color: color`0` }); - } + + const wormTiles = tilesWith(player, worm); + if (wormTiles.length > 0) { + level++; + if (level < levels.length) { + setMap(levels[level]); + hasKey = false; // Reset key state for new level + } else { + addText("you win!", { y: 4, color: color`0` }); } - }); -}); + return; // Exit early since we changed level + } + + const keyTiles = tilesWith(player, key); + if (keyTiles.length > 0) { + hasKey = true; + clearTile(17,17) + } + + const doorTiles = tilesWith(player, door); + if (doorTiles.length > 0 && hasKey) { -function resetGame() { - level = 0; - setMap(levels[level]); - hasKey = false; -} + } +}); \ No newline at end of file