forked from scnerd/Purebread-Ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HealthDisplay.java
executable file
·51 lines (45 loc) · 1.61 KB
/
HealthDisplay.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class HealthDisplay here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class HealthDisplay extends VisibleActor
{
private CameraViewableWorld world;
private int x_offset;
private int y_offset;
private int old_health = 5;
public HealthDisplay()
{
this.setImage(new GreenfootImage("BreadNinjaHealth1.png"));
}
public void act()
{
if (world == null)
{
world = (CameraViewableWorld)getWorld();
x_offset = world.getWidth() / 2 - 60;
y_offset = world.getHeight() / 2 - 60;
}
int health = ((Player)getWorld().getObjects(Player.class).get(0)).health;
if (old_health != health)
{
old_health = health;
switch (health) {
case 5: this.setImage(new GreenfootImage("BreadNinjaHealth1.png"));
break;
case 4: this.setImage(new GreenfootImage("BreadNinjaHealth2.png"));
break;
case 3: this.setImage(new GreenfootImage("BreadNinjaHealth3.png"));
break;
case 2: this.setImage(new GreenfootImage("BreadNinjaHealth4.png"));
break;
case 1: this.setImage(new GreenfootImage("BreadNinjaHealth5.png"));
break;
}
}
setLocation(world.getCameraX() - x_offset, world.getCameraY() - y_offset);
}
}