This is my code. The reason why I have been using this thread because I've genuinely been told off for making different threads when others have similar issues by who I think was a mod lmao. Here's my code, this has the change world code in:
import greenfoot.*;
/**
* Write a description of class Plane here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Plane extends Actor
{
/**
* shrinking plane size
*/
public Plane()
{
GreenfootImage image = getImage();
image.scale(image.getWidth() - 60, image.getHeight() - 60);
setImage(image);
}
private Counter counter;
/**
* adding up-down controlls and if the actor touches the right side they will go to a random world
*/
public void act()
{
{
setRotation(0);
move(2);
}
if (Greenfoot.isKeyDown("Up"))
{
setRotation(-20);
move(2);
}
if (Greenfoot.isKeyDown("Down"))
{
setRotation(50);
move(2);
}
if (getX() == getWorld().getWidth()-1)
{
if (Greenfoot.getRandomNumber(3)==0)
{
Greenfoot.setWorld(new SkyEnemy());
}
if (Greenfoot.getRandomNumber(3)==1)
{
Greenfoot.setWorld(new SkyEnemyTwo());
}
if (Greenfoot.getRandomNumber(3)==2)
{
Greenfoot.setWorld(new SkyEnemyThree());
}
}
/**
* plane can collect ball, play sound and add 1 to counter
*/
Actor Ball = getOneObjectAtOffset(0,0,Ball.class);
if (Ball != null)
{
getWorld().removeObject(Ball);
Greenfoot.playSound ("Coin-collect-sound-effect.mp3");
counter.add(1);
}
}
/**
* counter code
*/
public Plane (Counter pointcounter)
{
this();
counter = pointcounter;
}
}
