-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHpRender.java
39 lines (31 loc) · 1.02 KB
/
HpRender.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
package game.obj;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
public class HpRender {
private final HP hp;
public HpRender(HP hp) {
this.hp = hp;
}
protected void hpRender(Graphics2D g2, Shape shape, double y) {
if (hp.getCurrentHp() != hp.getMAX_HP()) {
double hpY = shape.getBounds().getY() - y - 10;
g2.setColor(new Color(70, 70, 70));
g2.fill(new Rectangle2D.Double(0, hpY, Player.PLAYER_SIZE, 2));
g2.setColor(new Color(253, 91, 91));
double hpSize = hp.getCurrentHp() / hp.getMAX_HP() * Player.PLAYER_SIZE;
g2.fill(new Rectangle2D.Double(0, hpY, hpSize, 2));
}
}
public boolean updateHP(double cutHP) {
hp.setCurrentHp(hp.getCurrentHp() - cutHP);
return hp.getCurrentHp() > 0;
}
public double getHP() {
return hp.getCurrentHp();
}
public void resetHP() {
hp.setCurrentHp(hp.getMAX_HP());
}
}