-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBullet.java
83 lines (64 loc) · 1.55 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
77
78
79
80
81
82
83
package FirstGame;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
public class Bullet {
//Coordinates
private int x;
private int y;
//Vector Components
private double dx;
private double dy;
//Speed
private int speed;
//Radius
private int r;
//Angle
public double angle;
//Bullet Colors
private Color bulletColor;
private Color bulletBoundaryColor;
public Bullet(int angle, int x, int y){
//set coordinates
this.x = x;
this.y = y;
//Set Speed
speed = 10 ;
//set radius
r = 5;
//Set Angle
this.angle = Math.toRadians(angle);
//Set Components
dx = Math.cos(this.angle)*speed;
dy = Math.sin(this.angle)*speed;
//Set Bullet Color
bulletColor = Color.YELLOW;
bulletBoundaryColor = bulletColor.darker().darker();
}
public int getx(){return x;}
public int gety(){return y;}
public int getr(){return r;}
public double getAngle(){return angle;}
public boolean update(){
x+= dx;
y+= dy;
//Return Condition of out of Frame
if(x > GamePanel.WIDTH-r || y > GamePanel.HEIGHT-r || x < -r || y < -r) return true;
//Return Default
return false;
}
public void draw(Graphics2D g){
//Set Stroke
g.setStroke(new BasicStroke(2));
//Set Color
g.setColor(bulletColor);
//Fill
g.fillOval(x+r, y+r, 2*r, 2*r);
//Boundary
g.setColor(bulletBoundaryColor);
//Draw Boundary
g.drawOval(x+r, y+r, 2*r, 2*r);
//Restore Stroke
g.setStroke(new BasicStroke(1));
}
}