-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDot.java
199 lines (176 loc) · 4.39 KB
/
Dot.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
package Galaga.Characters;
/**
* @author Brian @author Peteous
*/
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
public class Dot {
double x, y;
int intx, inty;
int wallx, wally;
double theta;
public double speed = 6.5;
Point location;
Color color = Color.green;
int size = 6;
Image PIC;
boolean active;
public Dot() {
this.color = Color.green;
location = new Point ();
active = false;
}
public Dot(Point p, double direction) {
location = p.getLocation ();
this.intx = p.x;
this.inty = p.y;
x = p.x;
y = p.y;
speed = 6.5;
wallx = 512;
wally = 512;
theta = direction;
active = true;
}
public Dot(int xx, int yy, double direction) {
location = new Point (xx, yy);
this.intx = xx;
this.inty = yy;
x = xx;
y = yy;
speed = 6.5;
wallx = 512;
wally = 512;
theta = direction;
active = true;
}
public Dot(int xx, int yy, double direction, int Size) {
location = new Point (xx, yy);
this.intx = xx;
this.inty = yy;
x = xx;
y = yy;
size = Size;
speed = 6.5;
wallx = 512;
wally = 512;
theta = direction;
active = true;
}
public void createNEW(Point p, int xwall, int ywall, double direction, boolean active) {
intx = (int) Math.round (p.x - (size / 2));
inty = (int) Math.round (p.y - (size / 2));
x = Math.round (p.x - (size / 2));
y = Math.round (p.y - (size / 2));
speed = 6.5;
location = p.getLocation ();
wallx = xwall;
wally = ywall;
theta = direction;
this.active = active;
}
public int getX() {
return intx;
}
public int getY() {
return inty;
}
public int size() {
return size;
}
/**
* updates the location of the bullet
*/
public void update() {
if (this.isActive ()) {
if (checkForWallx ()) {
x += (Math.cos (theta) * this.speed);
} else {
this.speed = 0;
active = false;
}
intx = (int) Math.round (x);
//===============================================
if (checkForWally ()) {
y += (Math.sin (theta) * this.speed);
} else {
this.speed = 0;
active = false;
}
inty = (int) Math.round (y);
}
this.setLocationPoint ();
}
public void deactivate() {
active = false;
}
/* sets the image of this bullet
* @param Image
* @return void */
public void setPIC(Image i) {
PIC = i;
}
/**
* returns the image of this bullet
* @return the Bullet Image
*/
public Image getPIC() {
return PIC;
}
private void setLocationPoint() {
location.setLocation (x, y);
}
private boolean checkForWallx() {
for (int A = 0; A < 4; A++) {
if (((x - size/2) < 512) & ((x + size/2) > 0)) {
return true;
}
}
active = false;
return false;
}
private boolean checkForWally() {//lololol
if (((y - size/2) < 512) & ((y + size/2) > 0)) {
return true;
}
active = false;
return false;
}
/**
* returns the speed at which the bullet should travel
* @return double
*/
public double getSpeed() {
return this.speed;
}
/**
* returns the surrounding rectangle
* @return rectangle(intx, inty, size, size)
*/
public Rectangle getBounds() {
return new Rectangle(intx - size / 2, inty - size / 2, size, size);
}
/**
* returns if bullet is active
* @return boolean
*/
public boolean isActive() {
return active;
}
public void setActive(boolean alive) {
active = alive;
}
/**
*draws image or a red oval
* @param Graphics (such as a buffer)
* @return the image or red oval
*/
public void draw(Graphics e) {
// e.drawImage(PIC, intx, inty, null);
e.setColor(color);
e.fillOval(intx - (int) (size/2), inty - (int) (size/2), size, size);
}
}