i want this brick to pop up on upper edge, every time this brick remove in bottom edge ( like animation )
java.lang.NullPointerException
at Brick.checkout(Brick.java:29)
at Brick.act(Brick.java:22)
at greenfoot.core.Simulation.actActor(Simulation.java:594)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
and this is the world class
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Brick here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Brick extends Actor
{
private static final int ACCEL = 5;
private int atas = 15;
/**
* Act - do whatever the Brick wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(), getY()+ACCEL);
// atas = atas + ACCEL;
checkout();
}
public void checkout()
{
if (getWorld() != null && (this.atWorldEdge()) ) {
getWorld().removeObject(this);
getWorld().addObject(new Brick(), 13, 20);
getWorld().addObject(new Brick(), 227, 20);
return;
}
}
public boolean atWorldEdge()
{
if(getWorld() != null && (getX() < 5 || getX() > getWorld().getWidth() - 5))
return true;
if(getWorld() != null && (getY() < 5 || getY() > getWorld().getHeight() - 5))
return true;
else
return false;
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
private static final int GAP = 20;
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(240, 450, 1);
int y = 20;
while( y < 450)
{
addObject(new Brick(),227,y);
y = y + 30 + GAP;
}
int y2 = 20;
while( y2 < 450)
{
addObject(new Brick(),13,y2);
y2 = y2 + 30 + GAP;
}
addObject(new Car(),121 , 405);
}
}