-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboxes.js
690 lines (572 loc) · 11.6 KB
/
boxes.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
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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
var sourceCode = `
title Boxes & Balloons
author Ben Reilly
homepage ben-reilly.com
color_palette amiga
realtime_interval 0.1
noaction
========
OBJECTS
========
Background
LightGrey LightGrey
00010
11111
01000
11111
00010
Exit
Yellow Brown
.111.
11111
11111
10001
11111
Wall
DarkGrey DarkGrey
00010
11111
01000
11111
00010
Player
darkbrown LightBrown orange
.000.
.111.
22222
.222.
.0.0.
DeadPlayer
darkred lightred red darkred
.000.
.111.
22222
.222.
.3.3.
Crate
Orange Lightbrown
00000
01110
01110
01110
00000
StuckCrate
DarkGrey Grey
00000
01110
01110
01110
00000
Balloon
Blue Grey
.000.
00000
.000.
..1..
.11..
PoppingBalloon
Blue Grey
.0.0.
0...0
.0.0.
..1.
.1...
LadderMain
Brown
.0.0.
.000.
.0.0.
.000.
.0.0.
LadderTop
Brown
.....
.....
.0.0.
.000.
.0.0.
LadderBottom
Brown
.0.0.
.000.
.0.0.
.....
.....
DownSpike
darkgrey red
..0..
..0..
..1..
.....
.....
UpSpike
darkgrey red
.....
.....
..1..
..0..
..0..
RightSpike
Darkgrey red
.....
.....
001..
.....
.....
LeftSpike
Darkgrey red
.....
.....
..100
.....
.....
(Weights/forces acting on objects; Wx, where x is the amount of downward pushing force applied to an object. Note that there is only one negative one, since we do top-down force calculations, so we only need to know if an object is moving up, not with how much force.)
FreeBody
White
Wn1
Grey
W0
Grey
W1
Grey
W2
Grey
W3
Grey
W4
Grey
W5
Grey
Final
Black
TimeTick
Blue
AllowMove
Red
Shadow
Black
Sound
Grey
=======
LEGEND
=======
Ladder = LadderMain or LadderTop or LadderBottom
Status = TimeTick or AllowMove or Sound
. = Background
# = Wall and Background
P = Player
C = Crate
B = Balloon
t = LadderTop
L = LadderMain
m = LadderBottom
- = Crate and LadderMain
+ = Balloon and LadderMain
* = Player and LadderMain
/ = Crate and LadderTop
0 = upspike
1 = rightspike
2 = downspike
3 = leftspike
X = Exit
W = Wn1 or W0 or W1 or W2 or W3 or W4 or W5
FB = FreeBody
Upper = Balloon
Downer = Crate or Player
Obj = Upper or Downer
Spike = Upspike or Downspike or Leftspike or Rightspike
vertspike = upspike or downspike
horizspike = leftspike or rightspike
Ground = Obj or StuckCrate or Wall or Ladder
=======
SOUNDS
=======
Crate MOVE 53548707
Balloon MOVE 798907
sfx5 15551704
sfx6 12412104
sfx7 50943104
================
COLLISIONLAYERS
================
Status
FB
W, Final
Shadow
Background
Ladder, Exit
Player, Wall, Crate, Balloon, StuckCrate, PoppingBalloon, DeadPlayer
Spike
======
RULES
======
(Mark if player is moving or not.)
[orthogonal Player] [Exit no AllowMove] -> CANCEL
[orthogonal Player] [timetick] -> [orthogonal Player] [no timetick]
[stationary Player] [Exit no timetick] -> [Player] [Exit TimeTick]
(If player moves, resolve gravity on the player before allowing another move.)
[Player no Shadow] -> [Player Shadow]
late [Exit no AllowMove] -> [Exit AllowMove]
late [Player no Shadow] [AllowMove] -> [Player] []
late [Shadow] -> []
(**********************************************************)
(***PLAYER-CAUSED MOTION***)
(**********************************************************)
(Player cannot move vertically, except on ladders, and to exit a ladder from below.)
[Exit no TimeTick] [vertical Player no Ladder] -> [Exit] [Player]
up [Exit no TimeTick] [> Player Ladder | no Ladder] -> [Exit] [ Player Ladder | ]
(Player cannot move horizontally mid-air)
down [Exit no TimeTick] [horizontal Player no Ladder | no Ground] -> [Exit] [Player |]
(Player pushes things, things push things. Includes vertical movement because players are strong and grip ladders really tightly.)
[Exit no TimeTick] [> Obj | Obj] -> [Exit] [> Obj | > Obj]
(**********************************************************)
(***GRAVITY***)
(**********************************************************)
(Idea: Apply gravitational forces to objects that are not being moved by the player. Process them from the top of a stack of objects downward, balancing the sum of positive (downward) and negative (upward) forces.
Since we're processing downward, any object determined to be moving upwards is definitely moving upwards. Such an object indicates the bottom of a sub-stack, and the next object in the stack starts the calculation over.
When we reach the bottom of a (sub-)stack, the movement of the final, lowest object tells us how the whole (sub-)stack will move, so we apply that movement iteratively upwards.
NOTE: Players can grip ladders really tightly, so they are only affected by stack gravity when the player is not on a ladder.
)
(***STEP 1: Mark the bodies that the player is not affecting.***)
[TimeTick] [stationary Balloon no FB] -> [TimeTick] [Balloon FB]
[TimeTick] [stationary Crate no FB] -> [TimeTick] [Crate FB]
[TimeTick] [stationary Player no Ladder no FB] -> [TimeTick] [Player FB]
(***STEP 2: Begin the gravity calc at top of each stack.***)
down [no FB | Upper FB] -> [ | < Upper FB Wn1]
down [no FB | Downer FB] -> [ | > Downer FB W1]
(***STEP 3: Iteratively apply gravity downward on stack.***)
(1. DOWNWARD MOTION)
down [> Obj W1 | Upper FB] -> [ Obj | Upper FB W0]
+ down [> Obj W2 | Upper FB] -> [> Obj | > Upper FB W1]
+ down [> Obj W3 | Upper FB] -> [> Obj | > Upper FB W2]
+ down [> Obj W4 | Upper FB] -> [> Obj | > Upper FB W3]
+ down [> Obj W5 | Upper FB] -> [> Obj | > Upper FB W4]
+ down [> Obj W1 | Downer FB] -> [> Obj | > Downer FB W2]
+ down [> Obj W2 | Downer FB] -> [> Obj | > Downer FB W3]
+ down [> Obj W3 | Downer FB] -> [> Obj | > Downer FB W4]
+ down [> Obj W4 | Downer FB] -> [> Obj | > Downer FB W5]
+ down [> Obj W5 | Downer FB] -> [> Obj | > Downer FB W5](!!)
(2. UPWARD MOTION)
(doesn't affect next; re-apply top-of-stack rules)
+ down [< Obj W | Upper FB] -> [< Obj Final | < Upper FB Wn1]
+ down [< Obj W | Downer FB] -> [< Obj Final | > Downer FB W1]
(3. NO MOTION)
(possibly subject to next obj; re-apply top-of-stack rules)
+ down [stationary Obj W | Upper FB] -> [< Obj Final | < Upper FB Wn1]
+ down [stationary Obj W | Downer FB] -> [ Obj | > Downer FB W1]
(***Step 4: Stop at bottom of stack.***)
(As with beginning a stack, if the stack is pushing into a non-free object, the stack remains still or else it might interrupt the other object's motion.)
down [Obj W | no FB] -> [Obj Final | ]
(***Step 5: Apply bottom-of-sub-stack motion to whole sub-stack.)
(1. UPWARD MOTION)
up [> Obj Final | Obj FB no Final] -> [> Obj Final| > Obj Final]
(2. DOWNWARD MOTION)
+ up [< Obj Final | Obj FB no Final] -> [< Obj Final | Obj Final]
(3. NO MOTION)
+ up [stationary Obj Final | Obj FB no Final] -> [Obj Final | Obj Final]
(**********************************************************)
(***Cleanup***)
late [W] -> []
late [Final] -> []
late [FreeBody] -> []
(
(Horizontal motion has the right-of-way.)
vertical [> Obj | horizontal Obj] -> [Obj | horizontal Obj]
)
(Spikes)
[poppingballoon] -> []
vertical [> balloon | vertspike] -> [> poppingballoon | vertspike]
horizontal [> balloon | horizspike] -> [> poppingballoon | horizspike]
late [poppingballoon no spike] -> [balloon]
late [poppingballoon] -> sfx5
vertical [> Crate | vertspike] -> [> stuckcrate | vertspike]
horizontal [> Crate | horizspike] -> [> stuckcrate | horizspike]
late [stuckcrate no spike] -> [Crate]
late [stuckcrate no Sound] -> [StuckCrate Sound] sfx6
vertical [> Player | vertspike] -> [> DeadPlayer | vertspike]
horizontal [> Player | horizspike] -> [> DeadPlayer | horizspike]
late [DeadPlayer no spike] -> [Player]
late [DeadPlayer no Sound] -> [DeadPlayer Sound] sfx7
==============
WINCONDITIONS
==============
Any Exit on Player
=======
LEVELS
=======
Message Version 1.2
Message Level 1
##########
##tcc.####
##l##.####
##l#..####
##l#..####
#pl#....x#
#######.##
#######.##
##########
Message Level 2
#########
##..tp..#
##..l#c.#
##..l.c.#
##t.l.c.#
#.l######
#.l....x#
####...##
#########
Message Level 3
##########
##tc....##
##lc....##
##lc....##
##l#....##
##l.....##
##lp..#.##
#.l####.x#
#.l.....##
##########
Message Level 4
##############
#t...........#
#l#####......#
#lc..........#
#l####.......#
#lc..........#
#l###........#
#lc..........#
#l##.........#
#lc..........#
#l#.........x#
#l...p....#.##
##############
Message Level 5
##########
##########
#p.tb..x.#
###l#.####
###lb.####
##########
##########
Message Level 6
###############
#..x.b.......t#
#####.###.###l#
#####.###.###l#
#....p.b.....l#
#######b#######
#######b#######
#######b#######
###############
Message Level 7
###############
#t.......b.x..#
#l###.###.#####
#l###.###.#####
#l...p.b......#
#######b#######
#######b#######
#######b#######
###############
Message Level 8
####################
##.#################
##t...........x.####
##l######.#######.##
##l..............t##
#######.###.#####l##
#.#####.###.#####l##
#t...............l##
#l###.###.###.######
#l###.###.###.######
#l###.###.###.######
#l.b...b...b...b..p#
###b###b###b###b####
###b###b###b###b####
###b###b###b########
####################
Message Level 9
###########
#####t...##
#####l##.##
#x.pclb..##
##.###b####
######.####
###########
###########
Message Level 10
#############
#...........#
#.x...pt....#
####c##l##c.#
#...b..l..b.#
#......l..b.#
#############
Message Level 11
############
####.#######
#.p.t.....##
####lc###.##
####lc....##
####lc###.##
####lb....##
####lb....##
####lb.....#
####l.....x#
######..#.##
######..#.##
############
############
Message Level 12
############
#......c...#
#t.p.t.b.x.#
#l###-#b####
#l...+..####
#l...l..####
############
Message Level 13
###############
#..cbc......t.#
#..#.#######l##
#..#.#.....cl.#
#..#.#.....bl.#
#..#.b..c..bl.#
#..#.#..###.l.#
#..#.#######l##
#.t.........l.#
##l############
#.l...........#
#.l.p.....x...#
#######c#######
#######b#######
#######b#######
###############
Message Level 14
#############
##########.##
##########.##
##########.##
#t../..b.p.x#
#l##+##b##.##
#l..+...#####
####+########
####l########
####l########
#############
Message Level 15
###########
####ttt####
####l-l####
###pl-l.###
####l+l####
####l+l####
#####m#####
#####.#####
#####.#####
#####.#####
####.....x#
#####.#.###
#######.###
###########
Message Level 16
###############
#t.t.p.t.b..x3#
#l#l###l#.#####
#l#m###l#.#####
#l#..bbm#.#####
#l#####.b.#####
#l#####.#######
#l......#######
###############
Message Level 17
################
#############.##
#t..p.........x#
#l######.##.#.##
#l###t.t.##c####
#l###l#l...c.###
#l###l#l###b####
#l###l#l###b####
#l###l#l###.####
#l###l.l########
#l#####l########
#lbbbbbl########
#######l########
#######0########
################
Message Level 18
#################
####c############
####c############
####c############
##t.c...........#
##l####.........#
##l.............#
##l......p.t....#
##l.....###l....#
#.l........l....#
#.l....0...l...x#
#############.###
#############.###
#############.###
#############.###
#################
Message Level 19
############
#########2##
#t........##
#l###.###.##
#l#tc3#t.t##
#l#lb.#l#l##
#l#lb3#l#l.#
#l.l...l.l.#
#l###.###-##
#l###..x#+##
#l###.###l##
#l.p.0...l##
############
Message Level 20
############
#t.p.....x.#
#l#####.####
#l#2#2#.####
#l.t....####
#l#l#c#.####
#l.-.c..####
#l#+#b..####
#l.l###.####
###l..b3####
############
Message Level 21
##########
####2#####
#tp..2.x3#
#l##tt####
#l..ll...#
####--####
#tb.++.bt#
#l##ll##l#
#l##ll##l#
#l##ll##l#
#l..ll..l#
##########
Message Level 22
#####################
###...........t.#####
###.##########l..####
###.#####.....l...###
#.t.t...2..c..l....##
#.m#l###.#####l.....#
##cbl#x.......l.....#
##b.l###1.....l.p..t#
##.#l###.##########l#
##.bl###....2......l#
##..l#######.###.##l#
##0.l.........b....l#
##############b######
##############b######
##############b######
##############b######
#####################
`