-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBullet.java
76 lines (62 loc) · 1.73 KB
/
Bullet.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
package game.obj;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
public class Bullet {
private double x;
private double y;
private final Shape shape;
private final Color color = new Color(255, 255, 255);
private final float angle;
private double size;
private float speed = 1f;
public Bullet(double x, double y, float angle, double size, float speed) {
x += Player.PLAYER_SIZE / 2 - (size / 2);
y += Player.PLAYER_SIZE / 2 - (size / 2);
this.x = x;
this.y = y;
this.angle = angle;
this.size = size;
this.speed = speed;
shape = new Ellipse2D.Double(0, 0, size, size);
}
public void update() {
x += Math.cos(Math.toRadians(angle)) * speed;
y += Math.sin(Math.toRadians(angle)) * speed;
}
public boolean check(int width, int height) {
if (x <= -size || y < -size || x > width || y > height) {
return false;
} else {
return true;
}
}
public void draw(Graphics2D g2) {
AffineTransform oldTransform = g2.getTransform();
g2.setColor(color);
g2.translate(x, y);
g2.fill(shape);
g2.setTransform(oldTransform);
}
public Shape getShape() {
return new Area(new Ellipse2D.Double(x, y, size, size));
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getSize() {
return size;
}
public double getCenterX() {
return x + size / 2;
}
public double getCenterY() {
return y + size / 2;
}
}