forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshitpest.js
324 lines (299 loc) · 5.7 KB
/
shitpest.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
@title: shitpest
@author: Mason Meirs
@tags: ['strategy']
@addedOn: 2022-12-24
snwy.me
*/
const player = "p"
const enemy = "e"
const lane = "w"
const laneL = "z"
const laneR = "x"
const bg = "b"
const blBg = "h"
const bullet = "l"
let score = 0
let gameOver = false
let useSuper = true
setLegend(
[bullet, bitmap`
................
................
.....222222.....
....23333332....
....23333332....
....23333332....
....23333332....
....23333332....
....23333332....
....23333332....
....23333332....
....23333332....
....23333332....
....23333332....
.....222222.....
................`],
[player, bitmap`
5000000220000005
5002000220000005
5000002L12000005
5020002L12020005
500002L551200025
520002L551200005
50002L5557120205
50002L5557120005
5002L55577712005
5002L55577712005
502L555577771205
502L555777771205
52L5555777777125
52L5557777777125
2L55557777777712
2222222222222222`],
[enemy, bitmap`
0000000000000000
0000222222220000
0002333333322000
0023333333332200
0233233333233220
0233323332333220
0233333333333220
0233323332333220
0233333333333220
0233322222333220
0233233333233220
0223333333332220
0022333333322200
0002222222222000
0000222222220000
0000000000000000`],
[lane, bitmap`
5000000000000005
5000200000002005
5000000000000005
5000000000000005
5000000000000005
5000000000200005
5000200000000005
5000000000000005
5000000002000005
5000000000000005
5002000000002005
5000000000000005
5000000000000005
5000000000000005
5000000020000005
5000200000000005`],
[laneL, bitmap`
5000000000000000
5000200000002000
5000000000000000
5000000000000002
5000000000000000
5000000000200000
5000000200000000
5000000000000000
5000000000000002
5000000000000000
5002000000002000
5000000020000000
5000000000000002
5000000000000000
5000000000000000
5000200000000000`],
[laneR, bitmap`
0000000000000005
2000000000002005
0000000020000005
0000000000000005
0000020000000005
0000000000200005
0000000000000005
0000000000000005
0200000002000005
0000000000000005
0000000000002005
0000000000000005
0000020000000005
2000000000020005
0000000020000005
0000200000000005`],
[bg, bitmap`
0000000000000000
0200000200000200
0000000000000000
0000000000000002
0020000002000000
0000000000000000
0000000000002000
0000000000000000
0200000000000002
0000000000000000
0000002000000000
0000000000002000
0000000000000000
0000000000000000
0200000000000000
0000000000020000`],
[blBg, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
)
setMap(
map`
hhhhhhbbbb
bbbbbbbbbb
zbbbbbbbbx
wzbbbbbbxw
wwzbbbbxww
wwwzbbxwww
wwwwzxwwww
wwwwwwwwww`
)
onInput("a", () => {
if(!gameOver) {
getFirst(player).x -= 1
handleMovement()
}
})
onInput("d", () => {
if(!gameOver) {
getFirst(player).x += 1
handleMovement()
}
})
onInput("i", () => {
if(!gameOver)
fireProjectile(getFirst(player))
})
onInput("j", () => {
if(useSuper && !gameOver) {
getAll(enemy).forEach(e => e.remove())
useSuper = false
}
})
function fireProjectile(player) {
addSprite(player.x, player.y, bullet)
}
function handleMovement() {
switch (getFirst(player).x) {
case 1: getFirst(player).y = 4; break
case 2: getFirst(player).y = 5; break
case 3: getFirst(player).y = 6; break
case 4:
case 5: getFirst(player).y = 7; break
case 6: getFirst(player).y = 6; break
case 7: getFirst(player).y = 5; break
case 8: getFirst(player).y = 4; break
}
}
addSprite(4, 7, player)
function spawnEnemies() {
let chance = Math.floor(Math.random() * 10) % 10
switch(chance) {
case 9:
case 8:
if(chance % 2 == 0)
addSprite(1, 0, enemy)
else
addSprite(7, 0, enemy)
break
case 7:
case 6:
if(chance % 2 == 0)
addSprite(2, 0, enemy)
else
addSprite(6, 0, enemy)
break
case 5:
case 4:
if(chance % 2 == 0)
addSprite(3, 0, enemy)
else
addSprite(5, 0, enemy)
break
case 3:
case 2:
case 1:
case 0:
if(chance % 2 == 0)
addSprite(4, 0, enemy)
else
addSprite(4, 0, enemy)
break
default:
// console.log(chance)
}
}
function moveEnemies() {
getAll(enemy).forEach(e => {
e.y += 1
})
}
function cleanup() {
getAll(enemy).forEach(e => {
if(e.y == 7) {
e.remove()
doGameOver()
}
})
}
function moveProjectiles() {
getAll(bullet).forEach(b => {
getTile(b.x, b.y - 1).forEach(t => {
if(t.type == enemy) {
t.remove()
b.remove()
score++
}
})
b.y--
if(b.y <= 0)
b.remove()
})
}
function doGameOver() {
clearInterval(spawnInterval)
clearInterval(moveInterval)
clearInterval(cleanup)
clearInterval(scoreInterval)
clearInterval(bulletInterval)
gameOver = true
getAll(enemy).forEach(e => e.remove())
getAll(bullet).forEach(b => b.remove())
getFirst(player).remove()
drawText()
addText("GAME OVER", { x: 6, y: 5, color: color`2`})
addText("GAME OVER", { x: 6, y: 4, color: color`3`})
addText("GAME OVER", { x: 6, y: 3, color: color`2`})
}
function drawText() {
clearText()
addText("SCORE: " + score, { x: 0, y: 0, color: color`6`})
if(useSuper && !gameOver)
addText("SUPER ACTIVE", { x: 0, y: 1, color: color`4`})
}
function setSuper() {
useSuper = true
}
let spawnInterval = setInterval(spawnEnemies, 1000)
let moveInterval = setInterval(moveEnemies, 1000)
let cleanupInterval = setInterval(cleanup, 1000)
let scoreInterval = setInterval(drawText, 50)
let bulletInterval = setInterval(moveProjectiles, 50)
let superInterval = setInterval(setSuper, 20000)