-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprojectile.js
53 lines (48 loc) · 1.02 KB
/
projectile.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
class Projectile{
constructor(x, y, data){
this.x = x;
this.y = y;
this.w = data.width;
this.h = data.height;
this.color = data.color;
this.xv = data.xv;
this.yv = data.yv;
this.power = data.power;
this.owner = data.owner;
this.strength = data.strength;
this.gone = false;
}
kinematics(field){
this.x += this.xv;
this.y += this.yv;
if(this.x < 0 || this.x > field.width ||
this.y < 0 || this.y > field.height){
this.gone = true;
}
}
collision(players){
for(let [id, player] of players){
if(this.owner !== id && !player.gone){
if(this.x < player.x + player.w &&
this.x + this.h > player.x &&
this.y < player.y + player.h &&
this.y + this.h > player.y){
this.gone = true;
//player.shotTimer = player.recharge;
player.hp -= Math.round(this.strength*this.power/player.defense);
}
}
}
}
getVisualData(){
return {
x: this.x,
y: this.y,
w: this.w,
h: this.h,
type: "projectile",
color: this.color
};
}
}
module.exports = Projectile;