-
Notifications
You must be signed in to change notification settings - Fork 0
/
projectiles.js
82 lines (80 loc) · 2.35 KB
/
projectiles.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
export class MyLaser {
constructor(game, x, y){
this.game = game;
this.x = x;
this.y = y;
this.width = 3;
this.height = 25;
this.toDelete = false;
this.sound = new Audio('./sounds/xwing_fire.mp3');
this.soundOnce = true;
}
update(){
this.y -= 10;
if (this.soundOnce === true){
this.sound.play();
this.soundOnce = false;
}
if (this.y < -this.height) this.toDelete = true;
}
draw(context){
context.save();
context.shadowColor = "white";
context.shadowBlur = 3;
context.fillStyle = 'red';
context.fillRect(this.x, this.y, this.width, this.height);
context.restore();
}
}
export class EnemyLaser extends MyLaser {
constructor(game, x, y){
super(game, x, y);
this.sound = new Audio('./sounds/tie-fighter_fire.mp3');
this.sound2 = new Audio('./sounds/tie-fighter_fire2.mp3');
this.soundOnce = true;
}
update(){
this.y += 5;
if (this.soundOnce === true){
let random = Math.random();
if (random > 0.5) this.sound.play();
else this.sound2.play();
this.soundOnce = false;
}
if (this.y > this.game.height - this.height) this.toDelete = true;
}
draw(context){
context.save();
context.shadowColor = "white";
context.shadowBlur = 2;
context.fillStyle = 'green';
context.fillRect(this.x, this.y, this.width, this.height);
context.restore();
}
}
export class EnemyBomb extends MyLaser{
constructor(game, x, y){
super(game, x, y);
this.round = 7;
this.sound = new Audio('./sounds/tie-bomber_fire.mp3');
this.soundOnce = true;
}
update(){
this.y += 3;
if (this.soundOnce === true){
this.sound.play();
this.soundOnce = false;
}
if (this.y > this.game.height - this.height) this.toDelete = true;
}
draw(context){
context.save();
context.strokeRect(this.x - this.round, this.y - this.round, this.round, this.round)
context.fillStyle = 'white';
context.beginPath();
context.arc(this.x, this.y, this.round, 0, Math.PI * 2);
context.fill();
context.stroke();
context.restore();
}
}