I am trying to implement a different score depending on if my asteroid is completely cleared or of it has been split into smaller pieces. I have reviewed the forum and saw a few similar discussions, however I do not understand how to do this. In the asteroid game, I have it set to score 25 points every time an asteroid is broken up or cleared.
How can I make it so that a cleared asteroid will yield 25 points while if it is split up it will only give you 10. I have tried putting it into the if statement but not sure why it is not working. thanks for your help.
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
/**
* A rock in space
*
* @author Poul Henriksen
*/
public class Asteroid extends SmoothMover
{
/** Size of this asteroid */
private int size;
/** When the stability reaches 0 the asteroid will explode */
private int stability;
public Asteroid()
{
this(50);
}
public Asteroid(int size)
{
super(new Vector(Greenfoot.getRandomNumber(360), 2));
setSize(size);
}
public Asteroid(int size, Vector speed)
{
super(speed);
setSize(size);
}
public void act()
{
move();
intersecting();
}
/**
* Set the size of this asteroid. Note that stability is directly
* related to size. Smaller asteroids are less stable.
*/
public void setSize(int size)
{
stability = size;
this.size = size;
GreenfootImage image = getImage();
image.scale(size, size);
}
/**
* Return the current stability of this asteroid. (If it goes down to
* zero, it breaks up.)
*/
public int getStability()
{
return stability;
}
/**
* Hit this asteroid dealing the given amount of damage.
*/
public void hit(int damage) {
stability = stability - damage;
if(stability <= 0)
breakUp ();
}
/**
* Break up this asteroid. If we are still big enough, this will create two
* smaller asteroids. If we are small already, just disappear.
*/
private void breakUp()
{
((Space)getWorld()).countScore();
Greenfoot.playSound("Explosion.wav");
if(size <= 16)
{
getWorld().removeObject(this);
}
else
{
int r = getMovement().getDirection() + Greenfoot.getRandomNumber(45);
double l = getMovement().getLength();
Vector speed1 = new Vector(r + 60, l * 1.2);
Vector speed2 = new Vector(r - 60, l * 1.2);
Asteroid a1 = new Asteroid(size/2, speed1);
Asteroid a2 = new Asteroid(size/2, speed2);
getWorld().addObject(a1, getX(), getY());
getWorld().addObject(a2, getX(), getY());
a1.move();
a2.move();
getWorld().removeObject(this);
}
}
public void intersecting() {
Actor rocket = getOneIntersectingObject(Rocket.class);
if(rocket != null) {
Actor Explosion = new Explosion();
getWorld().addObject(Explosion,getX(), getY());
((Space)getWorld()).gameOver();
Greenfoot.playSound("MetalExplosion.wav");
getWorld().removeObject(rocket);
getWorld().removeObject(this);
}
}
}
