-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.js
More file actions
40 lines (36 loc) · 978 Bytes
/
Copy pathBullet.js
File metadata and controls
40 lines (36 loc) · 978 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
30
31
32
33
34
35
36
37
38
39
40
class Bullet {
constructor(Vaisseau) {
this.x = Vaisseau.x;
this.y = Vaisseau.y;
this.angle = Vaisseau.angle;
this.boundingBox = {
x: this.x,
y: this.y,
width: 10,
height: 2
}
}
drawBoundingBox(ctx) {
ctx.save();
ctx.strokeStyle = 'red';
ctx.strokeRect(this.boundingBox.x, this.boundingBox.y, this.boundingBox.width, this.boundingBox.height);
ctx.restore();
}
draw(ctx) {
if (afficher_bounding == true) {
this.drawBoundingBox(ctx);
}
ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.angle);
ctx.fillStyle = 'red';
ctx.fillRect(-25, 0, 10, 2);
ctx.restore();
}
move() {
this.x -= 10 * Math.cos(this.angle);
this.y -= 10 * Math.sin(this.angle);
this.boundingBox.x = this.x;
this.boundingBox.y = this.y;
}
}