From 05dc31532f4231f19cd8e283025e90ad9fc2295a Mon Sep 17 00:00:00 2001 From: yug-khandelwal Date: Mon, 30 Dec 2024 19:56:57 -0500 Subject: [PATCH 1/3] Add files via upload --- games/flappy-bird-with-gravity-and-sound.js | 194 ++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 games/flappy-bird-with-gravity-and-sound.js diff --git a/games/flappy-bird-with-gravity-and-sound.js b/games/flappy-bird-with-gravity-and-sound.js new file mode 100644 index 0000000000..d6585d17a3 --- /dev/null +++ b/games/flappy-bird-with-gravity-and-sound.js @@ -0,0 +1,194 @@ +/* +First time? Check out the tutorial game: +https://sprig.hackclub.com/gallery/getting_started + +@title: Flappy-bird-with-gravity-and-sound +@author: Yug Khandelwal +@addedOn: 2024-12-24 +*/ + +const player = "p"; +const obstacle = "o"; +const background = "b"; +const gameOverMelody = tune` +37.5: E4-37.5 + F4-37.5, +37.5: G4-37.5 + A4-37.5, +37.5: B4-37.5 + C5-37.5, +37.5: D5-37.5, +37.5: D5-37.5, +37.5: D5-37.5 + C5-37.5 + B4-37.5 + A4-37.5, +37.5: G4-37.5, +37.5: G4-37.5 + A4-37.5, +37.5: B4-37.5 + C5-37.5 + D5-37.5, +37.5: E5-37.5 + F5-37.5, +37.5: F5-37.5, +37.5: F5-37.5 + E5-37.5, +37.5: E5-37.5 + D5-37.5 + C5-37.5, +37.5: C5-37.5 + B4-37.5 + A4-37.5, +37.5: G4-37.5 + F4-37.5, +37.5: F4-37.5 + E4-37.5, +37.5: E4-37.5, +37.5: E4-37.5 + F4-37.5, +37.5: F4-37.5 + G4-37.5, +37.5: G4-37.5 + A4-37.5 + B4-37.5 + C5-37.5, +37.5: C5-37.5, +37.5: B4-37.5 + A4-37.5 + G4-37.5 + F4-37.5 + E4-37.5, +37.5: E4-37.5, +37.5: F4-37.5, +37.5: F4-37.5, +37.5: F4-37.5 + G4-37.5 + A4-37.5, +37.5: A4-37.5 + B4-37.5 + C5-37.5, +37.5: C5-37.5 + D5-37.5, +37.5: D5-37.5 + E5-37.5 + F5-37.5 + G5-37.5, +37.5: G5-37.5 + A5-37.5, +37.5: G5-37.5 + F5-37.5 + E5-37.5 + D5-37.5, +37.5: C5-37.5 + B4-37.5`; +const keyTune = tune` +500: G4-500, +15500`; +setLegend( + [player, bitmap` +................ +................ +................ +.....00000...... +...00666600..... +000206666060.... +0222206660250... +0666606660250... +.0660666600000.. +..0006660999990. +....0666099990.. +.....006600000.. +.......000...... +................ +................ +................`], + [obstacle, bitmap` +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL`], + [background, bitmap` +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777`] +); +let level = 0; +const levels = [ + map` +.......o.. +.......o.. +.......o.. +.......o.. +p......... +.......o.. +.......o.. +.......o..` +] + +setMap(levels[level]); +setBackground(background); +setPushables({ + [player]: [] +}); +var isGameOver = false; +var speed = 250; +var gap = 4; +var count = 0; +var score = 0; +onInput("s", () => { + if (!isGameOver) { + playTune(keyTune); + getFirst(player).y += 1; + } +}); + +onInput("w", () => { + if (!isGameOver) { + playTune(keyTune); + getFirst(player).y -= 1; + } +}); + +function generateObstacle() { + gap = Math.floor(Math.random() * 8); + for (let y = 0; y < 8; y++) { + if (y != gap) { + addSprite(7, y, obstacle); + } + } + score++; +} + +function gameLoop() { + addText(`Score: ${score}`, { x: 10, y: 1, color: color`2` }) + if (count % 4 == 0) { + getAll(player).forEach((p) => { + if (p.y == 8) {} else { + p.y += 1; + }; + }); + } + getAll(obstacle).forEach((o) => { + if (o.x == 0) { + o.remove(); + } else { + o.x -= 1; + }; + }); + if (getAll(obstacle).length == 0) { + generateObstacle(); + } + if (getFirst(obstacle).x == getFirst(player).x && getFirst(player).y != gap) { + gameOver(); + } + count += 1; + speed -= (250 - speed); + if (!isGameOver) { + setTimeout(gameLoop, speed); + } +} + +function gameOver() { + clearText(); + isGameOver = true; + setMap(map` +.......... +.......... +.......... +.......... +.......... +.......... +.......... +..........`); + playTune(gameOverMelody); + addText("Game over!", { x: 5, y: 7, color: color`2` }); + addText(`Score: ${score}`, { x: 5, y: 8, color: color`2` }); +} +gameLoop(); \ No newline at end of file From cf2a1d773c3a30589a1fdc6f0364f66253871857 Mon Sep 17 00:00:00 2001 From: yug-khandelwal Date: Mon, 30 Dec 2024 20:06:55 -0500 Subject: [PATCH 2/3] Update flappy-bird-with-gravity-and-sound.js --- games/flappy-bird-with-gravity-and-sound.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/games/flappy-bird-with-gravity-and-sound.js b/games/flappy-bird-with-gravity-and-sound.js index d6585d17a3..f1820385d3 100644 --- a/games/flappy-bird-with-gravity-and-sound.js +++ b/games/flappy-bird-with-gravity-and-sound.js @@ -4,7 +4,7 @@ https://sprig.hackclub.com/gallery/getting_started @title: Flappy-bird-with-gravity-and-sound @author: Yug Khandelwal -@addedOn: 2024-12-24 +@addedOn: 2024-12-30 */ const player = "p"; @@ -191,4 +191,4 @@ function gameOver() { addText("Game over!", { x: 5, y: 7, color: color`2` }); addText(`Score: ${score}`, { x: 5, y: 8, color: color`2` }); } -gameLoop(); \ No newline at end of file +gameLoop(); From 5a78eedb5c7c8c1df1693d3d5e0914a5427c9684 Mon Sep 17 00:00:00 2001 From: graham Date: Fri, 3 Jan 2025 15:53:18 -0500 Subject: [PATCH 3/3] Fixing metadata --- games/flappy-bird-with-gravity-and-sound.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/games/flappy-bird-with-gravity-and-sound.js b/games/flappy-bird-with-gravity-and-sound.js index f1820385d3..2e7aaf025c 100644 --- a/games/flappy-bird-with-gravity-and-sound.js +++ b/games/flappy-bird-with-gravity-and-sound.js @@ -2,7 +2,8 @@ First time? Check out the tutorial game: https://sprig.hackclub.com/gallery/getting_started -@title: Flappy-bird-with-gravity-and-sound +@title: Flappy Bird with Gravity and Sound +@tags: [] @author: Yug Khandelwal @addedOn: 2024-12-30 */