From 225cef049ecde18687bfddf91d1808fad7aa6208 Mon Sep 17 00:00:00 2001 From: Alexandru Moga <98146541+alexandru-moga@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:20:30 +0200 Subject: [PATCH 1/2] Sprig App - Flappy Bird --- games/Flappy-Bird.js | 144 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 games/Flappy-Bird.js diff --git a/games/Flappy-Bird.js b/games/Flappy-Bird.js new file mode 100644 index 0000000000..b7870cbc39 --- /dev/null +++ b/games/Flappy-Bird.js @@ -0,0 +1,144 @@ +const player = "p"; +const wall = "w"; +const background = "b"; + +setLegend( + [ player, bitmap` +................ +................ +................ +.....0000000.... +....006666020... +..006666602220.. +.02206666022020. +022220666022020. +022222066602220. +0622260666600000 +.066606666099990 +..00006660900000 +....066666099990 +.....00666600000 +......00000..... +................`], + [ wall, bitmap` +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444 +4DDD444444444444`], + [ background, bitmap` +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777 +7777777777777777` ] +); + +setMap( map` +.......w +.......w +.......w +.p...... +.......w +.......w +.......w +.......w` ); +setBackground(background); + +var opening = 3; +var speed = 250; +var score = 0; +var isGameOver = false; + +setPushables({ + [ player ]: [], +}); + +onInput("s", () => { + if (!isGameOver) { + getFirst(player).y += 1 + } +}); + +onInput("w", () => { + if (!isGameOver) { + getFirst(player).y -= 1 + } +}); + +function genWall() { + opening = Math.floor(Math.random() * 8); + for (let y=0; y < 8; y++) { + if (y != opening) { + addSprite(7, y, wall); + } + } + + score++; +} + +function gameLoop() { + addText(`Score: ${score}`, {x: 9, y: 14,color: color`2`}) + + getAll(wall).forEach((w) => { + if (w.x == 0) { + w.remove(); + } else { + w.x -= 1; + }; + }); + + if (getAll(wall).length == 0) { + genWall(); + } + + if (getFirst(wall).x == getFirst(player).x && getFirst(player).y != opening) { + lost(); + } + + speed -= (250-speed); + if (!isGameOver) { + setTimeout(gameLoop, speed); + } +} + +function lost() { + isGameOver = true; + // console.log("You lost"); + setMap(map` +........ +........ +........ +........ +........ +........ +........ +........`); + clearText(); + addText("Game over!", {x: 5, y: 7, color: color`3`}) + addText(`Score: ${score}`, {x: 5, y: 8, color: color`3`}) +} + +gameLoop(); \ No newline at end of file From 9be9f41e95c5f094849928db61486363113a6cd1 Mon Sep 17 00:00:00 2001 From: Mare Cosmin <147330889+Cosmin-Mare@users.noreply.github.com> Date: Thu, 9 Jan 2025 01:15:08 +0200 Subject: [PATCH 2/2] Update Flappy-Bird.js --- games/Flappy-Bird.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/games/Flappy-Bird.js b/games/Flappy-Bird.js index b7870cbc39..555e45952f 100644 --- a/games/Flappy-Bird.js +++ b/games/Flappy-Bird.js @@ -1,3 +1,9 @@ +/* +@title: alexandru moga +@author: flappy-bird +@tags: [] +@addedOn: 2025-01-09 +*/ const player = "p"; const wall = "w"; const background = "b"; @@ -141,4 +147,4 @@ function lost() { addText(`Score: ${score}`, {x: 5, y: 8, color: color`3`}) } -gameLoop(); \ No newline at end of file +gameLoop();