-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicEnemy.java
64 lines (45 loc) · 1.17 KB
/
BasicEnemy.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
package Enemies;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import Game.main.*;
public class BasicEnemy extends GameObject{
private Handler handler;
private Color color;
public BasicEnemy(float x, float y, ID id, Color color, Handler handler){
super(x, y, id);
this.handler = handler;
this.color = color;
velX = 6;
velY = 6;
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 <= 0 || y >= Game.HEIGHT - 42) velY *= -1;
if(x <= 0 || x >= Game.WIDTH - 20) velX *= -1;
vel[0] = velX;
vel[1] = velY;
handler.addObject(new Trail(x, y, ID.Trail, color, 16, 16, 0.02f, 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];
}
//handler.addObject(new BasicEnemy(r.nextInt(Game.WIDTH - 20), r.nextInt(Game.HEIGHT - 42), ID.Enemy, Color.red, handler));
}