-
Notifications
You must be signed in to change notification settings - Fork 0
/
cannon.js
57 lines (46 loc) · 1.34 KB
/
cannon.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
const pipesSprite = new Image();
pipesSprite.src = './images/pipes.png'; //Parts was designed by macrovector / Freepik
const cannonTop = new Image();
cannonTop.src="./images/cannon.png";
class Cannon {
constructor() {
this.x = 300;
this.y = 580;
this.topX = this.x-115;
this.topY = this.y-170;
this.pipesWidth = 238;
this.pipesHeight = 652;
this.cannonWidth = 75;
this.cannonHeight = 63;
}
pipes() {
ctx.drawImage(pipesSprite, this.x-280, this.y-430, this.pipesWidth, this.pipesHeight);
}
rotateTop() {
if (mousePos) {
angle = Math.atan2(mousePos.y - (this.y-145), mousePos.x - (this.x-80));
ctx.translate((this.x-80), (this.y-145));
ctx.rotate(angle);
ctx.translate(-(this.x-84), -(this.y-138));
}
}
draw() {
this.pipes();
ctx.save();
this.rotateTop();
if (!playerShooted) {
player = new Player(this.topX+120, this.topY);
player.draw();
}
ctx.drawImage(cannonTop, this.topX,this.topY, this.cannonWidth, this.cannonHeight);
}
move() {
this.x -= Xdiff;
this.topX -= Xdiff;
}
moveY() {
this.y -= Ydiff;
this.topY -= Ydiff;
}
}
let cannon = new Cannon();