-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
54 lines (37 loc) · 1.29 KB
/
Player.java
File metadata and controls
54 lines (37 loc) · 1.29 KB
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
//Kaushik Siruvuri, Ishaan Sharma, Supreet Mishra
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
public class Player extends GameObject {
Random r = new Random();
Handler handler;
private BufferedImage image;
public Player(int x, int y, ID id, Handler handler) {
super(x, y, id);
this.handler = handler;
}
public Rectangle getBounds() {
return new Rectangle((int) x, (int) y, 32, 32);
}
public void tick() {
x += velX;
x = Game.clamp(x, 0, Game.WIDTH - 32);
collision();
}
public void collision() {
for (int i = 0; i < handler.object.size(); i++) {
GameObject tempObject = handler.object.get(i);
if (tempObject.getId() == ID.BasicEnemy || tempObject.getId() == ID.Enemy2 || tempObject.getId() == ID.Enemy3 || tempObject.getId() == ID.EnemyBoss) {
if (getBounds().intersects(tempObject.getBounds())) {
//collision code
HUD.HEALTH -= 1;
}
}
}
}
public void render(Graphics g) {
g.setColor(Color.white);
g.fillRect((int) x, (int) y, 32, 32);
}
}