Skip to content

Commit 017849a

Browse files
authored
Add files via upload
1 parent b5a453d commit 017849a

File tree

1 file changed

+352
-0
lines changed

1 file changed

+352
-0
lines changed

games/Crossy Road.js

+352
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
/*
2+
First time? Check out the tutorial game:
3+
https://sprig.hackclub.com/gallery/getting_started
4+
5+
@title: Crossy Road
6+
@author:
7+
@tags: []
8+
@addedOn: 2024-00-00
9+
*/
10+
11+
const player = "p"
12+
const car = "c"
13+
const Ocar = "o"
14+
const Yellow = "y"
15+
const White = "W"
16+
const Black = "B"
17+
const Wall = "w"
18+
const Blue = "b"
19+
const Cloud = "C"
20+
const Bluecar = "a"
21+
var GameStarted = false
22+
var Score = 0
23+
var HighScore = 0
24+
var gameLoop;
25+
var playback;
26+
const Theme = tune`
27+
187.5: B5^187.5,
28+
187.5: C4~187.5,
29+
187.5: A5~187.5,
30+
187.5: D5~187.5,
31+
187.5: G5^187.5,
32+
187.5: G5/187.5 + B4/187.5,
33+
187.5: G5/187.5 + F5/187.5,
34+
187.5: F5/187.5 + G5/187.5 + B4/187.5,
35+
187.5: E5-187.5,
36+
187.5: B4~187.5,
37+
187.5: B4~187.5 + D5~187.5 + E5~187.5 + A5~187.5,
38+
187.5: A4-187.5,
39+
187.5: A4-187.5,
40+
187.5: A4-187.5,
41+
187.5: G5/187.5 + D5^187.5,
42+
187.5: A5/187.5 + C5^187.5,
43+
187.5: B5/187.5 + B4^187.5,
44+
187.5: A5/187.5 + C5^187.5,
45+
187.5: G5/187.5 + D5^187.5 + F4~187.5,
46+
187.5: F4~187.5,
47+
187.5: E4-187.5 + D4-187.5 + C4-187.5 + F4~187.5,
48+
187.5: G4~187.5,
49+
187.5: G5-187.5,
50+
187.5: G5-187.5,
51+
187.5: F5-187.5,
52+
187.5: E5^187.5,
53+
187.5: F5-187.5,
54+
187.5: G5-187.5,
55+
187.5: G5-187.5,
56+
187.5: G5-187.5 + A5-187.5,
57+
187.5: F5^187.5,
58+
187.5: G5~187.5 + C4/187.5`
59+
60+
setLegend(
61+
[player, bitmap`
62+
................
63+
................
64+
................
65+
................
66+
................
67+
................
68+
......222.......
69+
.....202022.....
70+
....22222333....
71+
...222222222....
72+
..22222222222...
73+
..22222222222...
74+
.....6....6.....
75+
.....6....6.....
76+
.....6....6.....
77+
.....6....6.....`],
78+
[car, bitmap`
79+
0000000000000000
80+
0000000000000000
81+
0000000000000000
82+
0000000000000000
83+
0000000000000000
84+
0000000000000000
85+
0000000000000000
86+
0000000330000000
87+
0000033333300000
88+
0000337777330000
89+
0000337777330000
90+
0003333333333000
91+
0033333333333300
92+
0033333333333300
93+
0000LL0000LL0000
94+
0000LL0000LL0000`],
95+
[Ocar, bitmap`
96+
0000000000000000
97+
0000000000000000
98+
0000000000000000
99+
0000000000000000
100+
0000000000000000
101+
0000000000000000
102+
0000000000000000
103+
0000000440000000
104+
0000044444400000
105+
0000447777440000
106+
0000447777440000
107+
0004444444444000
108+
0044444444444400
109+
0044444444444400
110+
0000LL0000LL0000
111+
0000LL0000LL0000`],
112+
[Black, bitmap`
113+
0000000000000000
114+
0000000000000000
115+
0000000000000000
116+
0000000000000000
117+
0000000000000000
118+
0000000000000000
119+
0000000000000000
120+
0000000000000000
121+
0000000000000000
122+
0000000000000000
123+
0000000000000000
124+
0000000000000000
125+
0000000000000000
126+
0000000000000000
127+
0000000000000000
128+
0000000000000000`],
129+
[Yellow, bitmap`
130+
6666666666666666
131+
6666666666666666
132+
6666666666666666
133+
6666666666666666
134+
6666666666666666
135+
6666666666666666
136+
6666666666666666
137+
6666666666666666
138+
6666666666666666
139+
6666666666666666
140+
6666666666666666
141+
6666666666666666
142+
6666666666666666
143+
6666666666666666
144+
6666666666666666
145+
6666666666666666`],
146+
[White, bitmap`
147+
2222222222222222
148+
2222222222222222
149+
2222222222222222
150+
2222222222222222
151+
2222222222222222
152+
2222222222222222
153+
2222222222222222
154+
2222222222222222
155+
2222222222222222
156+
2222222222222222
157+
2222222222222222
158+
2222222222222222
159+
2222222222222222
160+
2222222222222222
161+
2222222222222222
162+
2222222222222222`],
163+
[Wall, bitmap`
164+
3333333333333333
165+
3333333333333333
166+
LLLLLLLLLLLLLLLL
167+
LLLLLLLLLLLLLLLL
168+
3333333333333333
169+
3333333333333333
170+
LLLLLLLLLLLLLLLL
171+
LLLLLLLLLLLLLLLL
172+
3333333333333333
173+
3333333333333333
174+
LLLLLLLLLLLLLLLL
175+
LLLLLLLLLLLLLLLL
176+
3333333333333333
177+
3333333333333333
178+
LLLLLLLLLLLLLLLL
179+
LLLLLLLLLLLLLLLL`],
180+
[Blue, bitmap`
181+
7777777777777777
182+
7777777777777777
183+
7777777777777777
184+
7777777777777777
185+
7777777777777777
186+
7777777777777777
187+
7777777777777777
188+
7777777777777777
189+
7777777777777777
190+
7777777777777777
191+
7777777777777777
192+
7777777777777777
193+
7777777777777777
194+
7777777777777777
195+
7777777777777777
196+
7777777777777777`],
197+
[Cloud, bitmap`
198+
7777777777777777
199+
7777777777777777
200+
7777777777777777
201+
7777777777777777
202+
7777777777777777
203+
7777777777777777
204+
7777777777777777
205+
7777772222777777
206+
7777222222227777
207+
7777777777777777
208+
7777777777777777
209+
7777777777777777
210+
7777777777777777
211+
7777777777777777
212+
7777777777777777
213+
7777777777777777`],
214+
[Bluecar, bitmap`
215+
7777777777777777
216+
7777777777777777
217+
7777777777777777
218+
7777777777777777
219+
7777777777777777
220+
7777777777777777
221+
7777777777777777
222+
7777777337777777
223+
7777733333377777
224+
7777337777337777
225+
7777337777337777
226+
7773333333333777
227+
7733333333333377
228+
7733333333333377
229+
7777LL7777LL7777
230+
7777LL7777LL7777`]
231+
)
232+
233+
setSolids([Wall, car])
234+
235+
StartScreen = map`
236+
bCbCbby
237+
CbCbCbC
238+
bCbCbCb
239+
bbababb
240+
BBBBBBB`
241+
MainGame = map`
242+
wyyyyyyw
243+
wBcBBBBw
244+
wBBBoBBw
245+
wyyyyyyw
246+
wBBcBBBw
247+
wBBBBBBw
248+
wyyyypyw`
249+
250+
setMap(StartScreen)
251+
252+
setBackground(Black)
253+
254+
addText("Press i to Play", options = { x: 1, y: 5, color: color`3` })
255+
onInput("i", () => {
256+
if (!GameStarted) {
257+
GameStarted = true
258+
onInput("s", () => {
259+
getFirst(player).y += 1
260+
})
261+
onInput("w", () => {
262+
getFirst(player).y -= 1
263+
})
264+
onInput("a", () => {
265+
getFirst(player).x -= 1
266+
})
267+
onInput("d", () => {
268+
getFirst(player).x += 1
269+
})
270+
onInput("j", () => {
271+
playback = playTune(Theme, Infinity)
272+
})
273+
onInput("l", () => {
274+
playback.end()
275+
})
276+
setMap(MainGame)
277+
clearText()
278+
Main_Loop(1000)
279+
}
280+
})
281+
282+
function Player_Spawn() {
283+
getFirst(player).x = 3
284+
getFirst(player).y = 6
285+
}
286+
287+
function Collision() {
288+
if (tilesWith(car, player).length > 0 || tilesWith(Ocar, player).length > 0) {
289+
Player_Spawn()
290+
Score = 0
291+
Main_Loop(1000)
292+
clearText()
293+
};
294+
}
295+
296+
297+
function Move_RedCars(Steps) {
298+
for (let i = 0; i < getAll(car).length; i++) {
299+
dcar = getAll(car)[i]
300+
dcar.x += Steps
301+
Collision()
302+
if (dcar.x >= 6) {
303+
dcar.x = 1
304+
}
305+
}
306+
}
307+
308+
function Move_GreenCar(Steps) {
309+
getFirst(Ocar).x -= Steps
310+
Collision()
311+
if (getFirst(Ocar).x === 1) {
312+
getFirst(Ocar).x = 6
313+
};
314+
};
315+
316+
317+
function Main_Loop(time) {
318+
clearInterval(gameLoop);
319+
gameLoop = setInterval(() => {
320+
Move_RedCars(1);
321+
Move_GreenCar(1);
322+
Collision();
323+
}, time);
324+
}
325+
326+
function GettingPoints() {
327+
if (getFirst(player).y === 0) {
328+
Player_Spawn()
329+
Score++
330+
if (Score === 5) {
331+
Main_Loop(500)
332+
}
333+
if (Score === 10) {
334+
Main_Loop(250)
335+
}
336+
if (Score === 20) {
337+
Main_Loop(100)
338+
}
339+
if (Score > HighScore) {
340+
HighScore = Score
341+
}
342+
clearText()
343+
addText(`Score:${Score}`, options = { x: 1, y: 0, color: color`2` })
344+
addText(`HighScore:${HighScore}`, options = { x: 1, y: 12, color: color`2` })
345+
346+
}
347+
}
348+
349+
afterInput(() => {
350+
Collision();
351+
GettingPoints();
352+
})

0 commit comments

Comments
 (0)