forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch_5_victory.js
128 lines (115 loc) · 2.04 KB
/
ch_5_victory.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
/*
@title: CH. 5 - victory
@author: hackclub
Count the right number of target tiles to test the win condition.
hint: use tilesWith to count tiles with a certain content
*/
const bean = 'a';
const vine = 'b';
const trellis = 'c';
const target = 'd';
setLegend(
[bean, bitmap`
................
......000.......
.....0.220......
.....002020.....
..0..022..0.....
...0..0...0.....
...0000...20....
....2.0...20....
.....0....200...
....0...220.0...
....0...220.0...
....02.220...2..
.....0000.......
....0....0......
....0....0......
...00...00......`],
[vine, bitmap`
........44......
.......44.......
......44.......4
......4........4
.....44........4
.44..4........44
.44.44........4.
..444........44.
..44......44.4..
.44.......4444..
44.........444..
44..........42..
4...........4...
4..........44...
4.........44....
4........44.....`],
[trellis, bitmap`
.L...L.....L..L.
.L...L.....L..L.
..L.L.L...LL.L..
..L.L.L...L.LL..
..L.L.L..L..LL..
..LL...L.L..LL..
...L...L.L..L...
...L...LL...L...
..LL....L...LL..
..LL...LL...LL..
..L.L..LL..L.L..
.L..L..L.L.L.L..
.L..L.L..L.L.L..
.L..L.L..L.L..L.
L....L....L...L.
L....L....L...L.`],
[target, bitmap`
......3..3......
....333..333....
...3..3..3..3...
..3..........3..
.3............3.
.3............3.
333....33....333
......3..3......
......3..3......
333....33....333
.3............3.
.3............3.
..3..........3..
...3..3..3..3...
....333..333....
......3..3......`]
);
setMap(map`
bbbbbbbbb
bbbb..dbb
bbb.....b
bb..c...b
b...c.a.b
b......bb
b.d...bbb
bb.bbbbbb
bbbbbbbbb`);
const player = () => getFirst(bean);
onInput("a", () => {
player().x -= 1;
});
onInput("d", () => {
player().x += 1;
});
onInput("s", () => {
player().y += 1;
});
onInput("w", () => {
player().y -= 1;
});
setSolids( [ bean, trellis, vine ]);
afterInput(() => {
const coveredTargetCount = tilesWith(target, trellis).length;
// TODO: change three to something like the line above
const targetCount = 3;
if (targetCount == coveredTargetCount) {
addText("you win!");
}
})
setPushables({
[bean]: [trellis]
})