forked from Oletus/elevator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
237 lines (205 loc) · 7.58 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>The Everything Building</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta property="og:url" content="http://oletus.github.io/elevator/">
<meta property="og:title" content="The Everything Building">
<meta property="og:image" content="http://oletus.github.io/elevator/ogimage2.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- output -->
<script src="src/lib/hsl.js"></script>
<script src="src/sprite.js"></script>
<script src="src/animatedsprite.js"></script>
<script src="src/audio.js"></script>
<script>
Audio.defaultExtensions = ['ogg', 'mp3'];
Audio.audioPath = 'assets/audio/';
</script>
<script src="src/canvasresizer.js"></script>
<script src="src/loadingbar.js"></script>
<script src="src/particle.js"></script>
<!--<script src="src/canvasui.js"></script>-->
<script src="src/lib/dat.gui.js"></script>
<script src="src/gameparameters.js"></script>
<!-- input -->
<script src="src/lib/mousetrap.js"></script>
<script src="src/lib/mousetrap-global-bind.js"></script>
<script src="src/gamepad.js"></script>
<script src="src/inputmapper.js"></script>
<script src="src/mainloop.js"></script>
<script src="src/util2d.js"></script>
<script src="src/utiljs.js"></script>
<script src="src/tilemap.js"></script>
<script src="src/monospacebitmapfont.js"></script>
<script src="src/elevator.js"></script>
<script src="src/level.js"></script>
<script src="src/character.js"></script>
<script src="src/gamedata.js"></script>
<script src="src/floor.js"></script>
<script>
'use strict';
var Game = function(resizer) {
this.canvas = resizer.getCanvas();
this.realCtx = this.canvas.getContext('2d');
/*this.canvasUI = new CanvasUI({
element: this.canvas,
getCanvasPositionFromEvent: function(event) {
return resizer.getCanvasPosition(event);
}
});*/
this.time = 0;
this.level = new Level();
this.input = new InputMapper(this, 1);
this.input.addListener(Gamepad.BUTTONS.UP_OR_ANALOG_UP, ['up', 'w'], this.upPress, this.upRelease);
this.input.addListener(Gamepad.BUTTONS.DOWN_OR_ANALOG_DOWN, ['down', 's'], this.downPress, this.downRelease);
this.input.addListener(Gamepad.BUTTONS.START, ['enter', 'space'], this.startPress, this.startRelease);
};
Game.prototype.render = function(ctx) {
// CanvasResizer passes a wrapped 2D context to use here when run in FIXED_COORDINATE_SYSTEM mode,
// where ctx.canvas.width/height are set to the coordinate system width/height.
// Otherwise the context initialized here is used.
if (ctx === undefined) {
ctx = this.realCtx;
}
ctx.textBaseline = 'top';
this.level.render(ctx);
return ctx;
};
Game.prototype.isWaitingStartPress = function() {
if (this.level.stateTime < 0.5) {
return false;
}
return this.level.state !== Level.State.IN_PROGRESS;
};
Game.prototype.startPress = function(playerNumber) {
if (!this.isWaitingStartPress()) {
return;
}
if (this.level.state === Level.State.FAIL) {
this.level = new Level();
} else if (this.level.state === Level.State.TITLE_SCREEN) {
this.level.goToState(Level.State.IN_PROGRESS);
}
};
Game.prototype.startRelease = function(playerNumber) {
};
Game.prototype.downPress = function(playerNumber) {
this.level.downPress(playerNumber);
};
Game.prototype.upPress = function(playerNumber) {
this.level.upPress(playerNumber);
};
Game.prototype.downRelease = function(playerNumber) {
this.level.downRelease(playerNumber);
};
Game.prototype.upRelease = function(playerNumber) {
this.level.upRelease(playerNumber);
};
Game.prototype.canvasPress = function(pos) {
if (this.isWaitingStartPress) {
this.startPress();
}
this.level.canvasPress(pos);
};
Game.prototype.canvasRelease = function(pos) {
if (this.isWaitingStartPress) {
this.startPress();
}
this.level.canvasRelease(pos);
};
Game.prototype.update = function(deltaTime) {
this.time += deltaTime;
this.level.update(deltaTime);
this.input.update();
Audio.muteAll(Game.parameters.get('muteAudio'));
};
var DEV_MODE = (window.location.href.indexOf("?devMode") != -1);
var blackBitmapFont = new MonospaceBitmapFont({color: 'black'});
var whiteBitmapFont = new MonospaceBitmapFont({color: 'white'});
var bigBitmapFont = new MonospaceBitmapFont({spriteSrc: 'bitmapfont-medium.png', characterWidth: 8, characterHeight: 13});
Game.music = new Audio('elevator_music');
Game.gameOverSound = new Audio('gameover');
Game.parameters = new GameParameters({
'initialSpawnInterval': {initial: 4, min: 0.5, max: 10},
'spawnIntervalRandomness': {initial: 1, min: 0, max: 2},
'floorCapacity': {initial: 22, min: 3, max: 50},
'bandUnionDuration': {initial: 0.5, min: 0.1, max: 2},
'muteAudio': false
});
var game;
var resizer;
var coordinatesDown = [
];
var coordinateIndices = {
mouse: -1
};
var eventListener = function(e) {
var type;
var ids = [];
if (e.type === 'mousedown') {
type = 'down';
ids.push('mouse');
} else if (e.type === 'mouseup' || e.type === 'mouseout') {
type = 'up';
ids.push('mouse');
} else if (e.type === 'touchstart') {
type = 'down';
for (var i = 0; i < e.changedTouches.length; ++i) {
ids.push('touch' + e.changedTouches[i].identifier);
}
} else if (e.type === 'touchcancel' || e.type === 'touchend') {
type = 'up';
for (var i = 0; i < e.changedTouches.length; ++i) {
ids.push('touch' + e.changedTouches[i].identifier);
}
}
for (var i = 0; i < ids.length; ++i) {
var id = ids[i];
if (type === 'down') {
var touchId = undefined;
if (id !== 'mouse') {
touchId = id.substring(5);
}
var pos = resizer.getCanvasPosition(event, touchId);
coordinatesDown.push(pos);
coordinateIndices[id] = coordinatesDown.length - 1;
game.canvasPress(pos);
} else {
if (coordinateIndices.hasOwnProperty(id) && coordinateIndices[id] !== -1) {
var index = coordinateIndices[id];
var pos = coordinatesDown.splice(index, 1)[0];
for (var key in coordinateIndices) {
if (coordinateIndices.hasOwnProperty(key) && coordinateIndices[key] > index) {
coordinateIndices[key] = coordinateIndices[key] - 1;
}
}
coordinateIndices[id] = -1;
game.canvasRelease(pos);
}
}
}
e.preventDefault();
};
window['start'] = function() {
var DEBUG_MAIN_LOOP = DEV_MODE && true; // Set to true to allow fast-forwarding main loop with 'f'
Game.parameters.set('muteAudio', (DEV_MODE && true)); // Set to true if sounds annoy developers
if (DEV_MODE) {
Game.parameters.initGUI();
}
resizer = new CanvasResizer({mode: CanvasResizer.Mode.MINIMUM_HEIGHT, width: 192, height: 312});
resizer.canvas.addEventListener('mousedown', eventListener);
resizer.canvas.addEventListener('mouseup', eventListener);
resizer.canvas.addEventListener('mouseout', eventListener);
resizer.canvas.addEventListener('touchstart', eventListener);
resizer.canvas.addEventListener('touchend', eventListener);
resizer.canvas.addEventListener('touchcancel', eventListener);
game = new Game(resizer);
startMainLoop([resizer, game, new LoadingBar(), resizer.pixelator()], {debugMode: DEBUG_MAIN_LOOP});
};
</script>
</head>
<body onload="start()" style="background: black;">
</body>
</html>