forked from JoshuaKGoldberg/Old-Deleted-FullScreenMario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
things.js
3012 lines (2825 loc) · 85.7 KB
/
things.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
/* Things.js */
// Stores Thing creators, functions, and manipulators
/* Typical Things */
// There is a lot of information stored in each of these.
// Variable amounts of arguments are passed to the constructor:
// * var mything = new Thing(ConstructionFunc[, arg1[, arg2[, ...]]]);
// * var mygoomb = new Thing(Goomba);
// * var mykoopa = new Thing(Koopa, true);
function Thing(type) {
// If there isn't a type, don't do anything
if(arguments.length == 0 || !type) return;
// Otherwise make this based off the type
// Make sure this is legally created
var self = this === window ? new Thing() : this,
args = self.args = arrayMake(arguments);
args[0] = self;
type.apply(self, args);
self.alive = true;
self.placed = this.outerok = 0;
self.xvel = this.xvel || 0;
self.yvel = this.yvel || 0;
if(self.tolx == null) self.tolx = 0;
if(self.toly == null) self.toly = unitsized8;
self.movement = self.movement; // why..?
self.collide = self.collide || function() {}; // To do: why does taking this out mess things up?
self.death = self.death || killNormal;
self.animate = self.animate || emergeUp;
if(self.width * unitsize < quads.width && self.height * unitsize < quads.height)
self.maxquads = 4; // self could be done with modular stuff... beh
else self.maxquads = quads.length;
self.quads = new Array(self.maxquads)
self.overlaps = [];
self.title = self.title || type.name;
self.spritewidth = self.spritewidth || self.width;
self.spriteheight = self.spriteheight || self.height;
self.sprite = "";
try { setContextStuff(self, self.spritewidth, self.spriteheight); }
catch(err) {
log("Thing context fail", err, self.title, self);
setTimeout(function() { setContextStuff(self, self.spritewidth, self.spriteheight); }, 1);
}
return self;
}
function setContextStuff(me, spritewidth, spriteheight) {
me.spritewidthpixels = me.spritewidth * unitsize;
me.spriteheightpixels = me.spriteheight * unitsize;
me.canvas = getCanvas(me.spritewidthpixels, me.spriteheightpixels);
me.context = me.canvas.getContext("2d");
me.imageData = me.context.getImageData(0, 0, me.spritewidthpixels, me.spriteheightpixels);
me.sprite_type = me.sprite_type || "neither";
canvasDisableSmoothing(me, me.context);
}
// A helper function to make a Thing given the type and arguments
function ThingCreate(type, args) {
var newthing = new Thing();
Thing.apply(newthing, [type].concat(args));
return newthing;
}
/* Thing Functions */
function setCharacter(me, type) {
me.type = type.split(" ")[0]; // so 'shell smart' becomes 'shell'
me.resting = me.under = me.undermid = false;
me.alive = me.character = true;
me.libtype = "characters";
setClassInitial(me, "character " + type);
}
function setSolid(me, name) {
me.type = "solid";
me.name = name;
me.solid = me.alive = true;
me.speed = me.speed || 0; // vertical speed
me.collide = me.collide || characterTouchedSolid;
me.bottomBump = me.bottomBump || function() { /*play("Bump.wav");*/ };
me.action = me.action || function() {};
me.jump = me.jump || function() {};
me.spritewidth = me.spritewidth || 8;
me.spriteheight = me.spriteheight || 8;
me.libtype = "solids";
setClassInitial(me, "solid " + name);
}
function setScenery(me, name) {
setSolid(me, name);
me.libtype = "scenery";
}
// The primary function for placing a thing on the map
function addThing(me, left, top) {
// If me is a function (e.g. 'addThing(Goomba, ...)), make a new thing with that
if(me instanceof Function) {
me = new Thing(me);
}
placeThing(me, left, top);
window[me.libtype].push(me);
me.placed = true;
determineThingQuadrants(me);
if(me.onadding) me.onadding(); // generally just for sprite cycles
setThingSprite(me);
window["last_" + (me.title || me.group || "unknown")] = me;
return me;
}
// Called by addThing for simple placement
function placeThing(me, left, top) {
setLeft(me, left);
setTop(me, top);
updateSize(me);
return me;
}
function addText(html, left, top) {
var element = createElement("div", {innerHTML: html, className: "text",
left: left,
top: top,
onclick: body.onclick || canvas.onclick,
style: {
marginLeft: left + "px",
marginTop: top + "px"
}});
body.appendChild(element);
texts.push(element);
return element;
}
// Called by funcSpawner placed by pushPreText
// Kills the text once it's too far away
function spawnText(me, settings) {
var element = me.element = addText("", me.left, me.top);
if(typeof(settings) == "object") proliferate(element, settings);
else element.innerHTML = settings;
me.movement = false;
}
// Set at the end of shiftToLocation
function checkTexts() {
var delx = quads.delx,
element, me, i;
for(i = texts.length - 1; i >= 0; --i) {
me = texts[i]
element = texts[i].element || me;
me.right = me.left + element.clientWidth
if(me.right < delx) {
body.removeChild(element);
killNormal(me);
deleteThing(element, texts, i);
}
}
}
// To do: make this use a variable number of arguments!
function pushPreThing(type, xloc, yloc, extras, more) {
var prething = new PreThing(map.refx + xloc, map.refy - yloc, type, extras, more);
if(prething.object.solid) {
map.area.width = max(map.area.width, prething.xloc + prething.object.width);
map.area.presolids.push(prething);
}
else map.area.precharacters.push(prething);
return prething;
}
/*
* Characters (except Mario, who has his own .js)
*/
/*
* Items
*/
function Mushroom(me, type) {
me.group = "item";
me.width = me.height = 8;
me.speed = .42 * unitsize;
me.animate = emergeUp;
me.movement = moveSimple;
me.collide = collideFriendly;
me.jump = mushroomJump;
me.death = killNormal;
var name = "mushroom";
switch(type) {
case 1: me.action = gainLife; name += " gainlife"; break;
case -1: me.action = killMario; name += " death"; break;
default: me.action = marioShroom; name += " regular"; break;
}
setCharacter(me, name);
}
function mushroomJump(me) {
me.yvel -= unitsize * 1.4;
me.top -= unitsize;
me.bottom -= unitsize;
updatePosition(me);
}
function FireFlower(me) {
me.group = "item";
me.width = me.height = 8;
me.animate = emergeUp;
me.collide = collideFriendly;
me.action = marioShroom;
me.nofall = me.nofire = true;
me.movement = false;
setCharacter(me, "fireflower");
addSpriteCycle(me, ["one", "two", "three", "four"]);
}
function FireBall(me, moveleft) {
me.group = "item";
me.width = me.height = 4;
me.speed = unitsize * 1.75;
me.gravity = gravity * 1.56;
me.jumpheight = unitsize * 1.56;
me.nofire = me.nostar = me.collide_primary = true;
me.moveleft = moveleft;
me.animate = emergeFire;
me.movement = moveJumping;
me.collide = fireEnemy;
me.death = fireExplodes;
setCharacter(me, "fireball");
addSpriteCycle(me, ["one", "two", "three", "four"], 4);
}
function fireEnemy(enemy, me) {
if(!me.alive || me.emerging || enemy.nofire || enemy.height <= unitsize) return;
playLocal("Kick.wav", me.right);
if(!enemy.solid) {
enemy.death(enemy, 2);
scoreEnemyFire(enemy);
}
me.death(me);
}
function fireDeleted() {
--mario.numballs;
}
function fireExplodes(me) {
var fire = new Thing(Firework);
addThing(fire, me.left - fire.width / 2, me.top - fire.height / 2);
fire.animate();
killNormal(me);
}
function Star(me) { // GOLDEEN GOLDEEN
me.group = "item";
me.width = 7;
me.height = 8;
me.speed = unitsize * .56;
me.jumpheight = unitsize * 1.17;
me.gravity = gravity / 2.8;
me.animate = emergeUp;
me.movement = moveJumping;
me.collide = collideFriendly;
me.action = marioStar;
me.death = killNormal;
setCharacter(me, "star item"); // Item class so mario's star isn't confused with this
addSpriteCycle(me, ["one", "two", "three", "four"], 0, 7);
}
function Shell(me, smart) {
me.width = 8; me.height = 7;
me.group = "item";
me.speed = unitsizet2;
me.collide_primary = true;
me.moveleft = me.xvel = me.move = me.hitcount = me.peeking = me.counting = me.landing = me.enemyhitcount = 0;
me.smart = smart;
me.movement = moveShell;
me.collide = hitShell;
me.death = killFlip;
me.spawntype = Koopa;
var name = "shell" + (smart ? " smart" : " dumb");
setCharacter(me, name);
}
function hitShell(one, two) {
// Assuming two is shell
if(one.type == "shell" && two.type != one.type) return hitShell(two, one);
switch(one.type) {
// Hitting a wall
case "solid":
if(two.right < one.right) {
playLocal("Bump.wav", one.left);
setRight(two, one.left);
two.xvel = -two.speed;
two.moveleft = true;
} else {
playLocal("Bump.wav", one.right);
setLeft(two, one.right);
two.xvel = two.speed;
two.moveleft = false;
}
break;
// Hitting Mario
case "mario":
var shelltoleft = objectToLeft(two, one),
mariojump = one.yvel > 0 && one.bottom <= two.top + unitsizet2;
// Star Mario is pretty easy
if(one.star) {
scoreMarioShell(one, two);
return two.death(two, 2);
}
// If the shell is already being landed on by Mario:
if(two.landing) {
// If the recorded landing direction hasn't changed:
if(two.shelltoleft == shelltoleft) {
// Increase the landing count, and don't do anything.
++two.landing;
// If it's now a count of 1, score the shell
if(two.landing == 1) scoreMarioShell(one, two);
// Reduce that count very soon
addEvent(function(two) { --two.landing; }, 2, two);
}
// Otherwise, the shell has reversed direction during land. Mario should die.
else {
// This prevents accidentally scoring Mario's hit
mario.death(mario);
}
return;
}
// Mario is kicking the shell (either hitting a still shell or jumping onto a shell)
if(two.xvel == 0 || mariojump) {
// Mario has has hit the shell in a dominant matter. You go, Mario!
two.counting = 0;
scoreMarioShell(one, two);
// The shell is peeking
if(two.peeking) {
two.peeking = false;
removeClass(two, "peeking");
two.height -= unitsized8;
updateSize(two);
}
// If the shell's xvel is 0 (standing still)
if(two.xvel == 0) {
if(shelltoleft) {
two.moveleft = true;
two.xvel = -two.speed;
} else {
two.moveleft = false;
two.xvel = two.speed;
}
// Make sure to know not to kill Mario too soon
++two.hitcount;
addEvent(function(two) { --two.hitcount; }, 2, two);
}
// Otherwise set the xvel to 0
else two.xvel = 0;
// Mario is landing on the shell (movements, xvels already set)
if(mariojump) {
play("Kick.wav");
// The shell is moving
if(!two.xvel) {
jumpEnemy(one, two);
one.yvel *= 2;
scoreMarioShell(one, two);
setBottom(one, two.top - unitsize, true);
}
// The shell isn't moving
else {
// shelltoleft ? setRight(two, one.left) : setLeft(two, one.right);
scoreMarioShell(one, two);
}
++two.landing;
two.shelltoleft = shelltoleft;
addEvent(function(two) { --two.landing; }, 2, two);
}
}
else {
// Since the shell is moving and Mario isn't, if the xvel is towards Mario, that's a death
if(!two.hitcount && ((shelltoleft && two.xvel < 0) || (!shelltoleft && two.xvel > 0)))
one.death(one);
}
break;
// Shell hitting another shell
case "shell":
// If one is moving...
if(one.xvel != 0) {
// and two is also moving, knock off each other
if(two.xvel != 0) {
var temp = one.xvel;
shiftHoriz(one, one.xvel = two.xvel);
shiftHoriz(two, two.xvel = temp);
}
// otherwise one kills two
else {
score(two, 500);
two.death(two);
}
}
// otherwise two kills one
else if(two.xvel != 0) {
score(one, 500);
one.death(one);
}
break;
default:
switch(one.group) {
case "enemy":
if(two.xvel) {
// If the shell is moving, kill the enemy
if(one.type.split(" ")[0] == "koopa") {
// If the enemy is a koopa, make it a shell
// To do: automate this for things with shells (koopas, beetles)
var spawn = new Thing(Shell, one.smart);
addThing(spawn, one.left, one.bottom - spawn.height * unitsize);
killFlip(spawn);
killNormal(one);
} // Otherwise just kill it normally
else killFlip(one);
play("Kick.wav");
score(one, findScore(two.enemyhitcount), true);
++two.enemyhitcount;
} // Otherwise the enemy just turns around
else one.moveleft = objectToLeft(one, two);
break;
case "item":
if(one.type == "shell") {
if(two.xvel) killFlip(one);
if(one.xvel) killFlip(two);
}
else return;
break;
}
break;
}
}
function moveShell(me) {
if(me.xvel != 0) return;
if(++me.counting == 350) {
addClass(me, "peeking");
me.peeking = true;
me.height += unitsized8;
updateSize(me);
} else if(me.counting == 490) {
var spawn = new Thing(me.spawntype, me.smart);
addThing(spawn, me.left, me.bottom - spawn.height * unitsize);
killNormal(me);
}
}
// Assuming one is Mario, two is item
function collideFriendly(one, two) {
if(one.type != "mario") return;
if(two.action) two.action(one);
two.death(two);
}
/*
* Enemies
*/
function jumpEnemy(me, enemy) {
if(me.keys.up) me.yvel = unitsize * -1.4;
else me.yvel = unitsize * -.7;
me.xvel *= .91;
play("Kick.wav");
if(enemy.group != "item" || enemy.type == "shell")
score(enemy, findScore(me.jumpcount++ + me.jumpers), true);
++me.jumpers;
addEvent(function(me) { --me.jumpers; }, 1, me);
}
function Goomba(me) {
me.width = me.height = 8;
me.speed = unitsize * .21;
me.toly = unitsize;
me.moveleft = me.noflip = true;
me.smart = false;
me.group = "enemy";
me.movement = moveSimple;
me.collide = collideEnemy;
me.death = killGoomba;
setCharacter(me, "goomba");
addSpriteCycleSynched(me, [unflipHoriz, flipHoriz]);
}
// Big: true if it should skip squash (fire, shell, etc)
function killGoomba(me, big) {
if(!me.alive) return;
if(!big) {
var squash = new Thing(DeadGoomba);
addThing(squash, me.left, me.bottom - squash.height * unitsize);
addEvent(killNormal, 21, squash);
killNormal(me);
}
else killFlip(me);
}
function DeadGoomba(me) {
me.width = 8;
me.height = 4;
me.movement = false;
me.nocollide = me.nocollide = true;
me.death = killNormal;
setSolid(me, "deadGoomba");
}
// If fly == true, then it's jumping
// If fly is otherwise true (an array), it's floating
function Koopa(me, smart, fly) {
me.width = 8;
me.height = 12;
me.speed = me.xvel = unitsize * .21;
me.moveleft = me.skipoverlaps = true;
me.group = "enemy";
me.smart = smart; // will it run off the edge
var name = "koopa";
name += (me.smart ? " smart" : " dumb");
if(me.smart) name+= " smart";
if(fly) {
name += " flying";
me.winged = true;
if(fly == true) {
me.movement = moveJumping;
me.jumpheight = unitsize * 1.17;
me.gravity = gravity / 2.8;
}
else {
me.movement = moveFloating;
me.ytop = me.begin = fly[0] * unitsize;
me.ybot = me.end = fly[1] * unitsize;
me.nofall = me.fly = true;
me.changing = me.xvel = 0;
me.yvel = me.maxvel = unitsized4;
}
}
else {
name += " regular";
if(me.smart) me.movement = moveSmart;
else me.movement = moveSimple;
}
me.collide = collideEnemy;
me.death = killKoopa;
setCharacter(me, name);
addSpriteCycleSynched(me, ["one", "two"]);
me.toly = unitsizet2;
}
// Big: true if it should skip shell (fire, shell, etc)
function killKoopa(me, big) {
if(!me.alive) return;
var spawn;
if((big && big != 2) || me.winged) spawn = new Thing(Koopa, me.smart);
else spawn = new Thing(Shell, me.smart);
// Puts it on stack, so it executes immediately after upkeep
addEvent(
function(spawn, me) {
addThing(spawn, me.left, me.bottom - spawn.height * unitsize);
spawn.moveleft = me.moveleft;
},
0,
spawn, me
);
killNormal(me);
if(big == 2) killFlip(spawn);
else return spawn;
}
function Pirhana(me, evil) {
me.width = 8;
me.height = 12;
me.counter = 0;
me.countermax = me.height * unitsize;
me.dir = unitsized8;
me.toly = unitsizet8;
me.nofall = me.deadly = me.nocollidesolid = me.repeat = true;
me.group = "enemy";
me.collide = collideEnemy;
me.death = killNormal;
me.movement = movePirhanaInit;
me.death = killPirhana;
setCharacter(me, "pirhana");
}
// The visual representation of a pirhana is visual_scenery; the collider is a character
function movePirhanaInit(me) {
me.hidden = true;
var scenery = me.visual_scenery = new Thing(Sprite, "Pirhana");
addThing(scenery, me.left, me.top);
addSpriteCycle(scenery, ["one", "two"]);
me.movement = movePirhanaNew;
// Pirhanas start out minimal
movePirhanaNew(me, me.height * unitsize);
}
// Moving a pirhana moves both it and its scenery
function movePirhanaNew(me, amount) {
amount = amount || me.dir;
me.counter += amount;
shiftVert(me, amount);
shiftVert(me.visual_scenery, amount);
// Height is 0
if(me.counter <= 0 || me.counter >= me.countermax) {
me.movement = false;
me.dir *= -1;
addEvent(movePirhanaRestart, 35, me);
}
}
function movePirhanaRestart(me) {
var marmid = getMidX(mario);
// If Mario's too close and counter == 0, don't do anything
if(me.counter >= me.countermax && marmid > me.left - unitsizet8 && marmid < me.right + unitsizet8) {
setTimeout(movePirhanaRestart, 7, me);
return;
}
// Otherwise start again
me.movement = movePirhanaNew;
}
function killPirhana(me) {
if(!me && !(me = this)) return;
killNormal(me);
killNormal(me.visual_scenery);
}
// Really just checks toly for pirhanas.
function marioAboveEnemy(mario, enemy) {
if(mario.bottom < enemy.top + enemy.toly) return true;
return false;
}
// Assuming one should generally be Mario/thing, two is enemy
function collideEnemy(one, two) {
// Check for life
if(!characterIsAlive(one) || !characterIsAlive(two)) return;
// Check for nocollidechar
if((one.nocollidechar && !two.mario) || (two.nocollidechar && !one.mario)) return;
// Items
if(one.group == "item") {
if(one.collide_primary) return one.collide(two, one);
// if(two.height < unitsized16 || two.width < unitsized16) return;
return;
}
// Mario on top of enemy
if(!map.underwater && one.mario && ((one.star && !two.nostar) || (!two.deadly && objectOnTop(one, two)))) {
// Enforces toly
if(marioAboveEnemy(one, two)) return;
// Mario is on top of them (or star):
if(one.mario && !one.star) addEvent(function(one, two) { jumpEnemy(one, two); }, 0, one, two);
else two.nocollide = true;
// Kill the enemy
//// If killed returns a Thing, then it's a shell
//// Make sure Mario isn't immediately hitting the shell
var killed = two.death(two, one.star * 2);
if(one.star) scoreEnemyStar(two);
else {
scoreEnemyStomp(two);
/*addEvent(function(one, two) { */setBottom(one, min(one.bottom, two.top + unitsize));/* }, 0, one, two);*/
}
// Make Mario have the hopping thing
addClass(one, "hopping");
removeClasses(one, "running skidding jumping one two three")
// addClass(one, "running three");
one.hopping = true;
if(mario.power == 1) setMarioSizeSmall(one);
}
// Mario getting hit by an enemy
else if(one.mario) {
if(!marioAboveEnemy(one, two)) one.death(one);
}
// Two regular characters colliding
else two.moveleft = !(one.moveleft = objectToLeft(one, two));
}
function Podoboo(me, jumpheight) {
me.width = 7;
me.height = 8;
me.deadly = me.nofall = me.nocollidesolid = me.nofire = true;
me.gravity = map.gravity / 2.1;
me.jumpheight = (jumpheight || 64) * unitsize;
me.speed = -map.maxyvel;
me.movement = movePodobooInit;
me.collide = collideEnemy;
me.betweentime = 70;
setCharacter(me, "podoboo");
}
function movePodobooInit(me) {
if(!characterIsAlive(me)) return;
// For the sake of the editor, flip this & make it hidden on the first movement
// flipVert(me);
me.hidden = true;
me.heightnorm = me.top;
me.heightfall = me.top - me.jumpheight;
addEvent(podobooJump, me.betweentime, me);
me.movement = false;
}
function podobooJump(me) {
if(!characterIsAlive(me)) return;
unflipVert(me);
me.yvel = me.speed + me.gravity;
me.movement = movePodobooUp;
me.hidden = false;
// Sadly, this appears to be occasionally necessary
setThingSprite(me);
}
function movePodobooUp(me) {
shiftVert(me, me.speed, true);
if(me.top - gamescreen.top > me.heightfall) return;
me.nofall = false;
me.movement = movePodobooSwitch;
}
function movePodobooSwitch(me) {
if(me.yvel <= 0) return;
flipVert(me);
me.movement = movePodobooDown;
}
function movePodobooDown(me) {
if(me.top < me.heightnorm) return;
setTop(me, me.heightnorm, true);
me.movement = false;
me.nofall = me.hidden = true;
me.heightfall = me.top - me.jumpheight;
addEvent(podobooJump, me.betweentime, me);
}
function HammerBro(me) {
me.width = 8;
me.height = 12;
me.group = "enemy";
me.collide = collideEnemy;
me.statex = me.counter = me.statey = me.counterx = me.countery = me.level = me.throwcount = 0;
me.death = killFlip;
me.movement = moveHammerBro;
setCharacter(me, "hammerbro");
me.gravity = gravity / 2;
addSpriteCycle(me, ["one", "two"]);
addEvent(throwHammer, 35, me, 7);
addEventInterval(jumpHammerBro, 140, Infinity, me);
}
function moveHammerBro(me) {
// Slide side to side
me.xvel = Math.sin(Math.PI * (me.counter += .007)) / 2.1;
// Make him turn to look at mario if needed
lookTowardMario(me);
// If falling, don't collide with solids
me.nocollidesolid = me.yvel < 0 || me.falling;
}
function throwHammer(me, count) {
if(!characterIsAlive(me) || me.right < -unitsizet32) return;
if(count != 3) {
switchClass(me, "thrown", "throwing");
}
addEvent(function(me) {
if(count != 3) {
if(!characterIsAlive(me)) return;
// Throw the hammer...
switchClass(me, "throwing", "thrown");
// var hammer = new Thing(Hammer, me.lookleft);
addThing(new Thing(Hammer, me.lookleft), me.left - unitsizet2, me.top - unitsizet2);
// ...and go again
}
if(count > 0) addEvent(throwHammer, 7, me, --count);
else {
addEvent(throwHammer, 70, me, 7);
removeClass(me, "thrown");
}
}, 14, me);
}
function jumpHammerBro(me) {
if(!characterIsAlive(me)) return true; // finish
if(!me.resting) return; // just skip
// If it's ok, jump down
if(map.floor - (me.bottom / unitsize) >= jumplev1 - 2 && me.resting.name != "floor" && Math.floor(Math.random() * 2)) {
me.yvel = unitsize * -.7;
me.falling = true;
addEvent(function(me) { me.falling = false; }, 42, me);
}
// Otherwise, jump up
else me.yvel = unitsize * -2.1;
me.resting = false;
}
function Hammer(me, left) {
me.width = me.height = 8;
me.nocollidesolid = me.nocollidechar = me.deadly = me.nofire = true;
me.collide = collideEnemy;
me.yvel = -unitsize * 1.4;
me.xvel = unitsize / 1.4;
if(left) me.xvel *= -1;
me.gravity = gravity / 2.1;
setCharacter(me, "hammer");
addSpriteCycle(me, ["one", "two", "three", "four"], 3);
}
function Cannon(me, height, nofire) {
me.width = 8;
me.height = (height || 1) * 8;
me.spriteheight = 16;
if(!nofire) me.movement = moveCannonInit;
me.timer = 117;
me.repeat = true;
setSolid(me, "cannon");
}
function moveCannonInit(me) {
addEventInterval(
function(me) {
if(mario.right > me.left - unitsizet8 && mario.left < me.right + unitsizet8)
return; // don't fire if Mario is too close
var spawn = new Thing(BulletBill);
if(objectToLeft(mario, me)) {
addThing(spawn, me.left, me.top);
spawn.direction = spawn.moveleft = true;
spawn.xvel *= -1;
flipHoriz(spawn);
}
else addThing(spawn, me.left + me.width, me.top);
playLocal("Bump.wav", me.right);
}, 270, -1, me);
me.movement = false;
}
function BulletBill(me) {
me.width = 8; me.height = 7;
me.group = "enemy";
me.nofall = me.nofire = me.nocollidesolid = me.nocollidechar = true;
me.speed = me.xvel = unitsized2;
me.movement = moveSimple;
me.collide = collideEnemy;
me.death = killFlip;
setCharacter(me, "bulletbill");
}
function Bowser(me, hard) {
me.width = me.height = 16;
me.speed = .28 * unitsize;
me.gravity = gravity / 2.8;
me.deadly = me.dx = me.lookleft = me.nokillend = me.skipoverlaps = true;
me.moveleft = me.smart = me.movecount = me.jumpcount = me.firecount = me.deathcount = 0;
me.killonend = freezeBowser;
me.counter = -.7;
me.group = "enemy";
me.movement = moveBowserInit;
me.collide = collideEnemy;
me.death = killBowser;
setCharacter(me, "bowser");
addSpriteCycle(me, ["one", "two"]);
if(hard) addEvent(throwHammer, 35, me, 7);
}
function moveBowserInit(me) {
addEventInterval(bowserJumps, 117, Infinity, me);
addEventInterval(bowserFires, 280, Infinity, me);
addEventInterval(bowserFires, 350, Infinity, me);
addEventInterval(bowserFires, 490, Infinity, me);
me.movement = moveBowser;
}
function moveBowser(me) {
if(!characterIsAlive(mario)) return;
lookTowardMario(me);
if(me.lookleft) me.xvel = Math.sin(Math.PI * (me.counter += .007)) / 1.4;
else me.xvel = min(me.xvel + .07, .84);
}
function bowserJumps(me) {
if(!characterIsAlive(me)) return true;
if(!me.resting || !me.lookleft) return;
me.yvel = unitsize * -1.4;
me.resting = false;
// If there is a platform, don't bump into it
me.nocollidesolid = true;
addEventInterval(function(me) {
if(me.yvel > unitsize) {
me.nocollidesolid = false;
return true;
}
}, 3, Infinity, me);
}
function bowserFires(me) {
if(!characterIsAlive(me) || !characterIsAlive(mario)) return true;
if(!me.lookleft) return;
// Close the mouth
addClass(me, "firing");
playLocal("Bowser Fires.wav", me.left);
// After a little bit, open and fire
addEvent(function(me) {
var top = me.top + unitsizet4,
fire = new Thing(BowserFire, roundDigit(mario.bottom, unitsizet8));
removeClass(me, "firing");
addThing(fire, me.left - unitsizet8, top);
play("Bowser Fires.wav");
}, 14, me);
}
// This is for when Fiery Mario kills bowser - the normal one is listed under the castle things
function killBowser(me, big) {
if(big) {
me.nofall = false;
return killFlip(me);
}
if(++me.deathcount == 5) {
me.yvel = me.speed = me.movement = 0;
killFlip(me, 350);
score(me, 5000);
}
}
// For when the axe is hit
function freezeBowser(me) {
me.movement = false;
thingStoreVelocity(me);
}
// Each fireball leaves his mouth, and while moving horizontally, shifts its yloc
function BowserFire(me, ylev) {
me.width = 12;
me.height = 4;
me.xvel = unitsize * -.63;
me.deadly = me.nofall = me.nocollidesolid = me.nofire = true;
me.collide = collideEnemy;
if(ylev) {
me.ylev = ylev;
me.movement = moveFlying;
}
setCharacter(me, "bowserfire");
addSpriteCycle(me, [unflipVert, flipVert]);
}
function moveFlying(me) {
if(round(me.bottom) == round(me.ylev)) {
me.movement = false;
return;
}
shiftVert(me, min(max(0, me.ylev - me.bottom), unitsize));
}
function WaterBlock(me, width) {
me.height = 16;
me.width = width;
me.spritewidth = me.spriteheight = 1 / scale;
me.repeat = true;
setSolid(me, "water-block");
}
function Blooper(me) {
me.width = 8;
me.height = 12;
me.nocollidesolid = me.nofall = me.moveleft = 1;
me.squeeze = me.counter = 0;
me.speed = unitsized2;
me.xvel = me.speedinv = -unitsized4;
me.movement = moveBlooper;
me.collide = collideEnemy;
me.death = killFlip;
setCharacter(me, "blooper");
}
// Normally goes up at increasing rate
// Every X seconds, squeezes to go down
//// Minimum Y seconds, continues if Mario is below until bottom is 8 above floor
function moveBlooper(me) {
switch(me.counter) {
case 56: me.squeeze = true; ++me.counter; break;
case 63: squeezeBlooper(me); break;
default: ++me.counter; break;
}
if(me.squeeze) me.yvel = max(me.yvel + .021, .7); // going down
else me.yvel = min(me.yvel - .035, -.7); // going up
shiftVert(me, me.yvel, true);
if(!me.squeeze) {
if(mario.left > me.right + unitsizet8) {
// Go to the right
me.xvel = min(me.speed, me.xvel + unitsized32);
}
else if(mario.right < me.left - unitsizet8) {
// Go to the left
me.xvel = max(me.speedinv, me.xvel - unitsized32);
}
}
}
function squeezeBlooper(me) {
if(me.squeeze != 2) addClass(me, "squeeze");
// if(!me.squeeze) me.yvel = 0;
me.squeeze = 2;
me.xvel /= 1.17;
setHeight(me, 10, true, true);
// (104 (map.floor) - 12 (blooper.height) - 2) * unitsize
if(me.top > mario.bottom || me.bottom > 360) unsqueezeBlooper(me);
}
function unsqueezeBlooper(me) {
me.squeeze = false;
removeClass(me, "squeeze");
me.counter = 0;