Repository navigation
Expand file tree
/
Copy pathpacemaker.html
More file actions
194 lines (164 loc) · 6.51 KB
/
Copy pathpacemaker.html
File metadata and controls
194 lines (164 loc) · 6.51 KB
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
<!DOCTYPE html>
<head>
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed' rel='stylesheet' type='text/css'>
<script type = "text/javascript" src="./pacemaker_map.js"></script>
<script type = "text/javascript" src="./world_objects.js"></script>
<script type = "text/javascript" src="./setup.js"></script>
<script type = "text/javascript" src="./events.js"></script>
<script type = "text/javascript" src="./button.js"></script>
<script type = "text/javascript" src="./rendering.js"></script>
<link href = "style.css" rel = "stylesheet" type = "stylesheet"> </link>
<script type = "text/javascript">
var fps = 60, now, lastUpdate = (new Date)*1 - 1, fpsControl = 1, x, y;
// The higher this value, the less the FPS will be affected by quick changes
// Setting this to 1 will show you the FPS of the last sampled frame only
var fpsFilter = 10;
////////////////////////////////////////////////////////////////////////////////////////// UPDATE PLATFORM X POS (makes screen movement work)
function update_platforms(x_change){
for(i = 0; i<platforms.length; i++){
platforms[i].x += x_change;
}
}
function Control() {
this.space = false;
this.shift = false;
this.left = false;
this.right = false;
this.up = false;
this.down = false;
this.mouse_left = false;
this.mouse_right = false;
this.mouse_middle = false;
this.click_mouse_x = null;
this.click_mouse_y = null;
this.mouse_x = null;
this.mouse_y = null;
this.p = false;
}
function gamepadConnected(evt)
{
console.log(evt);
}
window.addEventListener('MozGamepadConnected', gamepadConnected);
////////////////////////////////////////////////////////////////////////////////////////// PLATFORMS CLASS
function onFocus(){
windowActive = true;
}
function onBlur(){
windowActive = false;
}
////////////////////////////////////////////////////////////////////////////////////////// DISTANCE BETWEEN TWO OBJECTS
function distanceBetween(Object1, Object2){
// return the distance between the centers of two objects
return Math.sqrt(
Math.pow(((Object1.x+.5*Object1.width)-(Object2.x+platform_x_movement+.5*Object2.width)),2)
+ Math.pow(((Object1.y+.5*Object1.height)-(Object2.y+0.5*Object2.height)),2)
);
}
////////////////////////////////////////////////////////////////////////////////////////// GAME CLASS
function Game(ctx, x_boundary, y_boundary, frame_delay){
this.ctx = ctx; // canvas context
this.frame_delay = frame_delay; // ms delay between drawing
this.x_boundary = x_boundary; // x-coord boundary
this.y_boundary = y_boundary; // y-coord boundary
this.clearColor = "rgba(100, 100, 100, 0.01)"; // initial clear color is null
this.state = GAMESTATE_START;
this.resetGame = resetGame;
////////////////////////////////////////////////////////////////////////////////////// RESET GAME
function resetGame(){
collectable_count = 0;
collectable_count = 0;
collectable = new Array();
imageMap = null;
lastfps = 0;
platform_x_movement = 0;
platforms = new Array();
platform_update = 0;
begin_game();
clearTimeout(gametimeout);
}
}
function screenClear(currentGame){
ctx.fillStyle = currentGame.clearColor;
ctx.fillRect(0, 0, currentGame.x_boundary, currentGame.y_boundary);
return true;
}
////////////////////////////////////////////////////////////////////////////////////////// AVOID THIS SHIT
function drawObject(drawableObject, ctx){
ctx.drawImage(drawableObject.image, Math.round(drawableObject.x), Math.round(drawableObject.y), drawableObject.width, drawableObject.height);
return true;
}
////////////////////////////////////////////////////////////////////////////////////////// UP DRAWN TO SCREEN
function drawUI(context){
var canvas = document.getElementById("draw_canvas");
if(debug) {
// draw debugging UI
context.font = '15px Calibri';
context.fillStyle = "rgb(240,240,240)";
context.fillText("FPS-Avg: " + fps.toFixed(0), 120, 20);
context.fillText("FPS-Imm: " + thisFrameFPS.toFixed(2), 120, 35);
context.fillText("Collided: " + CurrPlayer.grounded || CurrPlayer.grounded_last_frame, 600, 35);
context.fillText("Dist-Since-Change: " + CurrPlayer.distance_since_sprite_change.toFixed(2), 600, 20);
} else {
// draw normal UI
context.drawImage(Cell.image, 15, 12);
context.font = '25px Calibri';
context.fillStyle = "rgb(240,240,240)";
context.fillText(" x ", 57, 42);
context.fillText(" " + collectable_count, 60, 43);
}
if(CurrPlayer.dead){
context.font = '30px Calibri';
context.fillText("You dead bro?", 230, 35);
}
if(document.activeElement.id != "draw_canvas" || !windowActive || Controller.p){ ////////////////////////////Known Bug - can pause while jumped
context.fillStyle = "rgba(50,50,50,0.5)";
context.fillRect(527, 247, 145, 50);
context.fillStyle = "rgb(240,240,240)";
context.font = '30px Calibri';
context.fillText("Paused", 550, 280);
}
}
///////////////////////////////////////////////////////////////////// ACTIONS TO DO BEFORE DRAWING (good place to update shit)
function frame(){
if(document.activeElement.id == "draw_canvas" && windowActive){
///////////////////////////////////////////////////////////////////////////////////// UPDATE DAT CHAR
CurrPlayer.update();
}
screenClear(PlayerGame);
//window.requestAnimationFrame(frame);
gametimeout = setTimeout(frame, 16);
draw_world();
// IGNORE FRAME STUFF, it is used for accurate movement / fps counter
thisFrameFPS = 1000 / ((now=new Date) - lastUpdate);
if(thisFrameFPS < 10){
thisFrameFPS = 60;
}
lastfps = fps;
fps += (thisFrameFPS - fps) / fpsFilter;
if(isNaN(fps)){
// fps counter has glitched up, set it to a nice value
fps = 60;
}
lastUpdate = now;
fpsControl = 60/thisFrameFPS;
fpsWave = 60/thisFrameFPS;
}
////////////////////////////////////////////////////////////////////////////////////////// IGNORE THESE
window.addEventListener('keydown',key_event,true);
window.addEventListener('keyup',key_event_up,true);
window.addEventListener('mouseup', mouse_up, false);
window.addEventListener('mousedown', mouse_down, false);
window.onfocus = onFocus;
window.onblur = onBlur;
</script>
</head>
<body style="overflow: hidden;" onload="page_load()">
<canvas onmousemove="mouse_move(event)" onmousedown="mouse_press(event)" id="draw_canvas" width="1200" height="600" tabindex="1"></canvas>
<div id="fps" style="width: 50px;"></div><div id="ms" style="display: hidden;"></div>
<script type="text/javascript">
gameCanvas = document.getElementById("draw_canvas");
document.getElementById("draw_canvas").focus();
</script>
</body>
</html>