-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ts
More file actions
646 lines (644 loc) · 23.8 KB
/
main.ts
File metadata and controls
646 lines (644 loc) · 23.8 KB
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
namespace SpriteKind {
export const MovingPlatform = SpriteKind.create()
export const Sign = SpriteKind.create()
export const Star = SpriteKind.create()
}
controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
if (jumps_made < constants_jumps_max && can_jump) {
jump(sprite_player, constants_gravity, 32)
jumps_made += 1
}
})
scene.onHitWall(SpriteKind.Player, function (sprite, location) {
if (sprite.isHittingTile(CollisionDirection.Bottom)) {
jumps_made = 0
if (sprite_player.y < traveled_height) {
traveled_height = sprite_player.y
info.changeScoreBy(1)
}
if (sprite.tileKindAt(TileDirection.Bottom, assets.tile`trampoline`)) {
jump(sprite_player, constants_gravity, 64)
tiles.setTileAt(location, assets.tile`activated_trampoline`)
timer.after(100, function () {
tiles.setTileAt(location, assets.tile`trampoline`)
})
} else if (sprite.tileKindAt(TileDirection.Bottom, assets.tile`transition_block`)) {
timer.throttle("switch_boards", 5000, function () {
timer.background(function () {
enable_controls(false)
fade_in(2000, true)
clear_map()
local_col = make_map(19, Math.floor(width), 3, 3)
tiles.placeOnTile(sprite_player, tiles.getTileLocation(local_col, tiles.tilemapRows() - 4))
traveled_height = sprite_player.y
if (levels_passed == 0) {
make_sign(local_col, tiles.tilemapRows() - 4, "Be careful!\\n" + "If you fall below this platform, you will die!" + "" + "" + "")
}
fade_out(2000, false)
enable_controls(true)
width = Math.max(width - 0.25, 3)
moving_platform_speed = Math.max(moving_platform_speed - 1000, 3000)
double_platform_chance = Math.max(double_platform_chance - 5, 10)
disappearing_speed = Math.max(disappearing_speed - 100, 100)
levels_passed += 1
})
})
} else if (is_disappearing_tile(tiles.locationXY(location, tiles.XY.column), tiles.locationXY(location, tiles.XY.row))) {
update_disappearing(tiles.locationXY(location, tiles.XY.column), tiles.locationXY(location, tiles.XY.row), disappearing_speed)
}
}
})
function make_disappearing (left: number, width: number, height: number) {
for (let index = 0; index <= width - 1; index++) {
tiles.setTileAt(tiles.getTileLocation(left + index, height), assets.tile`disappearing_block`)
tiles.setWallAt(tiles.getTileLocation(left + index, height), true)
}
}
function make_platform (left: number, width: number, height: number) {
for (let index = 0; index <= width - 1; index++) {
tiles.setTileAt(tiles.getTileLocation(left + index, height), assets.tile`block`)
tiles.setWallAt(tiles.getTileLocation(left + index, height), true)
}
}
controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
if (sprite_player.overlapsWith(sprite_customization_icon)) {
timer.throttle("activate_customizer", 100, function () {
enable_controls(false)
blockMenu.showMenu(["Cancel", "Change hat color", "Change skin color", "Reset look"], MenuStyle.List, MenuLocation.FullScreen)
wait_for_menu_select()
if (blockMenu.selectedMenuOption().includes("Cancel")) {
} else if (blockMenu.selectedMenuIndex() == 1) {
local_color = ask_for_color()
if (local_color != -1) {
hat_color = local_color
blockSettings.writeNumber("hat_color", hat_color)
fade_in(2000, true)
game.reset()
}
} else if (blockMenu.selectedMenuIndex() == 2) {
local_color = ask_for_color()
if (local_color != -1) {
body_color = local_color
blockSettings.writeNumber("body_color", body_color)
fade_in(2000, true)
game.reset()
}
} else if (blockMenu.selectedMenuIndex() == 3) {
hat_color = 8
body_color = 6
blockSettings.writeNumber("hat_color", hat_color)
blockSettings.writeNumber("body_color", body_color)
fade_in(2000, true)
game.reset()
}
timer.after(100, function () {
enable_controls(true)
})
})
} else if (sprite_player.overlapsWith(sprite_nighttime_mode)) {
timer.throttle("switch_nighttime", 100, function () {
night_time = !(night_time)
write_bool("night_time", night_time)
enable_controls(false)
fade_in(2000, true)
game.reset()
})
} else if (sprite_player.overlapsWith(sprite_reset_all_icon)) {
timer.throttle("ask_reset_all", 100, function () {
if (game.ask("Are you sure you", "want to reset?")) {
if (game.ask("Are you REALLY sure", "you want to reset?")) {
blockSettings.remove("hat_color")
blockSettings.remove("body_color")
blockSettings.remove("night_time")
blockSettings.remove("high-score")
blockSettings.remove("timing")
enable_controls(false)
fade_in(2000, true)
game.reset()
}
}
})
} else if (sprite_player.overlapsWith(sprite_timed_mode_icon)) {
timer.throttle("toggle_timed_mode", 100, function () {
if (game.ask("Would you like to", "toggle timed mode?")) {
timing = !(timing)
write_bool("timing", timing)
enable_controls(false)
fade_in(2000, true)
game.reset()
}
})
} else if (overlaping_of_kind(sprite_player, SpriteKind.Sign).length > 0) {
for (let location of tiles.getTilesByType(assets.tile`moving_platform`)) {
tiles.setTileAt(location, assets.tile`transparency8`)
tiles.setWallAt(location, false)
}
game.showLongText(sprites.readDataString(overlaping_of_kind(sprite_player, SpriteKind.Sign)[0], "text"), DialogLayout.Full)
for (let location of tiles.getTilesByType(assets.tile`moving_platform`)) {
tiles.setTileAt(location, assets.tile`transparency8`)
tiles.setWallAt(location, false)
}
}
})
function make_trampoline (left: number, width: number, height: number) {
for (let index = 0; index <= width - 1; index++) {
tiles.setTileAt(tiles.getTileLocation(left + index, height), assets.tile`trampoline`)
tiles.setWallAt(tiles.getTileLocation(left + index, height), true)
}
}
scene.onOverlapTile(SpriteKind.Player, assets.tile`bottom_of_sky`, function (sprite, location) {
game_over()
})
function write_bool (name: string, value: boolean) {
if (value) {
blockSettings.writeNumber(name, 1)
} else {
blockSettings.writeNumber(name, 0)
}
}
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
if (jumps_made < constants_jumps_max && can_jump) {
jump(sprite_player, constants_gravity, 32)
jumps_made += 1
}
})
function clear_map () {
if (night_time) {
tiles.setSmallTilemap(tilemap`next_levels_night`)
} else {
tiles.setSmallTilemap(tilemap`next_levels`)
}
for (let sprite of sprites.allOfKind(SpriteKind.MovingPlatform)) {
sprite.destroy()
}
for (let sprite of sprites.allOfKind(SpriteKind.Food)) {
sprite.destroy()
}
for (let sprite of sprites.allOfKind(SpriteKind.Sign)) {
sprite.destroy()
}
}
scene.onOverlapTile(SpriteKind.MovingPlatform, assets.tile`transparency8`, function (sprite, location) {
tiles.setTileAt(location, assets.tile`moving_platform`)
tiles.setWallAt(location, true)
timer.after(sprites.readDataNumber(sprite, "block_delay"), function () {
tiles.setTileAt(location, assets.tile`transparency8`)
tiles.setWallAt(location, false)
})
})
function make_sign (col: number, row: number, text: string) {
sprite_sign = sprites.create(assets.image`sign`, SpriteKind.Sign)
tiles.placeOnTile(sprite_sign, tiles.getTileLocation(col, row))
sprites.setDataString(sprite_sign, "text", text)
}
function fade_out (time: number, block: boolean) {
color.startFade(color.Black, color.originalPalette, time)
if (block) {
color.pauseUntilFadeDone()
}
}
function read_bool (name: string) {
return blockSettings.readNumber(name) == 1
}
function make_coin (col: number, row: number) {
sprite_coin = sprites.create(assets.image`coin`, SpriteKind.Food)
animation.runImageAnimation(
sprite_coin,
assets.animation`coin_bobbing`,
500,
true
)
tiles.placeOnTile(sprite_coin, tiles.getTileLocation(col, row))
sprite_coin.y += -3
}
function game_over () {
sprite_player.setFlag(SpriteFlag.Ghost, true)
enable_controls(false)
timer.after(1000, function () {
sprite_player.destroy()
})
timer.after(2000, function () {
if (timing) {
time = spriteutils.roundWithPrecision((game.runtime() - start_time) / 1000, 3)
game.showLongText("Time: " + time + "s" + "\\nPoints: " + info.score() + "\\nHigh score: " + info.highScore() + "\\nPoints/second: " + spriteutils.roundWithPrecision(info.score() / time, 3), DialogLayout.Full)
timer.after(1000, function () {
game.over(false)
})
} else {
game.over(false)
}
})
}
info.onCountdownEnd(function () {
})
function fade_in (time: number, block: boolean) {
color.startFade(color.originalPalette, color.Black, time)
if (block) {
color.pauseUntilFadeDone()
}
}
function wait_for_menu_select () {
selected_menu = false
while (!(selected_menu)) {
pause(100)
}
blockMenu.closeMenu()
}
function ask_for_color () {
blockMenu.showMenu([
"Cancel",
"White",
"Red",
"Pink",
"Orange",
"Yellow",
"Cyan",
"Green",
"Dark blue",
"Light blue",
"Purple",
"Light purple",
"Dark purple",
"Tan",
"Brown",
"Black"
], MenuStyle.Grid, MenuLocation.FullScreen)
wait_for_menu_select()
if (blockMenu.selectedMenuOption().includes("Cancel")) {
return -1
} else {
return blockMenu.selectedMenuIndex()
}
}
function is_disappearing_tile (col: number, row: number) {
for (let tile of [assets.tile`disappearing_block`, assets.tile`disappearing_block_75`, assets.tile`disappearing_block_50`, assets.tile`disappearing_block_25`, assets.tile`disappearing_block_0`]) {
if (tiles.tileAtLocationEquals(tiles.getTileLocation(col, row), tile)) {
return true
}
}
return false
}
function make_transition (left: number, width: number, height: number) {
for (let index = 0; index <= width - 1; index++) {
tiles.setTileAt(tiles.getTileLocation(left + index, height), assets.tile`transition_block`)
tiles.setWallAt(tiles.getTileLocation(left + index, height), true)
}
}
function overlaping_of_kind (sprite_overlap: Sprite, kind: number) {
local_sprites_overlapped = []
for (let sprite of sprites.allOfKind(kind)) {
if (sprite_overlap.overlapsWith(sprite)) {
local_sprites_overlapped.push(sprite)
}
}
return local_sprites_overlapped
}
function enable_controls (enable: boolean) {
if (enable) {
controller.moveSprite(sprite_player, 100, 0)
} else {
controller.moveSprite(sprite_player, 0, 0)
}
can_jump = enable
}
function update_disappearing (col: number, row: number, delay: number) {
timer.throttle("disappear_" + col + "x" + row, delay * 4 + 3000, function () {
timer.after(delay * 0, function () {
tiles.setTileAt(tiles.getTileLocation(col, row), assets.tile`disappearing_block`)
})
timer.after(delay * 1, function () {
tiles.setTileAt(tiles.getTileLocation(col, row), assets.tile`disappearing_block_75`)
})
timer.after(delay * 2, function () {
tiles.setTileAt(tiles.getTileLocation(col, row), assets.tile`disappearing_block_50`)
})
timer.after(delay * 3, function () {
tiles.setTileAt(tiles.getTileLocation(col, row), assets.tile`disappearing_block_25`)
})
timer.after(delay * 4, function () {
tiles.setWallAt(tiles.getTileLocation(col, row), false)
tiles.setTileAt(tiles.getTileLocation(col, row), assets.tile`disappearing_block_0`)
timer.after(3000, function () {
if (tiles.tileAtLocationEquals(tiles.getTileLocation(col, row), assets.tile`disappearing_block_0`)) {
tiles.setWallAt(tiles.getTileLocation(col, row), true)
tiles.setTileAt(tiles.getTileLocation(col, row), assets.tile`disappearing_block`)
}
})
})
})
}
controller.menu.onEvent(ControllerButtonEvent.Pressed, function () {
if (timing) {
Notification.waitForNotificationFinish()
Notification.notify("Can't pause in timed mode!", 1, img`
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
`)
} else {
for (let location of tiles.getTilesByType(assets.tile`moving_platform`)) {
tiles.setTileAt(location, assets.tile`transparency8`)
tiles.setWallAt(location, false)
}
scene.systemMenu.showSystemMenu()
for (let location of tiles.getTilesByType(assets.tile`moving_platform`)) {
tiles.setTileAt(location, assets.tile`transparency8`)
tiles.setWallAt(location, false)
}
}
})
function jump (sprite: Sprite, gravity: number, pixels: number) {
sprite.vy = Math.sqrt(2 * (gravity * pixels)) * -1
}
function make_map (num_platforms: number, width: number, start_y: number, space: number) {
let index = 0
local_start = randint(0, 20 - width)
make_platform(local_start, width, 60 - (index * space + start_y))
for (let index = 0; index <= num_platforms - 3; index++) {
make_random(randint(0, 20 - width), width, 60 - ((index + 1) * space + start_y))
}
make_transition(randint(0, 20 - width), width, 60 - ((num_platforms - 1) * space + start_y))
return local_start + Math.round(width / 2)
}
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
otherSprite.destroy(effects.trail, 100)
info.changeScoreBy(1)
})
function make_random (left: number, width: number, height: number) {
local_random = randint(0, 100)
if (local_random < 40) {
make_platform(left, width, height)
if (Math.percentChance(3)) {
make_coin(randint(left + 1, left + width - 1), height - 1)
}
if (Math.percentChance(double_platform_chance)) {
make_platform(left + randint(width, 20), width, height)
}
} else if (local_random < 60) {
make_trampoline(left, width, height)
if (Math.percentChance(3)) {
make_coin(randint(left + 1, left + width - 1), height - 1)
}
} else if (local_random < 80) {
make_moving_platform(left, width, height, moving_platform_speed)
} else {
make_disappearing(left, width, height)
if (Math.percentChance(3)) {
make_coin(randint(left + 1, left + width - 1), height - 1)
}
}
}
function make_stars (stars: number) {
for (let index = 0; index < stars; index++) {
if (Math.percentChance(33)) {
sprite_star = sprites.create(assets.image`star_1`, SpriteKind.Star)
} else if (Math.percentChance(50)) {
sprite_star = sprites.create(assets.image`star_2`, SpriteKind.Star)
} else {
sprite_star = sprites.create(assets.image`star_3`, SpriteKind.Star)
}
if (Math.percentChance(50)) {
sprite_star.image.replace(5, 1)
}
sprite_star.setFlag(SpriteFlag.Ghost, true)
sprite_star.setFlag(SpriteFlag.RelativeToCamera, true)
sprite_star.setPosition(randint(0, scene.screenWidth()), randint(0, scene.screenHeight()))
sprite_star.z = -100
}
}
function animate_player (sprite: Sprite) {
character.loopFrames(
sprite,
assets.animation`walk_left`,
200,
character.rule(Predicate.MovingLeft)
)
character.loopFrames(
sprite,
assets.animation`look_left`,
200,
character.rule(Predicate.NotMoving, Predicate.FacingLeft)
)
character.loopFrames(
sprite,
assets.animation`walk_right`,
200,
character.rule(Predicate.MovingRight)
)
character.loopFrames(
sprite,
assets.animation`look_left0`,
200,
character.rule(Predicate.NotMoving, Predicate.FacingRight)
)
character.loopFrames(
sprite,
assets.animation`look_straight`,
200,
character.rule(Predicate.MovingUp)
)
character.loopFrames(
sprite,
assets.animation`look_down`,
200,
character.rule(Predicate.MovingDown)
)
}
blockMenu.onMenuOptionSelected(function (option, index) {
selected_menu = true
})
scene.onOverlapTile(SpriteKind.Player, assets.tile`bottom_of_sky_night`, function (sprite, location) {
game_over()
})
function make_moving_platform (left: number, width: number, height: number, time: number) {
sprite_moving_platform = sprites.create(assets.image`moving_platform_head`, SpriteKind.MovingPlatform)
tiles.placeOnTile(sprite_moving_platform, tiles.getTileLocation(0, height))
sprite_moving_platform.left = left * 8
sprite_moving_platform.setFlag(SpriteFlag.Invisible, true)
sprites.setDataNumber(sprite_moving_platform, "block_delay", time / 10)
local_path = ""
for (let index = 0; index < (156 - sprite_moving_platform.left) / 8; index++) {
local_path = "" + local_path + " h " + "8"
}
for (let index = 0; index < 20; index++) {
local_path = "" + local_path + " h " + "-8"
}
for (let index = 0; index < Math.abs(sprite_moving_platform.left - 4) / 8; index++) {
local_path = "" + local_path + " h " + "8"
}
animation.runMovementAnimation(
sprite_moving_platform,
local_path,
time,
true
)
}
let local_path = ""
let sprite_moving_platform: Sprite = null
let sprite_star: Sprite = null
let local_random = 0
let local_start = 0
let local_sprites_overlapped: Sprite[] = []
let selected_menu = false
let time = 0
let sprite_coin: Sprite = null
let sprite_sign: Sprite = null
let local_color = 0
let local_col = 0
let sprite_timed_mode_icon: Sprite = null
let sprite_reset_all_icon: Sprite = null
let sprite_nighttime_mode: Sprite = null
let sprite_customization_icon: Sprite = null
let sprite_player: Sprite = null
let start_time = 0
let levels_passed = 0
let disappearing_speed = 0
let double_platform_chance = 0
let moving_platform_speed = 0
let width = 0
let traveled_height = 0
let can_jump = false
let jumps_made = 0
let timing = false
let night_time = false
let body_color = 0
let hat_color = 0
let constants_jumps_max = 0
let constants_gravity = 0
constants_gravity = 400
constants_jumps_max = 2
if (blockSettings.exists("hat_color")) {
hat_color = blockSettings.readNumber("hat_color")
} else {
hat_color = 8
}
if (blockSettings.exists("body_color")) {
body_color = blockSettings.readNumber("body_color")
} else {
body_color = 6
}
if (blockSettings.exists("night_time")) {
night_time = read_bool("night_time")
} else {
night_time = false
}
if (blockSettings.exists("timing")) {
timing = read_bool("timing")
} else {
timing = false
}
jumps_made = 0
can_jump = true
traveled_height = 0
width = 5
moving_platform_speed = 10000
double_platform_chance = 50
disappearing_speed = 1000
levels_passed = 0
start_time = -1
color.setPalette(
color.Black
)
sprite_player = sprites.create(assets.image`front_facing`, SpriteKind.Player)
animate_player(sprite_player)
enable_controls(true)
sprite_player.ay = constants_gravity
sprite_player.z = 10
info.setScore(0)
tiles.setSmallTilemap(tilemap`starting_level`)
if (night_time) {
scene.setBackgroundColor(15)
make_stars(randint(30, 40))
} else {
scene.setBackgroundColor(9)
}
scene.cameraFollowSprite(sprite_player)
tiles.placeOnTile(sprite_player, tiles.getTileLocation(1, 58))
traveled_height = sprite_player.y
make_map(18, width, 5, 3)
make_sign(2, 58, "Welcome to Jump!\\n \\n" + "Press the left/right keys to move.\\n" + "Press A/up key to jump.\\n" + "Press B to read signs." + "")
make_sign(4, 58, "Your high score is: " + info.highScore())
sprite_customization_icon = sprites.create(assets.image`customization_icon`, SpriteKind.Sign)
tiles.placeOnTile(sprite_customization_icon, tiles.getTileLocation(17, 58))
if (night_time) {
sprite_nighttime_mode = sprites.create(assets.image`day_time_icon`, SpriteKind.Sign)
} else {
sprite_nighttime_mode = sprites.create(assets.image`night_time_icon`, SpriteKind.Sign)
}
tiles.placeOnTile(sprite_nighttime_mode, tiles.getTileLocation(15, 58))
sprite_reset_all_icon = sprites.create(assets.image`reset_all_icon`, SpriteKind.Sign)
tiles.placeOnTile(sprite_reset_all_icon, tiles.getTileLocation(13, 58))
sprite_timed_mode_icon = sprites.create(assets.image`stop_watch_icon`, SpriteKind.Sign)
tiles.placeOnTile(sprite_timed_mode_icon, tiles.getTileLocation(11, 58))
if (timing) {
animation.runImageAnimation(
sprite_timed_mode_icon,
assets.animation`stop_watch_moving_animation`,
100,
true
)
}
blockMenu.setColors(1, 15)
fade_out(2000, false)
timer.background(function () {
while (!(controller.anyButton.isPressed() && !(controller.menu.isPressed()))) {
pause(100)
}
start_time = game.runtime()
})
game.onUpdate(function () {
sprite_player.image.replace(6, body_color)
sprite_player.image.replace(8, hat_color)
})
game.onUpdate(function () {
if (timing && start_time != -1) {
info.startCountdown(spriteutils.roundWithPrecision((game.runtime() - start_time) / 1000, 3))
}
})
forever(function () {
if (night_time) {
if (Math.percentChance(1)) {
sprite_star = sprites.create(assets.image`star_1`, SpriteKind.Star)
if (Math.percentChance(50)) {
sprite_star.image.replace(5, 1)
}
sprite_star.setFlag(SpriteFlag.Ghost, true)
sprite_star.setFlag(SpriteFlag.RelativeToCamera, true)
sprite_star.z = -100
sprite_star.y = randint(0, scene.screenHeight())
if (Math.percentChance(50)) {
sprite_star.right = 0
sprite_star.vx = randint(80, 100)
} else {
sprite_star.left = scene.screenWidth()
sprite_star.vx = randint(-80, -100)
}
sprite_star.ay = 25
sprite_star.vy = -25
}
timer.after(100, function () {
if (sprite_star) {
sprite_star.setFlag(SpriteFlag.AutoDestroy, true)
}
})
pause(1000)
} else {
if (levels_passed < 5) {
effects.clouds.startScreenEffect(100)
}
pause(1000 + levels_passed * 500)
}
})