-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeitrain.html
41 lines (41 loc) · 1.29 KB
/
makeitrain.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
<html>
<head>
<link rel="stylesheet" type="text/css" href="yo.css">
</head>
<body>
<canvas id="mainframe"></canvas>
<script src="blocks.js"></script>
<script src="sprite.js"></script>
<script src="spawner.js"></script>
<script type="text/javascript">
var blockWidth = 32;
var blockHeight = 16;
var FPS = 30;
window.addEventListener('resize', resizeCanvas, false);
var canvas = document.getElementById("mainframe");
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
drawStuff();
}
var blocks = blocks({canvas: canvas});
var lastTime = new Date().getTime();
function drawStuff() {
canvas.width = canvas.width; // clears the canvas
currentTime = new Date().getTime();
deltaSec = (currentTime - lastTime) / 1000;
lastTime = currentTime;
blocks.render(deltaSec);
}
setInterval(drawStuff, 1000 / FPS);
var spawner = spawner({canvas: canvas, blockWidth: blockWidth, blockHeight: blockHeight});
function addBlock() {
var randomX = Math.random() * canvas.width;
var initX = randomX - randomX % blockWidth;
spawner.spawn(blocks, initX, 0);
}
setInterval(addBlock, 1000);
resizeCanvas();
</script>
</body>
</html>