-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.java
55 lines (39 loc) · 865 Bytes
/
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
import java.awt.*;
public class Bullet{
//field
private double x;
private double y;
private int r;
private double dx;
private double dy;
private double rad;
private double speed;
private Color color1;
//constructor
public Bullet(double angle,int x,int y){
this.x=x;
this.y=y;
r=4;
rad=Math.toRadians(angle);
speed=10;
dx=Math.cos(rad)*speed;
dy=Math.sin(rad)*speed;
color1=Color.YELLOW;
}
//function
public double getx(){return x;}
public double gety(){return y;}
public double getr(){return r;}
public boolean update(){
x+=dx;
y+=dy;
if(x<-r||x>GamePanel.WIDTH+r||y<-r||y>GamePanel.HEIGHT+r){
return true;
}
return false;
}
public void draw(Graphics2D g){
g.setColor(color1);
g.fillOval((int)(x-r),(int)(y-r),2*r,2*r);
}
}