-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
139 lines (124 loc) · 3.43 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
<html>
<head>
<title>Gimble</title>
<script src=gimble.js></script>
<script>
var win = false;
var die = false;
var counter = 1;
function go() {
counter = 1;
win = false;
die = false;
paused = false;
s = 24;
var canvas = document.getElementById('c');
WIDTH = canvas.width = SQUARE * s / 2;
HEIGHT = canvas.height = SQUARE * s / 2;
var ctx = canvas.getContext('2d');
var min_cam_x = 0;
var max_cam_y = HEIGHT;
var min_cam_y = 0;
complex = new Complex(difficulty);
var gimble = new Gimble (2 * SQUARE, HEIGHT*2 - 2 * SQUARE);
min_cam_y = complex.room.max_j * SQUARE;
max_cam_x = complex.width * SQUARE - WIDTH + SQUARE;
var cam = {x: 0, y: 0};
var time = new Date;
(function tick() {
var dt = new Date - time;
time = new Date;
if (counter) window.requestAnimationFrame(tick);
else stop();
if (paused) {
if (win) gimble.winTick();
if (die) gimble.dieTick();
} else {
gimble.tick(complex, dt);
complex.tick(gimble, dt);
}
ctx.save();
ctx.clearRect(0, 0, WIDTH, HEIGHT);
cam.x = gimble.x - WIDTH / 2;
cam.y = gimble.y - HEIGHT / 2;
/*
if (cam.x > max_cam_x) cam.x = max_cam_x;
if (cam.y > max_cam_y) cam.y = max_cam_y;
if (cam.x < min_cam_x) cam.x = min_cam_x;
if (cam.y < min_cam_y) cam.y = min_cam_y;
*/
//crawlie.tick(gimble);
ctx.translate(-cam.x, -cam.y);
ctx.globalCompositeOperation = 'source-over';
complex.room.drawDark(ctx, cam);
gimble.drawDark(ctx);
ctx.globalCompositeOperation = 'source-atop';
complex.room.draw(ctx, cam);
ctx.globalCompositeOperation = 'source-over';
gimble.draw(ctx);
ctx.globalCompositeOperation = 'destination-over';
ctx.fillStyle = 'black';
ctx.fillRect(cam.x, cam.y, WIDTH, HEIGHT);
ctx.restore();
gimble.drawStats(ctx);
//complex.drawMap(ctx);
if (win || die) gimble.drawOver(ctx);
})();
}
addEventListener('keydown', function (e) {
if (e.keyCode == 80) paused = !paused;
});
function start () {
document.getElementById('instructions').classList.add('hidden');
document.getElementById('canvas').classList.remove('hidden');
go();
}
function stop () {
document.getElementById('instructions').classList.remove('hidden');
document.getElementById('canvas').classList.add('hidden');
if (win) {
var s = document.getElementById('secret');
s.classList.remove('hidden');
document.getElementById('s').innerHTML += '+';
} else document.getElementById('secret').classList.add('hidden');
}
function startPlus () {
difficulty += 2;
start();
}
var difficulty = 6;
function toggleMap () {
var m = document.getElementById('map');
m.classList.toggle('hidden');
}
</script>
<style>
.hidden {
display:none;
}
#map {
opacity: .5;
}
</style>
</head>
<body>
<center>
<div id=instructions>
<h2> GIMBLE </h2>
<h3>When light is scarce, Gimble must escape with wits intact.</h3>
<p>Press the arrow keys to move, space to jump, and shift to use your special power.</p>
<p>Press up to use a door. Some doors are marked, and require a similar key.</p>
<p>Torches light your way. They require a little fuel.</p>
<p>Flies like light, but they put it out.</p>
<p>Roaches make you start leaking fuel. Look out!</p>
<p>There are large blue fueling stations and small blue fuel packs.</p>
<p>Gimble loves peppermint!</p>
<p id=secret class=hidden><a id=s href=javascript:startPlus()>new game</a></p>
<p><a href=javascript:start(false)>new game</a></p>
</div>
<div id=canvas class=hidden>
<canvas id=c style="border:3px solid grey"></canvas>
</div>
</center>
</body>
</html>