-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHealthBar.java
More file actions
62 lines (57 loc) · 1.3 KB
/
HealthBar.java
File metadata and controls
62 lines (57 loc) · 1.3 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
55
56
57
58
59
60
61
62
import greenfoot.*;
/**
* Write a description of class HealthBar here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class HealthBar extends Actor
{
GreenfootImage bar;
public HealthBar(Character player)
{
super();
setHealthImage(player);
bar = new GreenfootImage(getHealthPath(player));
bar.scale(150, 40);
setImage(bar);
}
/**
* Adjust the healthbar image for the player.
*/
public void setHealthImage(Character player)
{
bar = new GreenfootImage(getHealthPath(player));
bar.scale(150, 40);
setImage(bar);
}
/**
* Get path for new health bar image.
*/
public String getHealthPath(Character player)
{
int health = player.getHealthPercent();
int barNum = -1;
int temp;
String newPath = "";
temp = health % 4;
if (temp == 0)
{
barNum = health;
}
else if (temp == 1)
{
barNum = health + 3;
}
else if (temp == 2)
{
barNum = health + 2;
}
else
{
barNum = health + 1;
}
newPath = "images/hpbar/hp_" + barNum + "%.png";
return newPath;
}
}