I'm having a bit of an issue with a Space Invaders game that I have to make for school. All three of my aliens add 50 points to the score, when I want them to all add different values. Can anyone help me with this?
My first alien's code (parent):
My second alien's code (child):
My third alien's code (child):
My score actor's code:
import greenfoot.*; public class Alien1 extends Actor { int points = 50; int wait; int moving = 10; int moveTimer = 60; int shoot; public void act() { wait++; if (isTouching(PlayerBullet.class)) { removeTouching(PlayerBullet.class); Greenfoot.playSound("destroy.mp3"); ScoreCounter counter = getWorld().getObjects(ScoreCounter.class).get(0); counter.score = counter.score + points; getWorld().removeObject(this); } if(wait == 20) { wait = 0; movement(); shoot(); } } public void movement() { moveTimer--; if (moveTimer >= 30) { move(moving); } if (moveTimer <= 30) { move(-moving); } if (moveTimer == -1) { moveTimer = 61; } if (moveTimer == 0) { moving = 0; } if (moveTimer == 30) { setLocation(getX(), getY()+25); } if (moveTimer == 61) { setLocation(getX(), getY()+25); moving = 10; } } public void shoot() { if (Greenfoot.getRandomNumber(29) == 1) { getWorld().addObject(new AlienBullet(), getX(), getY()-1); Greenfoot.playSound("shoot.mp3"); } } }
import greenfoot.*; public class Alien2 extends Alien1 { int points = 25; }
import greenfoot.*; public class Alien3 extends Alien1 { int points = 10; }
import greenfoot.*; public class ScoreCounter extends Actor { int score = 0; public void act() { setImage(new GreenfootImage("Score: "+score,25,Color.WHITE,Color.BLACK)); } }