Hello,
If i made an actor were i made a lifebar and called it in the world class, and i want to remove 1 health if 2 of my other actors hit eachother. wheres the best place to write this code? in the world or actor class? This is my health class (thanks to DanPost) if its necessary to know.
thanks in advance!
public class heart extends Actor
{
public static final boolean HORIZONTAL = false;
private static final int GAP = 10;
private boolean orientation = HORIZONTAL;
private GreenfootImage icon;
private int count;
private boolean direction;
private int initValue;
private int value;
public vie()
{
icon = new GreenfootImage("viegr.png");
count = 3;
direction = false;
value = initValue = count;
orientation = direction;
updateImage();
}
private void updateImage()
{
int across = value;
int down = 1;
int xGap = GAP;
int yGap = 0;
if (orientation == VERTICAL)
{
across = 1;
down = value;
xGap = 0;
yGap = GAP;
}
int wide = icon.getWidth()*across+xGap*(across+1);
int high = icon.getHeight()*down+yGap*(down+1);
GreenfootImage base = new GreenfootImage(wide, high);
for (int j=0; j<down; j++) for (int i=0; i<across; i++)
{
int xOffset =xGap+i*(xGap+icon.getWidth());
int yOffset = yGap+j*(yGap+icon.getHeight());
base.drawImage(icon, xOffset, yOffset);
}
setImage(base);
}
public void adjustValue(int change)
{
if (value+change > initValue || value + change < 0) return;
value += change;
updateImage();
}
public int getValue()
{
return value;
}
