Skip to content

Commit c96c031

Browse files
Merge pull request #1 from yug-khandelwal/yug-khandelwal-patch-1
Added animated bird to flappy bird with gravity and sound
2 parents ed5c4cf + 766f468 commit c96c031

File tree

1 file changed

+60
-35
lines changed

1 file changed

+60
-35
lines changed

games/flappy-bird-with-gravity-and-sound.js games/flappy-bird-with-animated-bird-gravity-and-sound.js

+60-35
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
First time? Check out the tutorial game:
33
https://sprig.hackclub.com/gallery/getting_started
44
5-
@title: Flappy Bird with Gravity and Sound
5+
@title: Flappy Bird with Animated Bird, Gravity and Sound
66
@tags: []
77
@author: Yug Khandelwal
8-
@addedOn: 2024-12-30
8+
@addedOn: 2025-1-19
99
*/
1010

11-
const player = "p";
11+
const flapUp = "u";
12+
const flapDown = "d"
1213
const obstacle = "o";
1314
const background = "b";
1415
const gameOverMelody = tune`
@@ -47,41 +48,61 @@ const gameOverMelody = tune`
4748
const keyTune = tune`
4849
500: G4-500,
4950
15500`;
51+
52+
const bird = () => getFirst("u") || getFirst("d");
53+
5054
setLegend(
51-
[player, bitmap`
52-
................
55+
[flapUp, bitmap`
5356
................
5457
................
55-
.....00000......
56-
...00666600.....
57-
000206666060....
58-
0222206660250...
59-
0666606660250...
60-
.0660666600000..
61-
..0006660999990.
58+
00..............
59+
220..00000......
60+
62200666600.....
61+
062206666060....
62+
0662206660250...
63+
.066606660250...
64+
..060666600000..
65+
...006660999990.
6266
....0666099990..
6367
.....006600000..
6468
.......000......
6569
................
6670
................
71+
................`],
72+
[flapDown, bitmap`
73+
................
74+
................
75+
................
76+
....00000.......
77+
..00666600......
78+
.0206666060.....
79+
022206660250....
80+
026606660250....
81+
2260666600000...
82+
26606660999990..
83+
6000666099990...
84+
60..006600000...
85+
0.....000.......
86+
................
87+
................
6788
................`],
6889
[obstacle, bitmap`
6990
LLLLLLLLLLLLLLLL
91+
L333L333333L333L
92+
L333L333333L333L
93+
L333L333333L333L
7094
LLLLLLLLLLLLLLLL
95+
L3333333L333333L
96+
L3333333L333333L
97+
L3333333L333333L
7198
LLLLLLLLLLLLLLLL
99+
L333L333333L333L
100+
L333L333333L333L
101+
L333L333333L333L
72102
LLLLLLLLLLLLLLLL
73-
LLLLLLLLLLLLLLLL
74-
LLLLLLLLLLLLLLLL
75-
LLLLLLLLLLLLLLLL
76-
LLLLLLLLLLLLLLLL
77-
LLLLLLLLLLLLLLLL
78-
LLLLLLLLLLLLLLLL
79-
LLLLLLLLLLLLLLLL
80-
LLLLLLLLLLLLLLLL
81-
LLLLLLLLLLLLLLLL
82-
LLLLLLLLLLLLLLLL
83-
LLLLLLLLLLLLLLLL
84-
LLLLLLLLLLLLLLLL`],
103+
L3333333L333333L
104+
L3333333L333333L
105+
L3333333L333333L`],
85106
[background, bitmap`
86107
7777777777777777
87108
7777777777777777
@@ -107,7 +128,7 @@ const levels = [
107128
.......o..
108129
.......o..
109130
.......o..
110-
p.........
131+
u.........
111132
.......o..
112133
.......o..
113134
.......o..`
@@ -116,24 +137,26 @@ p.........
116137
setMap(levels[level]);
117138
setBackground(background);
118139
setPushables({
119-
[player]: []
140+
[flapUp]: [],
141+
[flapDown]: [],
120142
});
121143
var isGameOver = false;
122144
var speed = 250;
123145
var gap = 4;
124146
var count = 0;
125147
var score = 0;
126148
onInput("s", () => {
149+
const bird = () => getFirst("u") || getFirst("d");
127150
if (!isGameOver) {
128151
playTune(keyTune);
129-
getFirst(player).y += 1;
152+
bird().y += 1;
130153
}
131154
});
132-
133155
onInput("w", () => {
156+
const bird = () => getFirst("u") || getFirst("d");
134157
if (!isGameOver) {
135158
playTune(keyTune);
136-
getFirst(player).y -= 1;
159+
bird().y -= 1;
137160
}
138161
});
139162

@@ -149,12 +172,11 @@ function generateObstacle() {
149172

150173
function gameLoop() {
151174
addText(`Score: ${score}`, { x: 10, y: 1, color: color`2` })
175+
152176
if (count % 4 == 0) {
153-
getAll(player).forEach((p) => {
154-
if (p.y == 8) {} else {
155-
p.y += 1;
156-
};
157-
});
177+
if (bird().y == 8) {} else {
178+
bird().y += 1;
179+
};
158180
}
159181
getAll(obstacle).forEach((o) => {
160182
if (o.x == 0) {
@@ -166,10 +188,13 @@ function gameLoop() {
166188
if (getAll(obstacle).length == 0) {
167189
generateObstacle();
168190
}
169-
if (getFirst(obstacle).x == getFirst(player).x && getFirst(player).y != gap) {
191+
bird().type = [flapUp, flapDown][count % 2];
192+
if (getFirst(obstacle).x == bird().x && bird().y != gap) {
170193
gameOver();
171194
}
172195
count += 1;
196+
197+
173198
speed -= (250 - speed);
174199
if (!isGameOver) {
175200
setTimeout(gameLoop, speed);

0 commit comments

Comments
 (0)