-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBird.java
More file actions
144 lines (108 loc) · 3.36 KB
/
Bird.java
File metadata and controls
144 lines (108 loc) · 3.36 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class Bird {
/*
* From the basis of this class you should implement a working
* Bird robot.
* You will need to decide how to finish these methods as well as what fields
* to provide.
*
*/
private Canvas canvas; // private field reference to a canvas object
//private CartesianCoordinate posBird = new CartesianCoordinate ( 300, 400 );
CartesianCoordinate posStart = new CartesianCoordinate( 400, 300 );
CartesianCoordinate posEnd = new CartesianCoordinate ( 0, 0 );
double direction;
private int penUse;
CartesianCoordinate position;
public Bird(Canvas canvas) {
this.canvas = canvas;
int spawnX = Utils.randomInt(800);
int spawnY = Utils.randomInt(600);
CartesianCoordinate spawnLocation = new CartesianCoordinate ( spawnX, spawnY );
this.posStart = spawnLocation;
this.posEnd = posEnd;
this.direction = direction;
this.penUse = penUse;
this.position = position;
}
public void putPenUp() {
penUse = 0;
}
public void putPenDown() {
penUse = 1;
}
public void turn(double angle) {
this.direction = Math.toRadians(angle) + this.direction;
//this.direction %= 2*Math.PI;
}
public double getTurn(){
return this.direction;
}
public void resetTurn ()
{
this.direction = 0;
}
public void move(double pixels) {
if ( penUse == 1 )
{
posEnd.setX( posStart.getX() + Math.cos(this.direction) * pixels );
posEnd.setY( posStart.getY() - Math.sin(this.direction) * pixels );
canvas.drawLineBetweenPoints( posStart, posEnd );
posStart.setX(posEnd.getX());
posStart.setY(posEnd.getY());
}
else
{
posEnd.setX( posStart.getX() + Math.cos(this.direction) * pixels );
posEnd.setY( posStart.getY() - Math.sin(this.direction) * pixels );
posStart.setX(posEnd.getX());
posStart.setY(posEnd.getY());
}
}
public void setStart(CartesianCoordinate Start)
{
this.posStart = Start;
}
public void draw()
{
this.putPenDown();
for ( int i = 1; i <= 3; i++)
{
this.turn(-120);
this.move(12);
}
//this.direction = 0;
}
public void undraw ()
{
for ( int i = 1; i <= 3; i++ )
{
canvas.removeMostRecentLine();
}
}
public double getPositionX()
{
double BirdPosX;
BirdPosX = this.posStart.getX();
return BirdPosX;
}
public double getPositionY()
{
double BirdPosY;
BirdPosY = this.posStart.getY();
return BirdPosY;
}
public CartesianCoordinate getPosition(){
double i = this.getPositionX();
double j = this.getPositionY();
this.position = new CartesianCoordinate(i,j);
return this.position;
}
public double getDistance(Bird A,Bird B){
double APosX = A.getPositionX();
double APosY = A.getPositionY();
double BPosX = B.getPositionX();
double BPosY = B.getPositionY();
double distance = Math.sqrt(Math.pow(APosX-BPosX,2) + Math.pow(APosY-BPosY,2));
return distance;
}
}