-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBullet.java
More file actions
41 lines (34 loc) · 809 Bytes
/
Copy pathBullet.java
File metadata and controls
41 lines (34 loc) · 809 Bytes
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
import java.awt.*;
public class Bullet {
private double x, y, rad, speed, dx, dy;
private int r;
private Color color;
public Bullet (double angle, int x, int y) {
this.x = x;
this.y = y;
r = 5;
rad = Math.toRadians(angle);
speed = 10;
dx = Math.cos(rad) * speed;
dy = Math.sin(rad) * speed;
color = Color.YELLOW;
}
// Render methods
public boolean update () {
x += dx;
y += dy;
// Validating if let frame
if (x < -r || x > SpacePanel.width + r || y > SpacePanel.height + r)
return true;
return false;
}
public void draw (Graphics2D g) {
g.setColor(color);
g.fillOval((int) (x - r) - 10, (int) (y - r) - 15, 2 * r, 2 * r);
}
// Setters
// Getters
public double getX () {return x;}
public double getY () {return y;}
public double getR () {return r;}
}