-
Notifications
You must be signed in to change notification settings - Fork 1
/
OtherFish.java
132 lines (119 loc) · 2.89 KB
/
OtherFish.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
package FunFish;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
public class OtherFish
{
public static OtherFish otherFish;
public static Point2D.Double oFish;
public static double oSpeed, oFishR;
public OtherFish(Double oFish, double oSpeed, double oFishR)
{
this.oFish = oFish;
//double p = (int) Math.ceil(Math.random()*80);
//oFish.x = p;
this.oSpeed = oSpeed;
double q = (int) Math.ceil(Math.random()*8);
oFishR = q;
this.oFishR = oFishR;
}
public void otherFishMove()
{
if(MainFish.level == 1)
oFish.y += oSpeed;
else if(MainFish.level == 2)
oFish.x += oSpeed;
else if(MainFish.level == 3)
{
if(MainFish.numSmallFish % 2 == 0)
{
oFish.y += oSpeed;
}
if(MainFish.numSmallFish % 2 == 1)
{
oFish.x += oSpeed;
}
}
else if(MainFish.level == 4)
{
if(MainFish.numSmallFish % 4 == 0)
{
oFish.y += oSpeed;
}
else if(MainFish.numSmallFish % 4 == 1)
{
oFish.x += oSpeed;
}
else if(MainFish.numSmallFish % 4 == 2)
{
oFish.y -= oSpeed;
}
else if(MainFish.numSmallFish % 4 == 3)
{
oFish.x -= oSpeed;
}
}
}
public static boolean eatOtherFish()
{
if(Math.pow(oFishR + MainFish.mainFish.getFishR(), 2) > Math.pow(MainFish.mainFish.getFishX() - oFish.x, 2) + Math.pow(MainFish.mainFish.getFishY() - oFish.y, 2))
{
MainFish.mainFish.eaten = true;
return true;
}
else
{
MainFish.mainFish.eaten = false;
return false;
}
}
public static OtherFish generateOtherFish()
{
if(MainFish.level == 1)
{
otherFish = new OtherFish(new Point2D.Double(Math.ceil(Math.random()*80), 1.0), 1.0, 3.0);
return otherFish;
}
else if(MainFish.level == 2)
{
otherFish = new OtherFish(new Point2D.Double(1, Math.ceil(Math.random()*65)), 1.0, 3.0);
return otherFish;
}
else if(MainFish.level == 3)
{
if(MainFish.numSmallFish % 2 == 0)
{
otherFish = new OtherFish(new Point2D.Double(1, Math.ceil(Math.random()*65)), 1.0, 3.0);
return otherFish;
}
else if(MainFish.numSmallFish % 2 == 1)
{
otherFish = new OtherFish(new Point2D.Double(Math.ceil(Math.random()*80), 1.0), 1.0, 3.0);
return otherFish;
}
}
else if(MainFish.level == 4)
{
if(MainFish.numSmallFish % 4 == 0)
{
otherFish = new OtherFish(new Point2D.Double(Math.ceil(Math.random()*80), 1), 1.0, 3.0);
return otherFish;
}
else if(MainFish.numSmallFish % 4 == 1)
{
otherFish = new OtherFish(new Point2D.Double(1, Math.ceil(Math.random()*65)), 1.0, 3.0);
return otherFish;
}
else if(MainFish.numSmallFish % 4 == 2)
{
otherFish = new OtherFish(new Point2D.Double(Math.ceil(Math.random()*80), 65), 1.0, 3.0);
return otherFish;
}
else if(MainFish.numSmallFish % 4 == 3)
{
otherFish = new OtherFish(new Point2D.Double(80, Math.ceil(Math.random()*65)), 1.0, 3.0);
return otherFish;
}
}
return otherFish;
}
}