-
Notifications
You must be signed in to change notification settings - Fork 3
/
game.js
58 lines (46 loc) · 1.37 KB
/
game.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
50
51
52
53
54
55
56
57
58
console.log('ok!')
let canvas = document.querySelector('#cvGame')
let ctx = canvas.getContext('2d');
let W = canvas.getBoundingClientRect().width;
let H = canvas.getBoundingClientRect().height;
document.addEventListener('keydown', keyDownHandler);
document.addEventListener('keyup', keyUpHandler);
// player2 = new Blob(BLOB_RECT, 0, 0, 20, 20, 'cyan');
player2 = new Blob(BLOB_CIRCLE, 40, 40, 20, 20, 'brown');
ledges = [
new Ledge(10, 200, 200),
new Ledge(5, 600, 350),
new Ledge(9, 360, 550),
new Ledge(7, 40, 750),
]
function draw() {
drawRect(0, 0, W, H, 'black');
// player.update();
player2.update();
ledges.forEach(ledge => {
ledge.update();
ledge.collide(player2);
});
requestAnimationFrame(draw);
}
draw();
function drawCircle(centerX, centerY, radius, fillColor) {
ctx.beginPath();
ctx.fillStyle = fillColor;
ctx.arc(centerX,centerY, radius, 0,Math.PI*2, true);
ctx.fill();
ctx.closePath();
}
function drawText(topLeftX, topLeftY, msg, fillColor='black', fontSize='3em') {
ctx.font = `${fontSize} Arial`;
ctx.fillStyle = fillColor
ctx.fillText(msg, topLeftX, topLeftY)
}
function keyDownHandler(e) {
// player.keyDownHandler(e);
player2.keyDownHandler(e);
}
function keyUpHandler(e) {
// player.keyUpHandler(e);
player2.keyUpHandler(e);
}