-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.java
253 lines (217 loc) · 6.2 KB
/
Point.java
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import java.awt.Color;
import java.io.*;
import java.util.*;
import java.awt.Graphics;
class Point implements java.io.Serializable{
public long creationTime;
public double masterSpeed;
public double refreshTime;
public int x;
public int y;
public double trueX;
public double trueY;
private int fromOriginX;
private int fromOriginY;
public int previousX;
public int previousY;
public double vectorX;
public double vectorY;
private int ogDiameter;
public int diameter;
public Color color;
public Point(int x, int y, int diameter, Color color){
refreshTime = CircleOrbitMouse.refreshTime;
masterSpeed = CircleOrbitMouse.masterSpeed;
creationTime = CircleOrbitMouse.myTimerThread.myClock.millis();
this.x=x;
this.y=y;
trueX = x;
trueY = y;
previousX = x;
previousY = y;
fromOriginX = x;
fromOriginY =y;
this.diameter=diameter;
ogDiameter = diameter;
this.color = color;
vectorX = 0;
vectorY= 0;
}
public int getDiameter(){
return(this.diameter);
}
public int getOgDiameter(){
return(this.ogDiameter);
}
public void setDiameter(int newDiameter){
diameter=newDiameter;
}
public void camera(boolean north, boolean east, boolean south, boolean west, int playerVectorX, int playerVectorY){
if(north){
changeXY(0,-playerVectorY);
}
if(east){
changeXY(-playerVectorX,0);
}
if(south){
changeXY(0,-playerVectorY);
}
if(west){
changeXY(-playerVectorX,0);
}
}
public int getX(){
return x;
}
public void changeXY(double addX, double addY){
trueX += addX;
trueY += addY;
this.x = (int)(Math.round(trueX));
this.y = (int)(Math.round(trueY));
}
public void changeFromOriginXY(double addX, double addY){
fromOriginX+=addX;
fromOriginY+=addY;
}
public int getFromOriginX(){
return fromOriginX;
}
public int getFromOriginY(){
return fromOriginY;
}
public void setXY(double theX, double theY){
trueX = theX;
trueY = theY;
this.x =(int)(Math.round(trueX));
this.y =(int)(Math.round(trueY));
}
public void setX(double x){
trueX = x;
this.x = (int)(Math.round(trueX));
}
public int getY(){
return y;
}
public void setY(double y){
trueY = y;
this.y = (int)(Math.round(trueY));
}
//@Override
public void drawIt(Graphics g){
g.drawLine(100,100,500,500);
}
public void setVector(double vectorX, double vectorY ){
this.vectorX=vectorX;
this.vectorY=vectorY;
}
public void go(){
changeXY(vectorX, vectorY);
}
public void changeVector(double vectorChangeX, double vectorChangeY){
this.vectorX += vectorChangeX;
this.vectorY += vectorChangeY;
}
public int getXVector(){
return((int)this.vectorX);
}
public int getYVector(){
return((int)(this.vectorY));
}
public Color getColor(){
return color;
}
public void setItsColor(Color nColor){
color = nColor;
}
public void increaseDiameter(double change){
diameter = (int)(diameter*change);
}
public void updateVector(){
}
public String toString(){
String str = "" + x + ", " + y;
return str;
}
public void drawACircle(Graphics g){
g.setColor(color);
g.fillOval(x, y, diameter, diameter);
}
public double rotateXVector(double xv, double yv, double angle){
angle = fixAngle(angle);
double hypotenuse = findDistance(0,0,xv, yv);
//double adjacent = xv/hypotenuse;
//double opposite = yv/hypotenuse;
double ogAngle = findAngle(xv,yv);
ogAngle = fixAngle(ogAngle);
if(angle == Math.PI/2){
return hypotenuse*Math.cos(Math.PI/2+ogAngle);
}
if(angle == 3*Math.PI/2){
double rstuff = -hypotenuse*Math.cos(Math.PI/2+ogAngle);
//System.out.println(rstuff/simpleEnemySpeed);
return rstuff;
}
double newCos;
//double newAngle = adjacent*Math.cos(angle) - opposite*Math.sin(angle);
newCos = Math.cos(ogAngle+angle);
return newCos*hypotenuse;
}
public double rotateYVector(double xv, double yv, double angle){
angle = fixAngle(angle);
double hypotenuse = findDistance(0,0,xv, yv);
//double adjacent = xv/hypotenuse;
//double opposite = yv/hypotenuse;
double newSin;
double ogAngle = findAngle(xv,yv);
ogAngle = fixAngle(ogAngle);
if(angle == Math.PI/2){
return hypotenuse*Math.sin(Math.PI/2-ogAngle);
}
if(angle == 3*Math.PI/2){
return hypotenuse*Math.sin(Math.PI/2-ogAngle);
}
//double newAngle = opposite*Math.cos(angle)+ adjacent*Math.sin(angle);
newSin = Math.sin(ogAngle+angle);
//System.out.println(newSin);
return newSin*hypotenuse;
}
public double fixAngle(double angle){
while(angle<0){
angle+= 2*Math.PI;
}
angle %= 2*Math.PI;
return angle;
}
public double breakAngle(double angle){
angle = fixAngle(angle);
if(angle>Math.PI){
angle = angle-(2*Math.PI);
}
return angle;
}
public int shorterWay(double angle1, double angle2){
angle1 = fixAngle(angle1);
angle2 = fixAngle(angle2);
if(angle1-angle2<Math.PI){
return -1;
}else{
return 1;
}
}
public double findAngle(double vx, double vy){
//This one works, and well with rotateXVector and rotateYVector
double distance = findDistance(0,0,vx, vy);
if(distance != 0){
double angle = Math.acos(vx/distance);
if(vy<0){
angle = -angle;
}
angle = fixAngle(angle);
return angle;
}
return 0;
}
public static double findDistance(double x1, double y1, double x2, double y2){
return Math.sqrt((((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1))));
}
}