Hi, so I have a program that is basically code from the Rocket ship tutorial one. I added SpaceWombats to attack the Rocket but the game will not stop when the Wombat gets to the Rocket.
import greenfoot.*;
/**
* Write a description of class SpaceWombat here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SpaceWombat extends Actor
{
public void act()
{
if(Greenfoot.getRandomNumber(100) < 10)
turn(Greenfoot.getRandomNumber(90) - 45 );
if(getX() <= 10 || getX() >= getWorld().getWidth() - 10){
turn(180); move(2);}
move(4);
}
public void hitrocket () {
Space spaceWorld = (Space) getWorld();
}
public void touch() { if (isTouching(Rocket.class))
{
Greenfoot.stop();
getWorld().removeObject(this);
getWorld().removeObject(this);
Greenfoot.stop();
}
}
public void rocket ()
{
int ypos = getY();
if (ypos > 0) {
ypos = ypos - 5;
setLocation(getX(), ypos);
Actor Rocket = getOneIntersectingObject(Rocket.class);
if (Rocket != null) {
hitrocket();
getWorld().removeObject(Rocket);
getWorld().removeObject(this);
Greenfoot.stop();
}
else {
getWorld().removeObject(this);
Greenfoot.stop();
}
}
}
}
