Hey, I woud like to draw a Health bar in form of an Orb like seen in the Diablo games
Is it possible to draw an Oval and fill it vertically to a certain extent or is there any other way I can achieve this?
Thanks in advance.
//check for every pixel, x and y
if (<distance to middle> < <radius of orb> && y > <image height> - 1 - currentHealth/fullHealth)
{
//fill this pixel
}//image 1 create rectangle based on current health vs. full health //image 2 create the orb //image 3 fill all pixels which are filled in both image1 and image2
import greenfoot.*;
public class OrbHealth extends Actor
{
static final int SIZE = 80;
int health = 100;
GreenfootImage orb;
public OrbHealth(Color color)
{
orb = new GreenfootImage(SIZE, SIZE);
orb.setColor(color);
orb.fillOval(0, 0, SIZE, SIZE);
updateImage();
}
private void updateImage()
{
GreenfootImage img = new GreenfootImage(SIZE, SIZE);
int cutSize = SIZE*health/100;
if (cutSize > 0)
{
GreenfootImage cutImg = new GreenfootImage(SIZE, cutSize);
cutImg.drawImage(orb, 0, cutImage.getHeight()-SIZE);
img drawImage(cutImg, 0, SIZE-cutSize);
}
setImage(img);
}
public void adjustHealth(int change)
{
health += change;
if (health > 100) health = 100;
if (health < 0) health = 0;
updateImage();
}
public int getHealth()
{
return health;
}
}