forked from JoshuaKGoldberg/Old-Deleted-FullScreenMario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
triggers.js
183 lines (150 loc) · 4.42 KB
/
triggers.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
/* Triggers.js */
// Keeps track of triggers, which mainly consist of key presses
function resetTriggers() {
proliferate(body, {
onkeydown: keydown,
onkeyup: keyup,
oncontextmenu: contextmenu,
onmousedown: mousedown
});
}
function keydown(event) {
if((mario && mario.dead) || window.paused || window.nokeys) return;
// Allow this to be used as keyup(37) or keyup({which: 37})
if(typeof(event) != "number" || event.which)
event = event.which;
switch(event) {
case 37: case 65: // left
mario.keys.run = -1;
break;
case 38: case 87: case 32: // up
mario.keys.up = true;
if(mario.canjump && !mario.crouching && (mario.resting || map.underwater)) {
mario.keys.jump = 1;
mario.canjump = mario.keys.jumplev = 0;
// To do: can mario make a jumping sound during the spring?
if(mario.power > 1) play("Jump Super.wav");
else play("Jump Small.wav");
if(map.underwater) setTimeout(function() {
mario.jumping = mario.keys.jump = false;
}, timer * 14);
}
break;
case 39: case 68: // right
mario.keys.run = 1;
break;
case 40: case 83: // down
mario.keys.crouch = 1;
break;
case 16: // sprint
if(mario.power == 3 && mario.keys.sprint == 0) mario.fire();
mario.keys.sprint = 1;
break;
case 80: // pause
if(!paused && !(window.editing && !editor.playing))
setTimeout(function() { pause(true); }, 140);
break;
case 32: // space
timer = timerd2;
break;
case 77: // mute/unmute
toggleMute();
break;
case 81: // qqqqqqqqqqqqqqqqq
if(++qcount > 28) maxlulz();
switch(qcount) {
case 7: lulz(); break;
case 14: superlulz(); break;
case 21: hyperlulz(); break;
}
break;
case 66: // B; 8-4 protip
console.log("See map random! 7777777");
break;
default:
if(!(parentwindow && parentwindow.scrollPageBig)) return;
parentwindow.keydown(event);
break;
}
window.gamehistory[gamecount] = [keydown, event];
}
function keyup(event) {
if(window.nokeys) return;
// Allow this to be used as keyup(37) or keyup({which: 37})
if(typeof(event) != "number" || event.which)
event = event.which;
switch(event) {
case 37: case 65: // left
mario.keys.run = 0;
break;
case 38: case 87: case 32: // up
if(!map.underwater) mario.keys.jump = mario.keys.up = 0;
mario.canjump = true;
break;
case 39: case 68: // right
mario.keys.run = 0;
break;
case 40: case 83: // down
mario.keys.crouch = 0;
removeCrouch();
break;
case 16: // sprint
mario.keys.sprint = 0;
break;
case 80: // paused
unpause(true);
break;
case 32: // space
timer = timernorm;
break;
default: return; // for typing, exit this handler for other keys
}
window.gamehistory[gamecount] = [keyup, event];
}
function contextmenu(event) {
if(event.preventDefault)
event.preventDefault();
}
function mousedown(event) {
// Right click
if(event.which == 3) {
if(paused) unpause();
else if((!window.editor) || (!editing && !editor.playing)) pause(true);
if(event.preventDefault)
event.preventDefault()
}
}
function scriptKeys(oldhistory) {
var i, entry;
for(i in oldhistory) {
entry = oldhistory[i];
addEvent(entry[0], i, entry[1]);
addEvent(function() { alert(entry[0].name + ", " + entry[1]) }, i);
}
}
function lulz(options, timer) {
mario.star = true;
options = options || [Goomba];
timer = timer || 7;
addEventInterval(function() {
if(characters.length > 210) return;
var lul = new Thing(options[randInt(options.length)], randBoolJS(), randBoolJS());
lul.yvel = random() * -unitsizet4;
lul.xvel = lul.speed = random() * unitsizet2 * randSign();
addThing(lul, (32 * random() + 128) * unitsize, (88 * random()) * unitsize);
}, timer, Infinity);
}
function superlulz() {
lulz([Goomba, Koopa, Beetle, HammerBro, Lakitu, Podoboo, Blooper]);
}
function hyperlulz() {
lulz([Bowser], 21);
}
// Sigh....
function maxlulz() {
// window.palette = arrayShuffle(window.palette, 1);
// clearAllSprites(true);
addEventInterval(function(arr) {
setAreaSetting(arr[randInt(arr.length)]);
}, 7, Infinity, ["Overworld", "Underworld", "Underwater", "Sky", "Castle"]);
}