I Have a old code of breaking a actor up in smaller ones, but a would like it to break up to other images.
there is alot of things in the code from the old game that have to change or removed. so I hoped that someone would take a look at it
thanks in advance
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Asteroid here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Asteroid extends Mover
{
int health = 50;
public void act()
{
move (4);
setRotation(90);
}
/**
* Hit this asteroid dealing the given amount of damage.
*/
public void hit(int damage)
{
health = health - damage;
if(health <= 0)
{
//Cyberspace.countScore(10);
breakUp();
}
}
/**
* Break up this Asteroid. If we are still big enough, this will create small ones
*/
private void breakUp()
{
if(health <= 0)
{
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);
}
}
}

