forked from APCSLowell/AsteroidsGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsteroid.pde
84 lines (84 loc) · 2.83 KB
/
Asteroid.pde
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
public class Asteroid extends Floater
{
int topSide=(int)(Math.random()*2+1);
int leftRight=(int)(Math.random()*2+1);
int topDown=(int)(Math.random()*2+1);
int dir=(int)random(0,2);
double ray;
float rand=random(1,5);
public Asteroid()
{
//xCorners=new int[]{-1,-2,-2,-6,-6,-14,-14,-15,-15,-16,-16,-17,-17,-16,-16,-15,-15,-14,-14,-5,-5,-3,-3,-2,-2,2,2,3,3,5,5,14,14,15,15,16,16,17,17,16,16,15,15,14,14,6,6,2,2,1};
//yCorners=new int[]{20,1,2,2,1,1,2,2,15,15,2,2,-10,-10,-11,-11,-10,-10,-9,-11,-16,-16,-10,-9,-11,-11,-9,-10,-16,-16,-11,-9,-10,-10,-11,-11,-10,-10,2,2,15,15,2,2,1,1,2,2,1,20};
yCorners=new int[]{-10,-9,-9,-5,-4,-4,-3,-3,-1,1,3,3,4,4,5,9,9,10,10,9,9,5,4,3,1,-1,-3,-4,-5,-9,-9,-10};
xCorners=new int[]{8,8,1,1,3,7,7,4,5,5,4,7,7,3,1,1,8,8,-8,-8,-1,-1,-3,-4,-5,-5,-4,-3,-1,-1,-8,-8};
corners=Math.min(xCorners.length, yCorners.length);
myColor=color(255,255,255);
if(topSide==0)
{
myCenterX=(int)(Math.random()*990+5);
myCenterY=0;
}
myCenterY=(int)(Math.random()*990+5);
// myDirectionX=(int)(Math.random()*5+1);
// myDirectionY=(int)(Math.random()*5+1);
if(dir==0)
{
myPointDirection=random(5,85);
}else if(dir==1)
{
myPointDirection=random(275,355);
}
ray=(myPointDirection*(Math.PI/180));
myDirectionX=(rand)*Math.cos(ray);
myDirectionY=(rand)*Math.sin(ray);
}
public void setX(int x){myCenterX=x;}
public int getX(){return (int)myCenterX;}
public void setY(int y){myCenterY=y;}
public int getY(){return (int)myCenterY;}
public void setDirectionX(double x){myDirectionX=x;}
public double getDirectionX(){return myDirectionX;}
public void setDirectionY(double y){myDirectionY=y;}
public double getDirectionY(){return myDirectionY;}
public void setPointDirection(int degrees){myPointDirection=degrees;}
public double getPointDirection(){return myPointDirection;}
public void move()
{
super.move();
}
public void appear()
{
if(topSide==1)
{
myCenterX=(int)(Math.random()*990+5);
if(topDown==1)
{
myCenterY=0;
}else if(topDown==2)
{
myCenterY=1000;
}
}else if(topSide==2)
{
if(leftRight==1)
{
myCenterX=0;
}else if(leftRight==2)
{
myCenterX=1000;
}
myCenterY=(int)(Math.random()*990+5);
}
}
public boolean cloDet(int box, int boy)
{
//ALERT! You can use operator overiding for this and bomDet()
return dist(box, boy, (float)myCenterX, (float)myCenterY)<=20;
}
public boolean bomDet(int box, int boy, int sphe)
{
//if(dist(box, boy, this.getX(), this.getY())>sphe+5||dist(box, boy, this.getX(), this.getY())<sphe-5)
return dist(box, boy, (float)myCenterX, (float)myCenterY)<=sphe;
}
}