-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsteroid.js
56 lines (48 loc) · 1.11 KB
/
Asteroid.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
class Asteroid {
constructor(manager, pos, vel, size) {
this.entityManager = manager;
this.pos = createVector(pos.x, pos.y);
this.vel = vel;
this.size = size;
this.r = 60 - (20 * (0 - size / 2));
this.points = manager.getRandom(8, 16);
this.offset = [];
for (let i = 0; i < this.points; i++) {
this.offset[i] = manager.getRandom(-35, -20);
}
}
draw() {
this.edges();
this.update();
push();
translate(this.pos.x, this.pos.y);
noFill();
stroke(255);
beginShape();
for (let i = 0; i < this.points; i++) {
let angle = map(i, 0, this.points, 0, TWO_PI);
let r = this.r + this.offset[i];
let x = r * cos(angle);
let y = r * sin(angle);
vertex(x, y);
}
endShape(CLOSE);
//ellipse(0, 0, this.r, this.r);
pop();
}
update() {
this.pos.add(this.vel);
}
edges() {
if (this.pos.x < 0) {
this.pos.x = width;
} else if (this.pos.x > width) {
this.pos.x = 0;
}
if (this.pos.y < 0) {
this.pos.y = height;
} else if (this.pos.y > height) {
this.pos.y = 0;
}
}
}