-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredlight.html
295 lines (256 loc) · 6.17 KB
/
redlight.html
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>red light</title>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Y55LGP63JX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-Y55LGP63JX');
</script>
<meta
name="viewport"
content="width=device-width, height=device-height,
user-scalable=no, initial-scale=1, maximum-scale=1"
/>
<script src="https://unpkg.com/[email protected]/build/index.js"></script>
<script src="https://unpkg.com/[email protected]/build/index.js"></script>
<script src="https://unpkg.com/[email protected]/dist/pixi.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/pixi-filters.js"></script>
<script src="https://unpkg.com/[email protected]/docs/bundle.js"></script>
<script>
title = "red light";
characters = [
`
b b
bbbbbb
bBBBBb
bBBBBb
bbbbbb
b b
`,
`
rrr
r r
rrr
`,
`
ppp
p p
ppp
ppp
p p
`,
`
yyy
yy yy
yypyy
yy yy
yyyyy
y y
`
];
description = `
[Tap] to
stop & go
don't go on red
`;
let light, light_pos, light_status, yellow_counter;
let yellow_counter_max;
let ship, ship_pos;
let ship_moving;
let light_color;
let counter;
let speed;
let fall_speed;
let max_stop_odds, max_go_odds;
let move_speed;
let red_counter_max, green_counter_max;
let redgreen_counter_min;
let enemies;
let enemy_count;
let first_spawn;
options = {
isReplayEnabled: true,
theme: "pixel"
};
function update() {
if (!ticks) {
ship_pos = {
pos: vec(49, 80)
};
light_pos = {
pos: vec(45, 5)
};
enemies = [];
ship_moving = false;
counter = 0;
speed = 1;
light_status = 0; // green
fall_speed = 0;
enemy_count = 5;
first_spawn = true;
// changes go/stop frequency odds (higher is worse odds)
max_go_odds = 400;
max_stop_odds = 600;
move_speed = 0.35;
// number of ticks (120==2s) before yellow turns red
yellow_counter_max = 120;
// minimum number of ticks before red turns green and vice
redgreen_counter_min = 60;
// max counter, which we want higher for green to keep the game fun
green_counter_max = 180;
red_counter_max = 60;
return;
}
color("cyan");
rect(0, 20, 100, 3);
color("black");
ship = char("a", ship_pos.pos);
// if we cross the finish line, add a point
// and decrement yellow light time
if (ship.isColliding.rect.cyan)
{
addScore(1);
speed += 0.1;
enemies = [];
// always reset to green
light_status = 0;
redgreen_counter_min = 0;
first_spawn = true;
// add two more enemies every level
enemy_count += 1;
ship_pos = {
pos: vec(ship_pos.pos.x, 80)
};
ship_moving = false;
}
if (light_status == 2)
{
color("red");
}
else if (light_status == 1)
{
color("yellow");
}
else
{
color("green");
}
light = rect(light_pos.pos.x, light_pos.pos.y, 10, 10);
counter += 1;
if (input.isJustPressed)
{
ship_moving = !ship_moving;
}
// if light is red and we're moving, we lose
if (light_status == 2 && ship_moving)
{
end();
}
// if ship drops below 100, we lose
if (ship_pos.pos.y > 100)
{
end();
}
enemies.forEach((enemy) => {
color("black");
// we only move enemies if it's not red
if (light_status != 2)
{
enemy.pos.x -= enemy.speed;
}
let e = char(enemy.letter, enemy.pos);
if (e.isColliding.char.a)
{
end();
}
});
remove(enemies, (enemy) => {
return enemy.pos.x < 0 || enemy.pos.x > 100;
});
// spawn enemies if we're below our count
while (enemies.length < enemy_count)
{
// randomize whether enemy goes right to left or left to right
let enemy;
if (rnd(0, 2) < 1)
{
enemy = {pos: vec(rnd(90, 100), rnd(25,100)), speed: rnd(0.01, 0.10), letter: "b"};
}
else
{
enemy = {pos: vec(rnd(0, 10), rnd(25,100)), speed: -rnd(0.01, 0.10), letter: "b"};
}
if (first_spawn == true)
{
first_spawn = false;
enemy.pos.x = rnd(0, 100);
enemy.pos.y = rnd(25, 70);
}
let enemy_near_spawn = enemy.pos.y > 72 && enemy.pos.y < 85;
let enemy_near_midway_point = enemy.pos.y > 40 && enemy.pos.y < 50;
// randomize if we have aliens which are bigger and faster
// but only if they're not near spawn or the mid-way point, to give players a chance
// so they don't immediately lose on spawn because of a fast enemy
let random_enemy = floor(rnd(0, 3));
if (!enemy_near_spawn && !enemy_near_midway_point && random_enemy == 2)
{
enemy.letter = "c";
enemy.speed *= 2;
}
else if (!enemy_near_spawn && !enemy_near_midway_point && random_enemy == 1)
{
enemy.letter = "d";
enemy.speed *= 4;
}
enemies.push(enemy);
}
// ship movement
if (ship_moving)
{
ship_pos.pos.y -= move_speed;
}
else
{
ship_pos.pos.y += fall_speed;
}
// change color lights based off odds
if (light_status == 2) // red
{
redgreen_counter_min -= 1;
if ((rnd(0, max_stop_odds) < 2 && redgreen_counter_min <= 0) ||
redgreen_counter_min * -1 >= red_counter_max)
{
light_status = 0;
yellow_counter = yellow_counter_max;
redgreen_counter_min = 60;
}
}
else if (light_status == 1) // yellow
{
yellow_counter -= 1;
if (yellow_counter == 0)
{
light_status = 2;
}
}
else if (light_status == 0) // green
{
redgreen_counter_min -= 1;
if (rnd(0, max_go_odds) < 2 && redgreen_counter_min <= 0 ||
redgreen_counter_min * -1 >= green_counter_max)
{
light_status = 1;
yellow_counter = yellow_counter_max;
redgreen_counter_min = 60;
}
}
}
addEventListener("load", onLoad);
</script>
</head>
<body style="background: #eeeeee"></body>
</html>