From c2b44e5afcf46bc72d2a5bcd11e2a746c717482a Mon Sep 17 00:00:00 2001 From: Ezra Lederman Date: Tue, 10 Dec 2024 16:29:14 -0500 Subject: [PATCH 1/2] Sprig App - SkyFall --- games/SkyFall.js | 135 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 games/SkyFall.js diff --git a/games/SkyFall.js b/games/SkyFall.js new file mode 100644 index 0000000000..c14e62fe29 --- /dev/null +++ b/games/SkyFall.js @@ -0,0 +1,135 @@ +/* +First time? Check out the tutorial game: +https://sprig.hackclub.com/gallery/getting_started + +@title: SkyFall +@author: +@tags: [] +@addedOn: 2024-00-00 +*/ + +const player = "p"; +const meteor = "m"; +let moveMeteorInterval; + +setLegend( + [ player, bitmap` +................ +................ +................ +................ +................ +................ +................ +...5......5..... +...50000005..... +....0H00H0...... +....0H00H0...... +....000000...... +.....0..0....... +.....0..0....... +..0000..00000... +................` + ], + [ meteor, bitmap` +..6.6.6...6..6.. +..666.6..6.6.6.. +..93966.66996... +..63996666939... +..69399999396... +..69333333996... +...9333333966... +...69LLLLL666... +...6LLLLLLL6.... +....LLLLLLL..... +....LLLLLLL..... +....LLLLLLL..... +....LLLLLLL..... +.....LLLLL...... +................` + ] +); + +setSolids([]); + +const levels = [ + map` +..m.. +..... +..... +..p..` +]; + +let level = 0; +setMap(levels[level]); + +setPushables({ + [player]: [] +}); + +function endGame() { + clearInterval(moveMeteorInterval); + clearText(); + addText("Game Over!", { x: 5, y: 10, color: color`0` }); +} + +function detectCollisions() { + const playerSprite = getFirst(player); + const meteorSprites = getAll(meteor); + + meteorSprites.forEach(meteorSprite => { + if (playerSprite.x === meteorSprite.x && playerSprite.y === meteorSprite.y) { + endGame(); + } + }); +} + +function respawnMeteor() { + for (let i = 0; i < 3; i++) { + const randomX = Math.floor(Math.random() * width()); + const meteorSprite = addSprite(randomX, 0, meteor); + } +} + +function moveMeteors() { + const meteorSprites = getAll(meteor); + + meteorSprites.forEach(meteorSprite => { + meteorSprite.y += 1; + + if (meteorSprite.y >= height() - 1) { + if (Math.random() > 0.75) { + respawnMeteor(); + } + detectCollisions(); + meteorSprite.remove(); + } + + detectCollisions(); + }); + + if (meteorSprites.length < 4) { + respawnMeteor(); + } +} + +onInput("j", () => { + level = 0; + setMap(levels[level]); + clearText() + moveMeteorInterval = setInterval(moveMeteors, 1000); +}); + +onInput("d", () => { + getFirst(player).x += 1; +}); + +onInput("a", () => { + getFirst(player).x -= 1; +}); + +onInput("l", () => { + endGame(); +}); + +moveMeteorInterval = setInterval(moveMeteors, 1000); \ No newline at end of file From b42bdddde20d55a4523a3089dbd18bad1a0de394 Mon Sep 17 00:00:00 2001 From: Gus Ruben <95830851+gusruben@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:24:19 -0500 Subject: [PATCH 2/2] Fix metadata --- games/SkyFall.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/games/SkyFall.js b/games/SkyFall.js index c14e62fe29..6b514e4a6b 100644 --- a/games/SkyFall.js +++ b/games/SkyFall.js @@ -1,11 +1,8 @@ /* -First time? Check out the tutorial game: -https://sprig.hackclub.com/gallery/getting_started - @title: SkyFall -@author: +@author: Meowkewok @tags: [] -@addedOn: 2024-00-00 +@addedOn: 2024-12-10 */ const player = "p"; @@ -132,4 +129,4 @@ onInput("l", () => { endGame(); }); -moveMeteorInterval = setInterval(moveMeteors, 1000); \ No newline at end of file +moveMeteorInterval = setInterval(moveMeteors, 1000);