forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThe_Bird_Feedo.js
168 lines (147 loc) · 2.77 KB
/
The_Bird_Feedo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
@title: The Bird Feedo
@author: Arpan Pandey
@tags: ['endless']
@addedOn: 2023-01-09
*/
const bird = "b";
const cookie = "c";
let gameRunning = true;
let myTime = 0;
setLegend(
[bird, bitmap`
................
................
................
................
.......00000....
.....00022200...
.0..002220220...
..0022222222999.
.0.0222222229999
...02222222000..
...000000000....
.....0..0.......
....0..0........
................
................
................`],
[cookie, bitmap`
................
................
................
....CCCC.CCC....
...CC3C..CCCC...
..CCCCCCCCCCCC..
..CCCCCCCCC3CC..
..CC3CCC3CCCCC..
..CCCCCCCCC3CC..
..CCCCCCCCCCCC..
..CCCC3CC3CCCC..
..CCCCCCCCCCCC..
...CC3CCCCCCC...
....CCCCCCCC....
................
................`]
);
setSolids([]);
let level = 0;
const levels = [
map`
......
b.....
...c..
c....c
......`,
];
setMap(levels[level]);
setPushables({
[bird]: [],
});
onInput("s", () => {
if (gameRunning) {
getFirst(bird).y += 1
}
});
onInput("w", () => {
if (gameRunning) {
getFirst(bird).y -= 1
}
});
onInput("a", () => {
if (gameRunning) {
getFirst(bird).x -= 1
}
});
onInput("d", () => {
if (gameRunning) {
getFirst(bird).x += 1
}
});
afterInput(() => {
});
function moveBird() {
if (getFirst(bird).x != 5) {
getFirst(bird).x += 1
} else {
getFirst(bird).remove()
addSprite(0, 1, bird);
}
}
function checkHit() {
let cookies = getAll(cookie);
let birdS = getFirst(bird);
for (let i = 0; i < cookies.length; i++) {
if (cookies[i].x == birdS.x && cookies[i].y == birdS.y) {
return true;
}
}
return false;
}
function randomcookieiser() {
let birdS = getFirst(bird);
let cookies = getAll(cookie);
for (let i = 0; i < cookies.length; i++) {
let x = Math.floor(Math.random() * 5);
let y = Math.floor(Math.random() * 5);
if (birdS.x != x && birdS.y != y) {
cookies[i].x = x;
cookies[i].y = y;
}
}
}
function showEnd() {
getFirst(bird).remove();
let cookies = getAll(cookie);
for (let i = 0; i < cookies.length; i++) {
cookies[i].remove();
}
addText("The Bird Feedo", {
x: 3,
y: 2,
color: color`5`
});
addText(`Your time: ${myTime}s`, {
x: 3,
y: 5,
color: color`7`
});
addText("Game Over!", {
x: 3,
y: 6,
color: color`3`
});
addSprite(2, 3, bird);
addSprite(3, 3, cookie);
}
var gameLoop = setInterval(() => {
if (checkHit()) {
clearInterval(gameLoop);
gameRunning = false;
showEnd();
} else {
myTime += 1;
moveBird();
randomcookieiser();
}
}, 1000);