Hello,
I am making a tower defence game and have a score and health counter, these are just text with a variable, i have a mehod within the class that adds or subtracts the variable.
I am trying to call this from another class but can't at the moment,
Probably something really simple (am used to vb6 but completely new to java, a big change)
Here is the Code:
Score Counter:
And I am trying to call minusHealth() in the health() method in the Enemy class;
Thank you for any help!!!! :)
public class ScoreCounter extends Actor
{
private int score;
public ScoreCounter()
{
score = 0;
setImage(new GreenfootImage(200, 30));
update();
}
public void addScore()
{
score++;
update();
}
public void update()
{
GreenfootImage img = getImage();
img.clear();
img.setColor(Color.WHITE);
img.drawString("Score: " + score, 4, 20);
}
}
public class Enemy extends Actor
{
private int enemyDelayCount;
private Weapon weapon;
public World myWorld;
public void act()
{
followPath();
//if the enemy gets to the end, minus a life and remove the enemy.
if (getX() >= getWorld().getWidth() - 10)
{
removeEnemy();
health();
}
}
private void followPath()
{
/**
* making the enemy follow the correct path
*/
if (getX() < 93 )
{
setRotation(50);
move(1);
}
if (getX() >= 93 && getX() < 284)
{
setRotation(0);
move (1);
}
if (getX() >= 284 && getX() < 368)
{
setRotation (325);
move (1);
}
if (getX() >= 368 && getX() < 595)
{
setRotation (405);
move(1);
}
}
private void removeEnemy()
{
World world;
world = getWorld();
world.removeObject(this);
}
public void health()
{
}
}

