The scenario was working just fine but when I finished writing some code and clicked compile it got stuck in just a blank screen that tells me the world is being constructed.
I tried compiling again and then restarting but it's still the same
/**
* Autumn. A world with some leaves.
*
* @author Michael Kölling
* @version 0.1
*/
public class MyWorld extends World
{
/**
* Create the world and objects in it.
*/
public MyWorld()
{
super(600, 400, 1);
setUp();
}
/**
* Create the initial objects in the world.
*/
private void setUp()
{
addLeaves();
}
private void addLeaves()
{
addObject(new Block(), 300, 200);
int i= 0;
int x=Greenfoot.getRandomNumber(getWidth());
int y=Greenfoot.getRandomNumber(getHeight());
while (i<18);
{
addObject( new Leaf(),x,y);
}
}
}
import greenfoot.*;
/**
* A block that bounces back and forth across the screen.
*
* @author Michael Kölling
* @version 0.1
*/
public class Block extends Actor
{
private int delta = 2;
/**
* Move across the screen, bounce off edges. Turn leaves, if we touch any.
*/
public void act()
{
move();
checkEdge();
checkMouseClick();
checkLeaf();
World world = getWorld();
Leaf leaf = (Leaf) getOneIntersectingObject(Leaf.class);
leaf.turn(9);
if(leaf!= null)
{
}
}
/**
* Move sideways, either left or right.
*/
private void move()
{
setLocation(getX()+delta, getY());
}
/**
* Check whether we are at the edge of the screen. If we are, turn around.
*/
private void checkEdge()
{
if (isAtEdge())
{
delta = -delta; // reverse direction
}
}
/**
* Check whether the mouse button was clicked. If it was, change all leaves.
*/
private void checkMouseClick()
{
if (Greenfoot.mouseClicked(null))
{
// do this when the mouse is clicked. currently: nothing.
}
}
private void checkLeaf()
{
Leaf leaf = (Leaf) getOneIntersectingObject(Leaf.class);
if (leaf!= null)
{
}
else
{
turn (9);
}
}
}
import greenfoot.*;
/**
* A floating leaf that blows across the screen.
*
* @author Michael Kölling
* @version 1.0
*/
public class Leaf extends Actor
{
private int speed;
GreenfootImage img1 = new GreenfootImage("leaf-green.png");
GreenfootImage img2 = new GreenfootImage("leaf-brown.png");
/**
* Create the leaf.
*/
public Leaf()
{
setImage(img1);
speed = Greenfoot.getRandomNumber(3) + 1; // random speed: 1 to 3
setRotation(Greenfoot.getRandomNumber(360));
}
/**
* Move around.
*/
public void act()
{
if (isAtEdge())
{
turn(180);
}
move(speed);
if (Greenfoot.getRandomNumber(100) < 50)
{
turn(Greenfoot.getRandomNumber(5) - 2); // -2 to 2
}
}
/**
* Change the image to another leaf image. This toggles back and
* forth between two images.
*/
public void changeImage()
{
if (getImage() == img1)
{
setImage(img2);
}
else {
setImage(img1);
}
}
}