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!!!! :)
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 | 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 ); } } |
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 46 47 48 49 50 51 52 53 54 55 56 57 | 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() { } } |