-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicBullet.java
58 lines (43 loc) · 1.05 KB
/
BasicBullet.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
package Enemies;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Random;
import Game.main.*;
public class BasicBullet extends GameObject{
private Handler handler;
private Random r = new Random();
private Color color;
public BasicBullet(float x, float y, ID id, Color color, Handler handler){
super(x, y, id);
this.handler = handler;
this.color = color;
velX = (r.nextInt(7 - -7) + -7);
velY = 7;
vel[0] = velX;
vel[1] = velY;
}
public Rectangle getBounds(){
return new Rectangle((int)x, (int)y, 16, 16);
}
public void tick(){
x += velX;
y += velY;
if(y >= Game.HEIGHT + 16) handler.removeObject(this);
handler.addObject(new Trail(x, y, ID.Trail, color, 16, 16, 0.06f, handler));
}
public void render(Graphics g){
g.setColor(color);
g.fillRect((int)x, (int)y, 16, 16);
}
public void hide(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect((int)x, (int)y, 16, 16);
velX = 0;
velY = 0;
}
public void restoreVel(){
velX = vel[0];
velY = vel[1];
}
}