-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullet.js
More file actions
54 lines (54 loc) · 1.1 KB
/
bullet.js
File metadata and controls
54 lines (54 loc) · 1.1 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
var math = require("./mathFunctions");
module.exports = class Bullet {
constructor(config) {
this.x = config.x;
this.y = config.y;
this.xspeed = config.xspeed;
this.yspeed = config.yspeed;
this.r = config.r;
this.size = 0.3;
this.id = config.id;
this.powerup = config.power;
this.type = config.type;
this.startx = config.x;
this.starty = config.y;
}
update(data) {
for (let i in data) {
if (this[i] !== undefined) {
this[i] = data[i];
}
}
}
move() {
this.x += this.xspeed;
this.y += this.yspeed;
}
checkhit(x, y) {
if (math.dist(this.x, this.y, x, y) < 50) {
return true;
} else {
return false;
}
}
checkdist() {
if (math.dist(this.x, this.y, this.startx, this.starty) > 2000) {
return true;
} else {
return false;
}
}
checkborders() {
if (this.x < -7200) {
return true;
} else if (this.x > 7200) {
return true;
} else if (this.y < -7200) {
return true;
} else if (this.y > 7200) {
return true;
} else {
return false;
}
}
};