forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshark dodger.js
243 lines (229 loc) · 4.59 KB
/
shark dodger.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
/*
@title: shark_dodger
@author: angelgames
@tags: ['action']
@addedOn: 2024-05-23
@img: ""
*/
const player = "p"
const harpoon = "h"
const capturer = "c"
const fish = "f"
const background = "b"
let health = 3
let healthtext = health
var loop = 1
setLegend(
[harpoon, bitmap`
.......00.......
.......00.......
.......CC.......
.......CC.......
.......CC.......
.......CC.......
.......CC.......
.......CC.......
.......CC.......
.......CC.......
.....LLLLLL.....
...LL..LL..LL...
...L...LL...L...
...L...LL...L...
...L...LL...L...
...L...LL...L...`],
[player, bitmap`
................
................
....1111........
...1111111.....1
..1111111111..11
.1101L1L1L111.1.
11011L1L1L11111.
11111L1L1L1L111.
22111L1L1L1L111.
111L1L1L1L1L111.
111L1L1L1L11111.
.11L1L111111..11
..11111111.....1
....1111........
................
................`],
[fish, bitmap`
................
................
....66666.......
..666466666.....
.66644466666....
6066666466666...
60664444644466.6
666646666664666.
.4466666644446.6
...664444666....
....646666......
................
................
................
................
................`],
[background, bitmap`
5555555555555555
5555777775555555
5757755555577775
5777555755575555
5555577755577555
7557755577557555
7577555755557555
7775557755575555
7555777777755555
5755555557777755
5755557744555777
5577777754755555
5575555744777555
5777777457757755
7577557477777777
5555555455557555`],
[capturer, bitmap`
.......2........
.......222......
.......222......
.......C2.......
.......C2.......
.......C........
..CFF..C...FCCC.
FFFCCCCCCFCCCFFC
CCCCCCCCCFCFCFFC
CCCFCCCCCCCCFFCC
.CCFFCFFFCCFFCC.
..CCCCCCCCCCCC..
................
................
................
................`]
)
setBackground(background)
const level = map`
cccccccccccccccccccc
....................
....................
....................
....................
....................
.........p..........
....................
....................
....................
....................
....................
....................
....................
....................
....................`
setMap(level)
setSolids([player])
onInput("a", () => {
getFirst(player).x -= 1
})
onInput("s", () => {
getFirst(player).y += 1
})
onInput("w", () => {
getFirst(player).y -= 1
})
onInput("d", () => {
getFirst(player).x += 1
})
function moveobjects() {
let harpoons = getAll(harpoon)
for (let harpoonpos = 0; harpoonpos < harpoons.length; harpoonpos++) {
if (harpoons[harpoonpos].y == 15) {
harpoons[harpoonpos].remove()
}
harpoons[harpoonpos].y += 1
}
let fishs = getAll(fish)
for (let fishpos = 0; fishpos < fishs.length; fishpos++) {
if (fishs[fishpos].y == 15) {
fishs[fishpos].remove()
}
fishs[fishpos].y += 1
}
}
function spawnobjects() {
let harpoongoal = 4
for (let harpooncount = 1; harpooncount <= harpoongoal; harpooncount++) {
let x = Math.floor(Math.random() * 20)
let y = 0
addSprite(x, y, harpoon)
}
let fishgoal = 1
for (let fishcount = 1; fishcount <= fishgoal; fishcount++) {
let x = Math.floor(Math.random() * 20)
let y = 0
addSprite(x, y, fish)
}
}
function checkDeath() {
let harpoons = getAll(harpoon)
let capturers = getAll(capturer)
let p = getFirst(player)
for (let harpoonpos = 0; harpoonpos < harpoons.length; harpoonpos++) {
if (harpoons[harpoonpos].x == p.x && harpoons[harpoonpos].y == p.y) {
return true
}
for (let capturerpos = 1; capturerpos < capturers.length; capturerpos++)
for(let capturers = 15; capturerpos < capturers.length; capturerpos++) {
if (capturers[capturerpos].x == p.x && capturers[capturerpos].y == p.y) {
return true
}
}
}
}
function checkHealth() {
let fishs = getAll(fish)
let p = getFirst(player)
for (let fishpos = 0; fishpos < fishs.length; fishpos++) {
if (fishs[fishpos].x == p.x && fishs[fishpos].y == p.y) {
return true
}
}
return false
}
var gameLoop = setInterval(() => {
let healthstring = healthtext.toString()
addText(healthstring + " LIVES", {
x: 0,
y: 0,
color: color`6`
})
checkDeath()
if (checkDeath()) {
if (health == 1) {
clearInterval(gameLoop)
gameRunning = false
addText("0 LIVES", {
x: 0,
y: 0,
color: color`6`
})
addText("You were hunted!", {
x: 3,
y: 7,
color: color`3`
})
} else {
health--
healthtext--
}
}
spawnobjects()
moveobjects()
checkHealth()
if (checkHealth()) {
health++
healthtext++
if (health >= 9) {
let health = 9
let healthtext = 9
}
}
}, 150)