-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2ManaBar.java
45 lines (40 loc) · 1.1 KB
/
p2ManaBar.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class p2ManaBar here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class p2ManaBar extends Resources
{
int mana = 50;
int manaBarWidth = 250;
int manaBarHeight = 5;
int pixelsPerManaPoint = (int)manaBarWidth/mana;
public p2ManaBar(){
update();
}
public void act()
{
update();
}
/**
* Removes pixels from the manabar
*/
public void update(){
setImage(new GreenfootImage(manaBarWidth + 2, manaBarHeight + 2));
GreenfootImage myImage = getImage();
myImage.setColor(Color.WHITE);
myImage.drawRect(0, 0, manaBarWidth + 1, manaBarHeight + 1);
myImage.setColor(Color.CYAN);
myImage.fillRect(1, 1, mana*pixelsPerManaPoint, manaBarHeight);
myImage.mirrorHorizontally();
}
public void loseMana(){
mana = mana - 15;
}
public void gainMana(){
mana++;
}
}