forked from JoshuaKGoldberg/Old-Deleted-FullScreenMario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.js
4525 lines (4101 loc) · 155 KB
/
maps.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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Maps.js */
// Contains functions for creating, populating, and using maps
/* Basic Map Functions */
function resetMaps() {
var i, j, mapfunc;
window.currentmap = [1,1];
window.defaultsetting = { setting: "Overworld" };
// Mapfuncs starts off such that [X][Y] is window.WorldXY, if it exists
window.mapfuncs = new Array(9);
// For each [i][j], if window.WorldIJ exists, it's used
// Otherwise it will be queried via AJAX later
for(var i = 1, j; i <= 9; ++i) {
mapfunc = mapfuncs[i] = [0,0,0,0,0];
for(j = mapfunc.length; j >= 0; --j)
mapfunc[j] = window["World" + i + "" + j];
}
// Random maps are all window functions
mapfuncs["Random"] = {
Overworld: WorldRandomOverworld,
Underworld: WorldRandomUnderworld,
Underwater: WorldRandomUnderwater,
Bridge: WorldRandomBridge,
Sky: WorldRandomSky,
Castle: WorldRandomCastle
};
// Right now there aren't too many special maps
mapfuncs["Special"] = {
Blank: BlankMap
}
// Maps not found, and sounds, are loaded via AJAX
startLoadingMaps();
}
// A new map, which contains general settings for the game run
function Map() {
this.underwater = this.current_character = this.current_solid = this.current_scenery = this.xloc = 0;
this.canscroll = true;
this.floor = 104;
this.time = 400; // optionally specified later
this.curloc = -1;
this.gravity = gravity;
this.maxyvel = unitsize * 1.75;
this.maxyvelinv = this.maxyvel * -2.1;
}
// An Area within a map, which contains the PreThings
function Area(setting, rawfunc) {
this.creation = rawfunc || function() {};
this.precharacters = [];
this.presolids = [];
this.prescenery = [];
this.floor = 140;
this.width = 0;
this.underwater = false;
setAreaSetting(this, setting || "");
}
function setAreaSetting(area, setting, sound) {
map.shifting = true;
if(arguments.length == 1) {
setting = arguments[0] || "Overworld";
area = map.area;
}
area.setting = area.background = setting;
area.theme = setting.split(" ")[0];
area.fillStyle = getAreaFillStyle(area.setting);
// Water fixen
if(area.fillStyle.indexOf("Underwater") != -1) goUnderWater();
else goOntoLand();
if(sound) AudioPlayer.playTheme();
if(gameon) clearAllSprites();
map.shifting = false;
}
// A location within an Area
// Specifies the entry function and xloc if needed
function Location(area, entry, xloc) {
this.area = area;
this.xloc = xloc || 0;
this.yloc = this.floor = 0;
// If entry is true, use entryPlain (beginning of level).
// If it's valid, use it.
// Otherwise, use entryNormal (drop from top)
this.entry = ((entry == true) ? entryPlain : (entry || entryNormal));
}
// A holder for a thing to be placed in a Location
// Stores the coordinates, constructor, and any other arguments
function PreThing(xloc, yloc, type) {
this.xloc = xloc;
this.yloc = yloc;
this.type = type;
// Pass any arguments after type into the Thing
var args = arrayMake(arguments),
// Blank Things are just basically {}, just with the name Thing in devtools :)
object = new Thing();
args[2] = type;
args = args.splice(2); // args is now [type, arg1, arg2...]
Thing.apply(object, args);
this.object = object;
}
/* Map Setting */
// Resets the board and starts
function setMap(one, two) {
if(!gameon) return;
// Unless it's ok to, kill the editor
if(!window.canedit && window.editing) editorClose(true);
// Remove random stuff
removeRandomDisplays();
// If arguments[0] is an array, it's [one, two]
if(one instanceof Array) {
two = one[1];
one = one[0];
}
var newcurrentmap = one ? [one, two] : window.currentmap,
newmap = new Map(),
func = mapfuncs[newcurrentmap[0]];
// Create the new map using the mapfunc, making sure it's loaded
if(!func) {
log("No such map section exists (yet?):", func);
return;
}
newcurrentmap.func = func = func[newcurrentmap[1]];
if(!func) {
log("No such map exists (yet?):", func);
return;
}
// Since the func exists, set and use it
window.map = newmap;
window.currentmap = newcurrentmap;
func(newmap);
// Set the map variables back to 0
newmap.areanum = newmap.curloc =/* window.playediting =*/ 0;
window.area = newmap.area = newmap.areas[0];
// Save the score if need be
if(window.player && player.power) storePlayerStats();
if(window.data) data.scoreold = data.score.amount;
// Actual resetting is done in shiftToLocation
shiftToLocation(0);
}
// For ease of transfer
// Random map pipe transports are ["Random", "XXXworld", LocationType]
// LocationType is either 1 (down) or -1 (up)
// Down means Player is moving down; Up means Player is moving up.
function setMapRandom(transport) {
if(!gameon) return;
resetSeed();
// Determine how to get into the map
if(typeof(transport) == "string") transport = ["Random", transport];
else if(!transport) transport = ["Random", "Overworld"];
// Actually set the map and shift to the location
setMap(transport[0], transport[1]);
// Record random-specific stuff
data.traveledold = data.traveled;
map.sincechange = map.num_random_sections = 0;
map.entrancetype = transport[2];
map.random = true;
if(map.randname == "Sky") map.exitloc = ["Random", "Overworld", "Down"];
}
/* Map Traversal */
function shiftToLocation(loc) {
// Make sure this is the right function
if(map.random && typeof(loc) != "number") {
return setMapRandom(loc);
}
if(typeof(loc) == "number")
loc = map.locs[loc];
// Reset everything game-related
pause();
resetGameState();
resetGameScreenPosition();
resetQuadrants();
// Set this location's area as current
map.areanum = loc.area;
window.area = map.area = map.areas[map.areanum];
// Clear everything, create the map, then set post-creation settings
setAreaPreCreation(area);
area.creation();
setAreaPostCreation(area);
// Start off by spawning, then placing Player
spawnMap();
player = placePlayer();
scrollPlayer(loc.xloc * unitsize);
locMovePreparations(player);
// Note that some locs will pause manually after this
unpause();
// Typically this will do nothing or be from a pipe
loc.entry(player, loc.entrything);
// Don't forget the least annoying part of programming this!
TimeHandler.addEvent(AudioPlayer.playTheme, 2);
// Texts are bound-check checked periodically for peformance reasons
TimeHandler.addEventInterval(checkTexts, 117, Infinity);
}
// To do: add in other stuff
function setAreaPreCreation(area) {
// Clear the containers
window.events = [];
TimeHandler.clearAllEvents();
window.characters = [];
window.solids = [];
window.scenery = [];
clearTexts();
area.precharacters = [];
area.presolids = [];
area.prescenery = [];
// Reset the spawn & scroll settings
map.current_solid = map.current_character = map.current_scenery = map.shifting = 0;
map.canscroll = true;
data.time.amount = map.time;
data.world.amount = currentmap[0] + "-" + currentmap[1];
setDataDisplay();
startDataTime();
if(map.random) {
data.world.amount = "Random Map";
data.world.element.innerHTML = "WORLD<br>Random Map";
}
}
function clearTexts() {
if(window.texts)
for(var i = texts.length - 1; i >= 0; --i)
if(texts[i])
removeChildSafe(texts[i], body);
window.texts = [];
}
function setAreaPostCreation() {
map.current_character = map.current_solid = map.current_scenery = 0;
area.width = max(area.width, gamescreen.width);
// Reset gravity and underwater
map.underwater = map.area.underwater;
map.jumpmod = 1.056 + 3.5 * map.underwater;
map.has_lakitu = false;
TimeHandler.addEvent(setMapGravity, 1);
// If it's underwater, give it the waves on top and player's bubble event
if(area.underwater) {
// Random maps have a block to stop player from swimming too high
area.presolids.push(new PreThing(0, 0, WaterBlock, area.width));
// Non-random maps also have a water sprite (randoms set it themselves)
if(!map.random) area.presolids.push(new PreThing(0, 16, Sprite, "Water", [area.width / 3, 1]));
}
// Sort everything using ascending order
area.presolids.sort(prethingsorter);
area.precharacters.sort(prethingsorter);
area.prescenery.sort(prethingsorter);
// If the area has loops (really just castles), do this.
if(area.sections && area.sections[0]) {
setBStretch();
area.sections.current = 0;
area.sections[0](area.sections.start);
}
// Otherwise, give it a ScrollBlocker at the area.width if it's not a random Sky
else if(!map.random && area.setting != "Sky") {
var blocker = new PreThing(area.width, 0, ScrollBlocker);
area.presolids.push(blocker);
}
// The fillstyle is the background color
area.fillStyle = getAreaFillStyle(area.setting);
}
// Given a setting, returns the background color
function getAreaFillStyle(setting) {
if(stringHas(setting, "Underworld") ||
stringHas(setting, "Castle") ||
stringHas(setting, "Night"))
return stringHas(setting, "Underwater") ? "#2038ec" : "black";
if(stringHas(setting, "Underwater")) return "#2038ec";
return "#5c94fc";
}
function prethingsorter(a,b) {
if(a.xloc == b.xloc) return b.yloc - a.yloc;
else return a.xloc - b.xloc;
};
// Moves generation to a specific location #
function setLocationGeneration(num) {
map.curloc = num;
map.refx = map.locs[map.curloc].xloc;
map.refy = map.locs[map.curloc].yloc + map.floor;
map.areanum = map.locs[map.curloc].area;
}
/* Gamplay Functions */
// Solids are spawned a little bit before characters
function spawnMap() {
var area = map.area,
rightdiff = QuadsKeeper.getOutDifference(),
screenright = gamescreen.right + rightdiff,
quadswidtht2 = QuadsKeeper.getQuadWidth() * 2 + rightdiff,
screenrightpq = screenright + quadswidtht2,
arr, arrlen, prething, thing, current;
// Spawn characters
arr = area.precharacters;
arrlen = arr.length;
current = map.current_character;
while(arrlen > current && screenright >= (prething = arr[current]).xloc * unitsize) {
thing = prething.object;
addThing(thing, prething.xloc * unitsize - gamescreen.left, prething.yloc * unitsize);
thing.placenum = current;
++current;
}
map.current_character = current;
// Spawn solids
arr = area.presolids;
arrlen = arr.length;
current = map.current_solid;
while(arrlen > current && screenrightpq >= (prething = arr[current]).xloc * unitsize) {
thing = prething.object;
addThing(thing, prething.xloc * unitsize - gamescreen.left, prething.yloc * unitsize);
thing.placenum = current;
++current;
}
map.current_solid = current;
// Spawn scenery
arr = area.prescenery;
arrlen = arr.length;
current = map.current_scenery;
while(arrlen > current && screenrightpq >= (prething = arr[current]).xloc * unitsize) {
thing = prething.object;
addThing(thing, prething.xloc * unitsize - gamescreen.left, prething.yloc * unitsize);
thing.placenum = current;
++current;
}
map.current_scenery = current;
}
// Entry Functions
function goToTransport(transport) {
// Goes to a new map
if(transport instanceof Array) {
map.ending = true;
storePlayerStats();
pause();
if(map.random) {
setMapRandom(transport);
// entryRandom(player);
}
else setMap(transport);
}
// Goes to a new Location
else shiftToLocation(map.locs[transport]);
}
function entryPlain(me) {
// pause();
setLeft(me, unitsizet16);
setBottom(me, map.floor * unitsize);
me.nocollide = me.piping = false;
me.placed = true;
// unpause();
}
function entryNormal(me) {
// pause();
setLeft(me, unitsizet16);
setTop(me, unitsizet16);
me.nocollide = me.piping = false;
me.placed = true;
// unpause();
}
function entryBlank(me) {
setLeft(me, unitsizet16);
setBottom(me, map.floor * unitsize);
me.nocollide = me.piping = me.movement = false;
me.placed = me.nofall = me.nocollide = notime = nokeys = true;
thingStoreVelocity(me);
clearDataDisplay();
}
function entryRandom(me) {
data.time.amount = 0;
data.time.dir = 1;
updateDataElement(data.time);
if(map.startwidth) {
if(!map.nofloor) pushPreFloor(0, 0, map.startwidth);
}
else map.startwidth = 0;
map.firstRandomThings(map);
map.randtype((map.startwidth + 1) * 8); //17 * 8
entryPlain(me);
addDistanceCounter();
addSeedDisplay();
// To do: remember to set the text & width of the curmap datadisplay
switch(map.entrancetype) {
case "Down":
entryNormal(player);
break;
case "Up":
// Use a pipe
locMovePreparations(player);
exitPipeVert(player, addThing(new Thing(Pipe, 32), unitsizet8, (map.floor - 32) * unitsize));
break;
case "Vine":
// Do that vine stuff
locMovePreparations(player);
TimeHandler.addEvent(function() { enterCloudWorld(player, true); }, 1);
player.nofall = true;
spawnMap();
break;
case "Castle":
startCastle(player);
break;
default:
// Only reached by Overworld the first time
// if(map.randname == "Overworld") addThing(new Thing(Sprite, "Castle", 1), unitsizet16 * -1, (map.floor - 88) * unitsize);
break;
}
}
function enterCloudWorld(me) {
// There are four cloud blocks to the left
// The vine goes up until it has four blocks above the clouds, then waits 2 seconds
// Player climbs up the left until two blocks from the top, then switches & jumps
// if(paused) unpause();
if(map.random) map.exitloc = getAfterSkyTransport();
var screenbottom = 140 * unitsize,
screentop = 72 * unitsize;
me.placed = me.nofall = true;
setTop(me, screenbottom);
setLeft(me, unitsize * 30);
removeClass(me, "jumping");
addClasses(me, ["climbing", "animated"]);
me.climbing = TimeHandler.addSpriteCycle(me, ["one", "two"], "climbing");
me.attached = new Thing(Vine, -1);
addThing(me.attached, unitsizet32, screenbottom - unitsizet8);
var movement = setInterval(function() {
// Vine moving up
if(me.attached.top <= screentop) {
clearInterval(movement);
setTop(me.attached, screentop, true);
me.attached.movement = false;
var stopheight = me.attached.top + unitsizet16;
movement = setInterval(function() {
// Player moving up
shiftVert(me, unitsized4 * -1, true);
if(me.top <= stopheight) {
// Player stops moving up
removeClass(me, "animated");
clearInterval(movement);
setTop(me, stopheight, true);
clearInterval(movement);
setTimeout(function() {
// Player switches sides
setLeft(me, unitsize * 36, true);
addClass(me, "flipped");
setTimeout(function() {
// Player hops off
playerHopsOff(me, me.attached, true);
TimeHandler.clearClassCycle(me, "climbing");
me.running = TimeHandler.addSpriteCycle(me, ["one", "two", "three", "two"], "running", setPlayerRunningCycler);
}, timer * 28);
}, timer * 14);
}
}, timer);
}
}, timer);
}
function walkToPipe() {
player = placePlayer();
startWalking(player);
map.canscroll = false;
var hasPipingStarted = false;
var move = setInterval(function() {
if(player.piping) {
// We have started piping
AudioPlayer.pauseTheme();
// nokeys = player.keys.run = notime = false;
clearInterval(move);
player.maxspeed = player.maxspeedsave;
}
}, timer);
unpause();
}
function startWalking(me) {
me.movement = movePlayer;
me.maxspeed = me.walkspeed;
nokeys = notime = me.keys.run = true;
me.nofall = me.nocollide = false;
}
function intoPipeVert(me, pipe, transport) {
if(!pipe.transport || !me.resting ||
me.right + unitsizet2 > pipe.right ||
me.left - unitsizet2 < pipe.left) return;
pipePreparations(me);
switchContainers(me, characters, scenery);
unpause();
var move = setInterval(function() {
shiftVert(me, unitsized4, true);
if(me.top >= pipe.top) {
clearInterval(move);
setTimeout(function() { goToTransport(transport); }, 700);
}
}, timer);
}
function intoPipeHoriz(me, pipe, transport) {
// If Player isn't resting or swimming, he shouldn't be allowed to pipe
// (resting may have been cleared at this point, so yvel is how it checks)
// if(abs(me.yvel) > unitsized8 || !map.underwater) return;
pipePreparations(me);
switchContainers(me, characters, scenery);
unpause();
var move = setInterval(function() {
shiftHoriz(me, unitsized4, true);
if(me.left >= pipe.left) {
clearInterval(move);
setTimeout(function() { goToTransport(transport); }, 700);
}
}, timer);
}
function pipePreparations(me) {
AudioPlayer.pauseTheme();
AudioPlayer.play("Pipe");
locMovePreparations(me);
me.nofall = me.nocollide = nokeys = notime = true;
me.movement = me.xvel = me.yvel = 0;
}
function locMovePreparations(me) {
// pause();
me.keys = new Keys();
me.nocollide = me.piping = 1;
me.placed = false;
removeCrouch();
removeClass(me, "running");
removeClass(me, "jumping");
removeClass(me, "flipped");
}
function startCastle(me) {
me = me || window.player;
if(!me) return;
setBottom(me, unitsize * 56);
setLeft(me, unitsizet2);
me.nocollide = me.piping = false;
me.placed = true;
}
// Exit functions
function exitPipeVert(me, pipe) {
switchContainers(me, characters, scenery);
me.nofall = nokeys = notime = true;
AudioPlayer.play("Pipe");
setTop(me, pipe.top);
setMidXObj(me, pipe, true);
var dy = unitsize / -4, move = setInterval(function() {
shiftVert(me, dy, true);
if(me.bottom <= pipe.top) {
switchContainers(me, scenery, characters);
clearInterval(move);
me.nocollide = me.piping = me.nofall = nokeys = notime = false;
me.placed = true;
}
}, timer);
}
function endLevel() {
if(map.ending) return;
map.ending = true;
map.random ? setMapRandom(["Random", "Castle"]) : setNextLevelArr(currentmap);
storePlayerStats();
pause();
setMap();
}
function setExitLoc(num) {
map.exitloc = num;
}
/* Shortcut Functions */
// Most of which call pushPre---
function pushPreThing(type, xloc, yloc, extras, more) {
var prething = new PreThing(map.refx + xloc, map.refy - yloc, type, extras, more),
object = prething.object;
// Stretch the area's width if it's a solid or character
if((object.solid || object.character) && !object.nostretch)
map.area.width = max(map.area.width, prething.xloc + object.width);
// Otherwise put it in solids or chars (scenery has its own pushPre*)
if(object.solid && !object.spawn_as_char) map.area.presolids.push(prething);
else map.area.precharacters.push(prething);
return prething;
}
function pushPreScenery(name, xloc, yloc, repx, repy) {
repx = round(repx || 1); repy = round(repy || 1);
var prething = new PreThing(map.refx + xloc, map.refy - yloc, Sprite, name, [repx, repy]);
prething.yloc -= prething.object.height;
map.area.prescenery.push(prething);
return prething;
}
function pushPreScenerySolid(name, xloc, yloc, repx, repy) {
repx = repx || 1; repy = repy || 1;
var prething = new PreThing(map.refx + xloc, map.refy - yloc, Sprite, name, [repx, repy]);
prething.yloc -= prething.object.height;
map.area.presolids.push(prething);
return prething;
}
function pushPreText(settings, xloc, yloc) {
var prething = new PreThing(map.refx + xloc, map.refy - yloc, FuncSpawner, spawnText, settings);
map.area.presolids.push(prething);
return prething;
}
function fillPreThing(type, xloc, yloc, numx, numy, width, height, extras, more) {
var x = xloc, y;
for(var i = 0, j; i < numx; ++i) {
y = yloc;
for(j = 0; j < numy; ++j) {
pushPreThing(type, x, y, extras, more);
y += height;
}
x += width;
}
}
function pushPreFloor(xloc, yloc, length) {
pushPreThing(Floor, xloc, yloc || 0, length || 1, DtB(yloc, 8));
}
function makeCeiling(xloc, num) {
num = num || 1;
for(var i=0; i<num; ++i)
pushPreThing(Brick, xloc + i * 8, ceillev);
}
function makeCeilingCastle(xloc, bwidth, bheight) {
pushPreThing(Stone, xloc, ceillev, bwidth || 1, bheight || 1);
}
function pushPreBridge(xloc, yloc, length, sides) {
pushPreScenery("Railing", xloc, yloc, length * 2);
pushPreThing(BridgeBase, xloc, yloc, length);
if(sides instanceof Array) {
if(sides[0]) pushPreThing(Stone, xloc - 8, yloc, 1, 64);
if(sides[1]) pushPreThing(Stone, xloc + length * 8, yloc, 1, 64);
}
}
function fillPreWater(xloc, yloc, width) {
// Water is 3 x 5.5
var dtb = DtB(yloc),
numy = ceil(dtb / 5.5),
dtby = numy * 5;
pushPreScenery("Water", xloc, yloc - 5.5, width * 4 / 3);
pushPreScenery("WaterFill", xloc, yloc - dtby - 15.5, width * 4 / 3, numy + 2);
}
function pushPrePlatformGenerator(xloc, width, dir) {
pushPreThing(PlatformGenerator, xloc, ceilmax + 16, width, dir);
}
// settings = [platwidth, offy1, offy2] (offy is distance from top to platform)
function pushPreScale(xloc, yloc, width, settings) {
var platwidth = settings[0],
offx = platwidth * 2,
offy1 = settings[1] + 1.5,
offy2 = settings[2] + 1.5,
me = pushPreThing(Scale, xloc, yloc, width).object;
// Set the platforms
platleft = pushPreThing(Platform, xloc - offx, yloc - offy1 * 4, platwidth, moveFallingScale).object;
platright = pushPreThing(Platform, xloc + width * 4 - platwidth - 6, yloc - offy2 * 4, platwidth, moveFallingScale).object;
platleft.parent = me; platright.parent = me;
platleft.partner = platright; platright.partner = platleft;
platleft.tension = offy1 * unitsizet4 - unitsize * 10;
platright.tension = offy2 * unitsizet4 - unitsize * 10;
// Set the tension
me.tensionleft = offy1 * unitsize;
me.tensionright = offy2 * unitsize;
// Add the strings
platleft.string = pushPreScenery("String", xloc, yloc - offy1 * 4, 1, (offy1 - .5) * 4).object;
platright.string = pushPreScenery("String", xloc + width * 4 - 1, yloc - offy2 * 4, 1, (offy2 - .5) * 4).object;
}
// worlds gives the pipe [X,Y]
// offset is how far between scrollblocker and main area (8 before first pipe)
// block is whether the screen should be blocked from scrolling to this
function pushPreWarpWorld(xloc, yloc, worlds, offset, block) {
if(worlds.length == 1) worlds = [-1, worlds[0], -1];
var startx = (offset || 0) + xloc + 10,
len = worlds.length,
pipe, i;
warp = pushPreThing(WarpWorld, xloc, yloc + ceilmax).object;
var title = pushPreText({innerText: "WELCOME TO WARP ZONE!", style: {visibility: "hidden"} }, startx, 58);
warp.texts.push(title.object);
for(i = 0; i < len; ++i) {
if(worlds[i] != -1) {
warp.pipes.push(pipe = pushPrePipe(startx, yloc, 24, true, worlds[i]).object);
warp.pirhanas.push(pipe.pirhana);
if(worlds[i] instanceof Array)
warp.texts.push(pushPreText({innerText: worlds[i][0], style: {visibility: "hidden"}}, startx + 4, 38).object);
}
startx += 32;
}
if(block) {
window.block = pushPreThing(ScrollBlocker, xloc, ceilmax);
pushPreThing(ScrollBlocker, startx + 16, ceilmax);
}
}
// Can be called either in a map function or during gameplay
function goUnderWater() {
if(window.map) {
if(map.area) {
if(window.player && !map.shifting)
setAreaSetting(String(map.area.setting || "") + " Underwater");
map.area.underwater = true;
}
setMapGravity();
TimeHandler.clearEvent(map.bubbling);
map.bubbling = TimeHandler.addEventInterval(playerBubbles, 96, Infinity);
map.underwater = true;
}
}
function goOntoLand() {
if(map) {
if(map.area) {
if(window.player && !map.shifting)
setAreaSetting(map.area.setting.replace("Underwater", "") || "Overworld");
map.area.underwater = false;
}
setMapGravity();
TimeHandler.clearEvent(map.bubbling);
map.underwater = false;
}
}
function setMapGravity() {
if(window.player) {
if(map.underwater) player.gravity = gravity / 2.8;
else player.gravity = gravity;
}
}
function setBStretch() {
window.bstretch = gamescreen.width / 8 - 2;
}
/*
* Specific creation of often-used stuff
*/
// The detector has stuff stored in it, so the animation functions can use them
// Some worlds (8-3, for example) have an unusual distance from flag to castle
// To do: use typical FuncColliders instead of detectors
function endCastleOutside(xloc, yloc, castlevel, wall, dist) {
xloc = xloc || 0;
yloc = yloc || 0;
if(castlevel) castlevel = castlev;
dist = dist || 20;
var detect = pushPreThing(FlagDetector, xloc + 7, yloc + 108).object,
detect2 = pushPreThing(CastleDoorDetector, xloc + 60 + (castlev == 0) * 8, 8).object;
detect.flag = pushPreThing(Flag, xloc + .5, yloc + 79.5).object;
detect.stone = pushPreThing(Stone, xloc + 4, yloc + 8).object;
detect.top = pushPreThing(FlagTop, xloc + 6.5, 84).object;
detect.pole = pushPreThing(FlagPole, xloc + 8, 80).object;
// detect2.castle = pushPreScenery("Castle", xloc + dist, yloc + castlevel).object;
if(wall) pushPreScenery("CastleWall", xloc + dist + 72, yloc, wall);
if(castlevel == 0) shiftHoriz(detect2, unitsizet8);
pushPreCastle(xloc + dist + 16, yloc, castlevel);
}
function startCastleInside() {
pushPreThing(Stone, 0, 88, 5, 3);
pushPreThing(Stone, 0, 48, 3, DtB(48, 8));
pushPreThing(Stone, 24, 40, 1, DtB(40, 8));
pushPreThing(Stone, 32, 32, 1, DtB(32, 8));
}
function endCastleInside(xloc, last, hard) {
var collider = pushPreThing(FuncCollider, xloc + 104, 48, CastleAxeFalls, [16, 24]).object,
axe = collider.axe = pushPreThing(CastleAxe, xloc + 104, 40).object;
axe.bridge = pushPreThing(CastleBridge, xloc, 24, 13).object;
axe.chain = pushPreThing(CastleChain, xloc + 96.5, 32).object;
axe.bowser = pushPreThing(Bowser, xloc + 69, 42, hard).object;
pushPreThing(ScrollBlocker, xloc + 112, ceilmax); // 104 + 16
pushPreThing(Stone, xloc, 88, 32);
fillPreWater(xloc, 0, 26);
pushPreFloor(xloc + 104, 32, 3);
pushPreFloor(xloc + 104, 0, 19);
pushPreThing(Stone, xloc + 112, 80, 2, 3);
// Stop that scrolling... again
pushPreThing(ScrollBlocker, xloc + 256, ceilmax);
// Place the NPC
endCastleInsideFinal(xloc, last);
}
function endCastleInsideFinal(xloc, last) {
var stopper = pushPreFuncCollider(xloc + 180, collideCastleNPC).object,
style = { visibility: "hidden" },
text, i;
// Either put Peach...
if(last) {
pushPreThing(Peach, xloc + 194, 13).object;
text = stopper.text = [
pushPreText({innerHTML: "THANK YOU " + window.player.title.toUpperCase() + "!", style: style}, xloc + 160, 66).object,
pushPreText({innerHTML: "YOUR QUEST IS OVER.<BR>WE PRESENT YOU A NEW QUEST.", style: style}, xloc + 148, 50).object,
pushPreText({innerHTML: "PRESS BUTTON B<BR>TO SELECT A WORLD.", style: style}, xloc + 148, 26).object
];
}
// ...or that jerk Toad
else {
pushPreThing(Toad, xloc + 194, 12).object;
text = stopper.text = [
pushPreText({innerHTML: "THANK YOU " + window.player.title.toUpperCase() + "!", style: style}, xloc + 160, 66).object,
pushPreText({innerHTML: "BUT OUR PRINCESS IS IN<BR>ANOTHER CASTLE!", style: style}, xloc + 148, 50).object
];
}
}
function pushPreSectionPass(xloc, yloc, width, height, secnum) {
var passer = pushPreThing(Collider, xloc, yloc, [width, height], [sectionPass, sectionColliderInit]).object,
secnum = map.area.sections.current || 0,
section = map.area.sections[secnum];
if(section.numpass) ++section.numpass;
else section.numpass = 1;
if(!section.colliders) section.colliders = [passer];
else section.colliders.push(passer);
}
function pushPreSectionFail(xloc, yloc, width, height, secnum) {
var failer = pushPreThing(Collider, xloc, yloc, [width, height], [sectionFail, sectionColliderInit]).object,
secnum = map.area.sections.current || 0,
section = map.area.sections[secnum];
if(!section.colliders) section.colliders = [failer];
else section.colliders.push(failer);
}
function pushCastleDecider(xloc, secnum) {
pushPreThing(castleDecider, xloc, ceilmax, xloc, secnum);
}
function sectionColliderInit(me) {
me.sections = map.area.sections;
me.parent = me.sections[me.sections.current];
me.movement = false;
}
function sectionPass(character, collider) {
if(character.type != "player") return false;
collider.nocollide = true;
var parent = collider.parent;
if(--parent.numpass) return;
activateSection(collider.parent, true);
}
function sectionFail(character, collider) {
if(character.type != "player") return false;
collider.nocollide = true;
activateSection(collider.parent, false);
}
function activateSection(parent, status) {
var colliders = parent.colliders;
for(var i=colliders.length-1; i>=0; --i)
killNormal(colliders[i]);
parent.activated = true;
parent.passed = status;
}
function pushPreTree(xloc, yloc, width) {
pushPreThing(TreeTop, xloc, yloc, width);
// Although the tree trunks in later trees overlap earlier ones, it's ok because
// the pattern is indistinguishible when placed correctly.
var dtb = DtB(yloc);
pushPreScenerySolid("TreeTrunk", xloc + 8, yloc - dtb - 8, width - 2 , dtb / 8);
}
function pushPreShroom(xloc, yloc, width) {
pushPreThing(ShroomTop, xloc, yloc, width);
var dtb = DtB(yloc - 4);
pushPreScenery("ShroomTrunk", xloc + width * 4 - 4, yloc - dtb - 8, 1, dtb / 8);
}
function pushPrePipe(xloc, yloc, height, pirhana, intoloc, exitloc) {
if(!isFinite(height)) {
height = gamescreen.height;
yloc -= gamescreen.height;
}
var prepipe = pushPreThing(Pipe, xloc, yloc + height, height / 8, intoloc),
pipe = prepipe.object/*,
vert = pushPreThing(PipeVertical, xloc, yloc + height - 8, height - 8)*/;
if(pirhana) pipe.pirhana = pushPreThing(Pirhana, xloc + 4, yloc + height + 12).object;
if(exitloc) {
map.locs[exitloc].entrything = pipe;
map.locs[exitloc].xloc = xloc;
}
return prepipe;
}
function pushPreCastle(xloc, yloc, big) {
xloc = xloc || 0;
yloc = yloc || 0;
if(big) pushPreCastleBig(xloc, yloc);
else pushPreCastleSmall(xloc, yloc);
}
// Note: off by 16 or so
function pushPreCastleBig(xloc, yloc) {
var i, j;
pushPreCastleSmall(xloc + 16, yloc + 48);
// Top alternate fillings
for(i = 0; i < 3; ++i)
for(j = 0; j < 2; ++j)
pushPreScenerySolid("BrickPlain", xloc + 16 + i * 16, yloc + 24 + j * 8);
// Top alternate doors
for(i = 0; i < 2; ++i)
pushPreScenerySolid("CastleDoor", xloc + 24 + i * 16, yloc + 24);
// Top half filling
for(i = 0; i < 5; ++i)
if(i == 2) continue;
else pushPreScenerySolid("BrickHalf", xloc + 16 + i * 8, yloc + 48);
// Left railings
for(i = 0; i < 2; ++i)
pushPreScenerySolid("CastleRailing", xloc + i * 8, yloc + 44);
// Middle railings
for(i = 0; i < 5; ++i)
pushPreScenerySolid("CastleRailingFilled", xloc + 16 + i * 8, yloc + 44);
// Right railings
for(i = 5; i < 7; ++i)
pushPreScenerySolid("CastleRailing", xloc + 16 + i * 8, yloc + 44);
// Bottom alternate fillings
for(i = 0; i < 2; ++i)
for(j = 0; j < 3; ++j)
pushPreScenerySolid("BrickPlain", xloc + 24 + i * 16, yloc + j * 8);
// Bottom alternate doors
for(i = 0; i < 3; ++i)
pushPreScenerySolid("CastleDoor", xloc + 16 + i * 16, yloc);
// Left fill
for(i = 0; i < 2; ++i) {
for(j = 0; j < 5; ++j)
pushPreScenerySolid("BrickPlain", xloc + i * 8, yloc + j * 8);
pushPreScenerySolid("BrickHalf", xloc + i * 8, yloc + 40);
}
// Right fill
for(i = 0; i < 2; ++i) {
for(j = 0; j < 5; ++j)
pushPreScenerySolid("BrickPlain", xloc + 56 + i * 8, yloc + j * 8);
pushPreScenerySolid("BrickHalf", xloc + 56 + i * 8, yloc + 40);
}
for(i = 0; i < 3; ++i)
for(j = 0; j < 2; ++j)
pushPreScenerySolid("BrickHalf", xloc + 16 + i * 16, yloc + 20 + j * 20);
}
// To do: y u no work scenery
function pushPreCastleSmall(xloc, yloc) {
var i, j;