-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2HealthBar.java
40 lines (37 loc) · 1.03 KB
/
p2HealthBar.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
import greenfoot.*;
import java.awt.Color;
/**
* Write a description of class p2HealthBar here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class p2HealthBar extends Resources
{
int health = 50;
int healthBarWidth = 300;
int healthBarHeight = 15;
int pixelsPerHealthPoint = (int)healthBarWidth/health;
public p2HealthBar(){
update();
}
public void act()
{
update();
}
/**
* Removes pixels from the healthbar
*/
public void update(){
setImage(new GreenfootImage(healthBarWidth + 2, healthBarHeight + 2));
GreenfootImage myImage = getImage();
myImage.setColor(Color.WHITE);
myImage.drawRect(0, 0, healthBarWidth + 1, healthBarHeight + 1);
myImage.setColor(Color.GREEN);
myImage.fillRect(1, 1, health*pixelsPerHealthPoint, healthBarHeight);
myImage.mirrorHorizontally();
}
public void loseHealth(){
health--;
}
}