-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathasteroid.js
93 lines (88 loc) · 3.27 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
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
83
84
85
86
87
88
89
90
91
92
// file for the asteroids class object
// constructor should create the sprite and store it in a private attribute
// methods will act on the sprite, such as spawning
class Asteroid{
constructor(x = 0,y = 0){
//console.log(colliding);
/* this.asteroid = new colliding.Sprite(0,0,10,'dodecagon');
//this.asteroid.diameter = 50;
this.asteroid.color = 'darkgray';
this.asteroid.stroke = 'black';
//this.asteroid.life = 10;
this.asteroidSpeed = 7;
asteroids.push(this.asteroid); */
// this.asteroid.spriteSheet = loadImage('assets/asteroid.png');
this.asteroid = new asteroidGroup.Sprite(x,y, 50);
this.asteroid.img ="assets/asteroid.png"
this.asteroidSpeed = 10;
this.health = 10;
this.experericeAmount = 20;
this.attack = 10;
this.asteroid.damage = (num,x,y)=>{
this.health -=num;
if(this.health <= 0){
removal(asteroids,this.asteroid)
ExpOrb.createExp(x, y, this.experericeAmount)
HealthPack.createHealth(x, y)
}
}
asteroids.push(this.asteroid);
}
/*
movement(){
let x = floor(random(4));
// left side
if(x == 0){
this.asteroid.x = floor(random(-20, 0));
this.asteroid.y = floor(random(0, height));
this.asteroid.vel.x = random(2,this.asteroidSpeed);
this.asteroid.vel.y = random(-this.asteroidSpeed/2,this.asteroidSpeed/2);
}
// top
else if(x ==1){
this.asteroid.x = floor(random(0, width));
this.asteroid.y = floor(random(-20, 0));
this.asteroid.vel.x = random(-this.asteroidSpeed/2,this.asteroidSpeed/2);
this.asteroid.vel.y = random(2,this.asteroidSpeed);
}
// right
else if(x ==2){
this.asteroid.x = floor(random(width, width+20));
this.asteroid.y = floor(random(0, height));
this.asteroid.vel.x = random(-this.asteroidSpeed,2);
this.asteroid.vel.y = random(-this.asteroidSpeed/2,this.asteroidSpeed/2);
}
// bottom
else if(x ==3){
this.asteroid.x = floor(random(0,width));
this.asteroid.y = floor(random(height, height+20));
this.asteroid.vel.x = random(-this.asteroidSpeed/2,this.asteroidSpeed/2);
this.asteroid.vel.y = random(-this.asteroidSpeed,2);
}
}
*/
movement(){
let x = floor(random(4));
// left side
if(x == 0){
this.asteroid.x = floor(random(-20, 0));
this.asteroid.y = floor(random(0, height));
}
// top
else if(x ==1){
this.asteroid.x = floor(random(0, width));
this.asteroid.y = floor(random(-20, 0));
}
// right
else if(x ==2){
this.asteroid.x = floor(random(width, width+20));
this.asteroid.y = floor(random(0, height));
}
// bottom
else if(x ==3){
this.asteroid.x = floor(random(0,width));
this.asteroid.y = floor(random(height, height+20));
}
this.asteroid.moveTowards(random(width/4, 3*width/4), random(height/4, 3*height/4), random(0.005, 0.01))
}
};