From e1df9daa81d596420016c9bb0488766429804ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kel=C3=A9nyi=20Oliv=C3=A9r=20Gergely?= Date: Tue, 26 May 2026 20:35:06 +0200 Subject: [PATCH 1/3] Add files via upload --- games/Escape from the falling rocks!.js | 271 ++++++++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100644 games/Escape from the falling rocks!.js diff --git a/games/Escape from the falling rocks!.js b/games/Escape from the falling rocks!.js new file mode 100644 index 0000000000..3b547658dd --- /dev/null +++ b/games/Escape from the falling rocks!.js @@ -0,0 +1,271 @@ +/* +First time? Check out the tutorial game: +https://sprig.hackclub.com/gallery/getting_started + +@title: Escape from the falling rocks! +@description: Survive falling rocks! +@author: Olivér Kelényi +@tags: ['survival'] +@addedOn: 2026-05-26 +*/ + + +const player = "p"; +const rock = "r"; +const bg = "g"; + +setLegend( + [ player, bitmap` +................ +................ +......0000...... +....00000000.... +...0000000000... +...0000000000... +...0000000000... +....00000000.... +......0000...... +................ +................ +................ +................ +................ +................ +................`], + + [ rock, bitmap` +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111 +1111111111111111`], + + [ bg, bitmap` +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777`] +); + +setBackground(bg); + +function loadGame() { + setMap(map` +................ +................ +................ +................ +................ +................ +................ +................ +................ +p...............`); +} + +loadGame(); + +setSolids([player, rock]); + +let gameOver = false; + +function movePlayer(dx, dy) { + + const p = getFirst(player); + + const ox = p.x; + const oy = p.y; + + p.x += dx; + p.y += dy; + + if (tilesWith(player, rock).length > 0) { + + // vissza + p.x = ox; + p.y = oy; + + p.y -= 1; + p.x += dx; + + if (tilesWith(player, rock).length > 0) { + p.x = ox; + p.y = oy; + } + } + + p.x = Math.max(0, Math.min(width()-1, p.x)); + p.y = Math.max(0, Math.min(height()-1, p.y)); +} + +onInput("w", () => { + if (!gameOver) movePlayer(0, -1); +}); + +onInput("s", () => { + if (!gameOver) movePlayer(0, 1); +}); + +onInput("a", () => { + if (!gameOver) movePlayer(-1, 0); +}); + +onInput("d", () => { + if (!gameOver) movePlayer(1, 0); +}); + + +onInput("j", () => { + + gameOver = false; + + clearText(); + + loadGame(); +}); + +function spawnRock() { + + const x = Math.floor(Math.random() * width()); + + if (getTile(x, 0).length === 0) { + addSprite(x, 0, rock); + } +} + +function updateRocks() { + + const rocks = [...getAll(rock)]; + + for (const r of rocks.reverse()) { + + if (r.y >= height()-1) { + continue; + } + + const below = getTile(r.x, r.y + 1); + + const playerBelow = below.some(t => t.type === player); + const rockBelow = below.some(t => t.type === rock); + + + if (playerBelow) { + + const p = getFirst(player); + + + const leftFree = + p.x > 0 && + getTile(p.x - 1, p.y).every(t => t.type !== rock); + + const rightFree = + p.x < width()-1 && + getTile(p.x + 1, p.y).every(t => t.type !== rock); + + if (leftFree) { + + p.x -= 1; + r.y += 1; + + } else if (rightFree) { + + p.x += 1; + r.y += 1; + + } else { + + gameOver = true; + } + + } + + else if (!rockBelow) { + + r.y += 1; + } + } +} + +function crushCheck() { + + const p = getFirst(player); + + const up = + p.y > 0 && + getTile(p.x, p.y - 1).some(t => t.type === rock); + + const down = + p.y < height()-1 && + getTile(p.x, p.y + 1).some(t => t.type === rock); + + const left = + p.x > 0 && + getTile(p.x - 1, p.y).some(t => t.type === rock); + + const right = + p.x < width()-1 && + getTile(p.x + 1, p.y).some(t => t.type === rock); + + if (up && down && left && right) { + gameOver = true; + } +} + +function drawGameOver() { + + addText("GAME OVER", { + x: 3, + y: 5, + color: color`3` + }); + + addText("J = RESTART", { + x: 2, + y: 7, + color: color`2` + }); +} + +setInterval(() => { + + if (gameOver) { + + clearText(); + drawGameOver(); + return; + } + + clearText(); + + if (Math.random() < 0.45) { + spawnRock(); + } + + updateRocks(); + + crushCheck(); + +}, 220); \ No newline at end of file From 6713a8a9c428ee9109bb4c05e39bdd69f3100b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kel=C3=A9nyi=20Oliv=C3=A9r=20Gergely?= Date: Sun, 7 Jun 2026 19:20:22 +0200 Subject: [PATCH 2/3] Rename file to Escapefromthefalling rocks!.js --- ...rom the falling rocks!.js => Escapefromthefalling rocks!.js} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename games/{Escape from the falling rocks!.js => Escapefromthefalling rocks!.js} (99%) diff --git a/games/Escape from the falling rocks!.js b/games/Escapefromthefalling rocks!.js similarity index 99% rename from games/Escape from the falling rocks!.js rename to games/Escapefromthefalling rocks!.js index 3b547658dd..e1e19a8f79 100644 --- a/games/Escape from the falling rocks!.js +++ b/games/Escapefromthefalling rocks!.js @@ -268,4 +268,4 @@ setInterval(() => { crushCheck(); -}, 220); \ No newline at end of file +}, 220); From a8f9dfb65b843f8771ba3c6877c50d42109fb3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kel=C3=A9nyi=20Oliv=C3=A9r=20Gergely?= Date: Sun, 7 Jun 2026 19:20:59 +0200 Subject: [PATCH 3/3] Rename Escapefromthefalling rocks!.js to Escapefromthefallingrocks!.js --- ...capefromthefalling rocks!.js => Escapefromthefallingrocks!.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename games/{Escapefromthefalling rocks!.js => Escapefromthefallingrocks!.js} (100%) diff --git a/games/Escapefromthefalling rocks!.js b/games/Escapefromthefallingrocks!.js similarity index 100% rename from games/Escapefromthefalling rocks!.js rename to games/Escapefromthefallingrocks!.js