forked from enriquesanchezb/game_for_testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticles.js
More file actions
78 lines (74 loc) · 2.05 KB
/
particles.js
File metadata and controls
78 lines (74 loc) · 2.05 KB
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
class Particle {
constructor(game){
this.game = game;
this.markedForDeletion = false;
}
update(){
this.x -= this.speedX + this.game.speed;
this.y -= this.speedY;
this.size *=0.95;
if (this.size < 0.5) this.markedForDeletion = true;
}
}
export class Dust extends Particle {
constructor(game, x, y){
super(game);
this.size = Math.random() * 10 +10;
this.x = x;
this.y = y;
this.speedX = Math.random();
this.speedY = Math.random();
this.color = 'rgba(0,0,0,0.2)';
}
draw(context){
context.beginPath();
context.arc(this.x, this.y, this.size, 0, Math.PI * 2);
context.fillStyle = this.color;
context.fill();
}
}
export class Splash extends Particle {
constructor(game, x, y){
super(game);
this.size = Math.random() * 100 +100;
this.x = x - this.size * 0.4;
this.y = y - this.size * 0.5;
this.speedX = Math.random() * 6 -3;
this.speedY = Math.random() * 2 +2;
this.gravity = 0;
this.image = document.getElementById('fire');
}
update(){
super.update();
this.gravity += 0.1;
this.y += this.gravity;
}
draw(context){
context.drawImage(this.image, this.x, this.y, this.size, this.size);
}
}
export class Fire extends Particle {
constructor(game, x, y){
super(game);
this.image = document.getElementById('fire');
this.size = Math.random() * 100 +50;
this.x = x;
this.y = y;
this.speedX = 1;
this.speedY = 1;
this.angle = 0;
this.va = Math.random() * 0.2 -0.1;
}
update(){
super.update();
this.angle += this.va;
this.x += Math.sin(this.angle * 10);
}
draw(context){
context.save();
context.translate(this.x, this.y);
context.rotate(this.angle);
context.drawImage(this.image, -this.size * 0.5, -this.size *0.5, this.size, this.size);
context.restore();
}
}