forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DogsvsCats.js
202 lines (191 loc) · 3.38 KB
/
DogsvsCats.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
/*
@title: Dogs vs Cats
@author: Theodor
*/
const melody = tune `
500: f4^500 + g5~500,
500: f4^500,
500: g5~500,
500: c4^500,
500: c4^500 + g5~500,
500: c5^500,
500: c5^500 + g5~500,
500: e4^500,
500: e4^500 + g5~500 + c4-500,
500: f4^500 + c4-500,
500: f4^500 + g5~500,
500: c4^500,
500: c4^500 + g5~500,
500: c5^500,
500: c5^500 + g5~500,
500: e4^500,
500: e4^500 + a4-500 + g5~500,
500: f4^500 + a4-500,
500: f4^500 + g5~500,
500: c4^500,
500: c4^500 + g5~500,
500: c5^500,
500: c5^500 + g5~500,
500: e4^500,
500: e4^500 + c5-500 + g5~500,
500: f4^500 + c5-500,
500: f4^500 + g5~500,
500: c4^500,
500: c4^500 + g5~500,
500: c5^500,
500: c5^500 + g5~500,
500`
const playback = playTune(melody, Infinity)
const dogone = "p";
const dogtwo = "q";
const catone = "c";
const background = "b";
setLegend(
[ dogone, bitmap`
................
................
................
........66666666
........FFF66FFF
........FF0660FF
.........F6666F.
...66666666336..
.6666666666336..
.6.66666666666..
....6.......6...
....6.......6...
....66......66..
................
................
................`],
[ dogtwo, bitmap`
................
................
........66666666
66......FFF66FFF
.6......FF0660FF
.66......F6666F.
..666666666336..
..666666666336..
..666666666666..
6.6..........6.6
666..........666
................
................
................
................
................`],
[ catone, bitmap`
................
................
......L.L.......
.....LL.LL......
....LLL.LLL.....
....LLLLLLL.....
....LL3L3LL.....
.....LLLLL......
.....LLLL.......
.....LLLLLL....L
.....LLLLLLL..L.
.....LLLLLLL.LL.
.....LLLLLLLL...
.....LLLLLLLL...
................
................`],
[ background, bitmap`
444444444D444444
44444444D4D44444
44D4444444444444
4D4D444444444444
4444444444D44444
444444444D4D4444
4444444444444444
4444444444444444
4444444D444444D4
444444D4D4444D4D
4444444444444444
4D44444444444444
D4D4444444444444
44444D444444D444
4444D4D4444D4D44
4444444444444444`]
);
setBackground(background);
const dog = () => getFirst("p") || getFirst("q");
setSolids([]);
onInput("s", () => {
dog().y += 1;
});
onInput("w", () => {
dog().y -= 1;
});
let level = 0;
const levels = [
map`
.......
....c..
c......
......c
p......
.......
.......`,
];
setMap(levels[level]);
setPushables({
[ dog ]: [],
});
afterInput(() => {
if (dog()) {
const {x, y} = dog();
if (getTile(x, y).length > 1) {
addText("YOU LOSE!", { y: 4, color: color`3` });
}
}
});
let t=0;
let catspeed=400
let uded=false
let numcats=getAll(catone).length
function gameLoop() {
t++;
dog().type=[dogone,dogtwo][t % 2];
if (dog()) {
const {x, y} = dog();
if (getTile(x, y).length > 1) {
addText("YOU LOSE!", { y: 4, color: color`3` });
playback.end()
uded=true
}
}
if (!uded){
setTimeout(gameLoop, 400);
}
}
function movecat(cat) {
if (cat.x == 0){
cat.remove();
addSprite(6, Math.floor(Math.random() * 7), catone );
}
else{
cat.x -= 1
}
}
function moveCats() {
getAll(catone).forEach(movecat);
addText(""+numcats, { x:2, y: 0, color: color`H` });
if (!uded){
setTimeout(moveCats, catspeed);
}
}
function addCat() {
setTimeout(addCat, 20000);
addSprite(6, Math.floor(Math.random() * 7), catone );
catspeed=catspeed-10
numcats ++
if (catspeed < 100){
catspeed=100;
}
}
addCat();
moveCats();
gameLoop();