-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrollby.html
44 lines (44 loc) · 1.43 KB
/
scrollby.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
<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;
var scrollspeed = blockWidth / 30; // pixels / second
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();
var offsetX = 0;
function drawStuff() {
canvas.width = canvas.width; // clears the canvas
currentTime = new Date().getTime();
deltaSec = (currentTime - lastTime) / 1000;
lastTime = currentTime;
offsetX -= deltaSec * scrollspeed
blocks.renderWithOffset(deltaSec, offsetX);
}
resizeCanvas();
setInterval(drawStuff, 1000 / FPS);
var spawner = spawner({canvas: canvas, blockWidth: blockWidth, blockHeight: blockHeight});
var initX = canvas.width - blockWidth;
setInterval(function () { initX += blockWidth; }, 1000 * 30);
function addBlock() {
spawner.spawn(blocks, initX, 0);
}
setInterval(addBlock, 2000);
</script>
</body>
</html>