-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (45 loc) · 1.36 KB
/
app.js
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
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const info = document.getElementById("info");
let key = [];
function main(){
handleResize(); // init browser window sizing with canvas
let game = new Game(ctx);
window.game = game;
game.update();
}
var a = 0;
/*
function update() {
requestAnimationFrame(update);
ctx.clearRect(0,0,canvas.width, canvas.height);
ctx.fillRect(c.x, c.y, 2,2);
point.forEach((p) => {
ctx.fillRect(c.x + p.x, c.y + p.y, 5,5);
})
point = Utils.rotatePoints(point, a/180);
}
*/
const handleResize = () => {
canvas.width = innerWidth;
canvas.height = innerHeight;
}
const handleKeydown = (e) => {
key[e.keyCode] = true;
}
const handleKeyup = (e) => {
key[e.keyCode] = false;
}
const handleMouseDown = (e) => {
// Adds camera pos to translate screen position to world position
let angle = Utils.getAngleBetweenPoints(game.rocket.p, new Vector(e.clientX + game.camera.p.x, e.clientY + game.camera.p.y));
//game.rocket.shoot(angle);
}
const handleMouseUp = (e) => {
}
window.addEventListener("load", main);
window.addEventListener("resize", handleResize);
window.addEventListener("keydown", handleKeydown);
window.addEventListener("keyup", handleKeyup);
window.addEventListener("mousedown", handleMouseDown);
window.addEventListener("mouseup", handleMouseUp);