Skip to content

Commit 1cd4de6

Browse files
committed
Sprig App - horse rider 2
1 parent accce9e commit 1cd4de6

File tree

2 files changed

+196
-0
lines changed

2 files changed

+196
-0
lines changed

games/horse-rider-2.js

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/*
2+
First time? Check out the tutorial game:
3+
https://sprig.hackclub.com/gallery/getting_started
4+
5+
@title: horse rider 1
6+
@author: mozes
7+
@tags: []
8+
@addedOn: 2025-12-05
9+
*/
10+
11+
const player = "p"
12+
const fence = "f"
13+
const jumpgate = "j"
14+
const portal = "n"
15+
16+
setLegend(
17+
[player, bitmap`
18+
.....6666.......
19+
......CCC.......
20+
......CC0.......
21+
......CCC.......
22+
......7575......
23+
......755.5.FFF.
24+
......77555FF0C.
25+
......7775FFCCCC
26+
..CCCC555FFCCCC.
27+
FFCCCC555CCCC...
28+
FFCCCC555CCCC...
29+
FCCCCCLLLCCC....
30+
F.CCCCCCCCCC....
31+
F...CC..CCC.....
32+
...C.C..C.C.....
33+
...C.C.C..C.....`],
34+
[fence, bitmap`
35+
................
36+
................
37+
................
38+
................
39+
................
40+
................
41+
................
42+
................
43+
CCCCCCCCCCCCCCCC
44+
C..............C
45+
CCCCCCCCCCCCCCCC
46+
C..............C
47+
CCCCCCCCCCCCCCCC
48+
C..............C
49+
CCCCCCCCCCCCCCCC
50+
C..............C`],
51+
[jumpgate, bitmap`
52+
................
53+
.......333......
54+
.......232......
55+
.......333......
56+
.......232......
57+
.......333......
58+
.......232......
59+
.......333......
60+
.......232......
61+
.......333......
62+
.......232......
63+
.......333......
64+
.......232......
65+
.......333......
66+
.......232......
67+
.......333......`],
68+
[portal, bitmap`
69+
6363000000003636
70+
36300HHHHHH00363
71+
6300HH5555HH0036
72+
300HH588885HH003
73+
00HH55877855HH00
74+
0HH5588778855HH0
75+
0H558877778855H0
76+
0H588772277885H0
77+
0H588772227785H0
78+
0H558877277885H0
79+
0HH55887778855H0
80+
00HH558878855HH0
81+
300HH5588855HH00
82+
6300HH55555HH003
83+
36300HHHHHHH0036
84+
6363000000000363`]
85+
)
86+
87+
setSolids([fence, jumpgate, player])
88+
89+
let level = 0
90+
const levels = [
91+
map`
92+
njffffffff
93+
fjj.jf.j.j
94+
.j.fj.f.jf
95+
fj.ff.ff.f
96+
.j.f..j.j.
97+
fjfjfjfjff
98+
fjf.ff.f..
99+
pj.j.j..j.`,
100+
map`
101+
ffffffffff
102+
pj.j.j.j.j
103+
j.j.j.j..j
104+
j.jffffffn
105+
j.jf....ff
106+
f....ff...`,
107+
map`
108+
.j.fffn
109+
fj.ffff
110+
.jf.j..
111+
pj..fff`,
112+
map`
113+
pj.fj
114+
fnf..
115+
ff.j.`,
116+
map`
117+
.........jnfj.jj
118+
....ff...fffjfjj
119+
f.ffffff..f.j.j.
120+
f.fffpffffffffff
121+
jf.jjfjjf.j..jf.
122+
j.fjj.jjffjjfj..
123+
jf.jjfjj..jj.jfj
124+
j.fjj.jj.fjjfj.j
125+
jf.jjfjjffjj.jfj
126+
j.fjj.jj..jjfj..
127+
jf.j..jj.fjj.jf.
128+
jffjj.j.j.jjfjff
129+
fffffffffffj.j..`,
130+
map`
131+
pjn`
132+
]
133+
134+
setMap(levels[level])
135+
136+
setPushables({
137+
[player]: [],
138+
})
139+
140+
onInput("s", () => {
141+
getFirst(player).y += 1
142+
});
143+
144+
onInput("w", () => {
145+
getFirst(player).y -= 1
146+
});
147+
148+
onInput("d", () => {
149+
getFirst(player).x += 1
150+
});
151+
152+
onInput("a", () => {
153+
getFirst(player).x -= 1
154+
});
155+
156+
onInput("j", () => {
157+
getFirst(player).x -= 2
158+
});
159+
160+
onInput("l", () => {
161+
getFirst(player).x += 2
162+
});
163+
164+
onInput("i", () => {
165+
getFirst(player).y -= 2
166+
});
167+
168+
onInput("k", () => {
169+
getFirst(player).y += 2
170+
});
171+
172+
afterInput(() => {
173+
// count the number of tiles with goals
174+
const targetNumber = tilesWith(portal).length;
175+
176+
// count the number of tiles with goals and boxes
177+
const numberCovered = tilesWith(portal, player).length;
178+
179+
// if the number of goals is the same as the number of goals covered
180+
// all goals are covered and we can go to the next level
181+
if (numberCovered === targetNumber) {
182+
// increase the current level number
183+
level = level + 1;
184+
185+
const currentLevel = levels[level];
186+
187+
// make sure the level exists and if so set the map
188+
// otherwise, we have finished the last level, there is no level
189+
// after the last level
190+
if (currentLevel !== undefined) {
191+
setMap(currentLevel);
192+
} else {
193+
addText("you win!", { y: 4, color: color`3` });
194+
}
195+
}
196+
});

games/img/horse-rider-2.png

1.51 KB
Loading

0 commit comments

Comments
 (0)