-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHealthBar.java
executable file
·77 lines (63 loc) · 2.05 KB
/
HealthBar.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
65
66
67
68
69
70
71
72
73
74
75
76
77
package sample;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class HealthBar{
double health;
GraphicsContext gc;
Character character;
int posX;
int posY;
int direction;
Sprite sprite;
double width;
double maxHealth;
double bullets;
HealthBar (Character character, double health, int posX, int posY, int direction ){
this.health = health;
this.character = character;
this.gc = Game.gc;
this.posX = posX;
this.posY = posY;
this.direction = direction;
maxHealth = health;
bullets =7;
sprite = new Sprite();
if (direction==1)sprite.setImage("healthBar/healthBar1.png");
else sprite.setImage("healthBar/healthBar1Rev.png");
sprite.setPosition(posX,posY);
sprite.width*=15;
sprite.height*=15;
}
public double getHealth() {
return health;
}
public void setHealth(double health) {
this.health = health;
if (this.health<0)this.health=0;
if (this.health>maxHealth)this.health=maxHealth;
}
public void render(){
if (health<maxHealth && health>0){
health+=0.05;
}
if (bullets<7)bullets+=0.01;
width = (health*139)/maxHealth;
Color c;
if (direction==1) {
gc.setFill(new Color(0, 0.4, 1, 1));
gc.fillRect(posX + 10, posY + 20, width, 20);
sprite.render(gc);
c=Color.web("47464e");
gc.setFill(c);
gc.fillRect(posX + 71-(7-Math.floor(bullets))*8.3,posY+35,(7-Math.floor(bullets))*8.3,14);
}
else{
gc.setFill(new Color(0.8, 0.2, 0, 1));
gc.fillRect(posX + 24 + (maxHealth-health)*139/maxHealth, posY + 20, width, 20);
sprite.render(gc);
c=Color.web("47464e");
gc.setFill(c);
gc.fillRect(posX + 102.1,posY+35,(7-Math.floor(bullets))*8.3,14);
}
}
}