-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (26 loc) · 993 Bytes
/
script.js
File metadata and controls
29 lines (26 loc) · 993 Bytes
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
import Player from './player.js';
import InputHandler from './input.js';
import {drawStatusText} from './utils.js';
window.addEventListener('load', function(){
const loading = this.document.getElementById('loading');
loading.style.display = 'none';
const canvas = document.getElementById('canvas1');
const ctx = canvas.getContext('2d');
canvas.width = this.window.innerWidth
canvas.height = this.window.innerHeight
const player = new Player(canvas.width, canvas.height);
/* console.log(player */
const input = new InputHandler();
let lastTime = 0;
function animate(timeStamp){
const deltaTime = timeStamp - lastTime;
lastTime = timeStamp;
ctx.clearRect(0, 0, canvas.width, canvas.height);
/* console.log(input.lastKey); */
player.update(input.lastKey);
player.draw(ctx, deltaTime );
drawStatusText(ctx, input, player);
requestAnimationFrame(animate);
};
animate(0);
});