forked from Stanlee101/AsteroidsGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spaceship.pde
70 lines (61 loc) · 1.68 KB
/
Spaceship.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
class Spaceship extends Floater
{
public Spaceship(){
corners = 4; //the number of corners, a triangular floater has 3
xCorners = new int[corners];
yCorners = new int[corners];
xCorners = new int[] {-8, 16, -8, -2};
yCorners = new int[] {-8, 0, 8, 0};
myColor = 255;
myCenterX = 200;
myCenterY = 200; //holds center coordinates
myXspeed = 1;
myYspeed = 1; //holds the speed of travel in the x and y directions
myPointDirection = 0; //holds current direction the ship is pointing in degrees
}
public void move(){
myCenterX += myXspeed;
myCenterY += myYspeed;
//wrap around screen
if(myCenterX >width)
{
myCenterX = 0;
}
else if (myCenterX<0)
{
myCenterX = width;
}
if(myCenterY >height)
{
myCenterY = 0;
}
else if (myCenterY < 0)
{
myCenterY = height;
}
}
public void turn (double degreesOfRotation) {
//rotates the floater by a given number of degrees
myPointDirection+=degreesOfRotation;
}
public void accelerate (double dAmount)
{
//convert the current direction the floater is pointing to radians
double dRadians =myPointDirection*(Math.PI/180);
//change coordinates of direction of travel
myXspeed += ((dAmount) * Math.cos(dRadians));
myYspeed += ((dAmount) * Math.sin(dRadians));
}
public void setXspeed(double x) {
myXspeed = x;
}
public void setYspeed(double y) {
myYspeed = y;
}
public void setCenterX(double x){
myCenterX = x;
}
public void setCenterY(double y){
myCenterY = y;
}
}