OK, change 'SWorld sworld;' to 'SWorld sworld = null;'.
public void act()
{
checkKeys();
if (getWorld() == null) return;
checkShiftDown();
}
private void checkKeys()
{
if (Greenfoot.isKeyDown("left") )
{
setImage("AliceLeft.png");
moveLeft();
}
if (Greenfoot.isKeyDown("right") )
{
setImage("AliceRight.png");
moveRight();
}
if (Greenfoot.isKeyDown("up")&& onGround )
{
if (onGround())
jump();
}
if (Greenfoot.isKeyDown("space") )
{
//setImage("AliceShoot.png");
//Greenfoot.playSound(".wav");
getWorld().addObject(new Pumpkin(), getX(), getY());
}
}
public void checkShiftDown()
{
if (shiftDown && !Greenfoot.isKeyDown("shift")) shiftDown = false;
if (shiftDown) return;
if (Greenfoot.isKeyDown("shift"))
{
shiftDown = true;
int x = ((SWorld)getWorld()).getUnivX(getX());
int y = ((SWorld)getWorld()).getUnivY(getY());
int xOffset = getX()-x, yOffset = getY()-y;
SWorld sworld = null;
if (getWorld() instanceof Level1) sworld = new Level0(this);
if (getWorld() instanceof Level0) sworld = new Level1(this);
sworld.mainActor.setLocation(sworld.mainActor.getX()+xOffset, sworld.mainActor.getY()+yOffset);
}
} public class Level0 extends SWorld
{
public Level0()
{
this (new Alice());
}
public Level0(Alice alice)
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 400, 1, 2400);
//Player
setMainActor(new Alice(),10,340);
mainActor.setLocation(200, 340);
//Background
GreenfootImage bg = new GreenfootImage("Forest.jpg");
setScrollingBackground(bg);
//Counter
addObject(new Score(), 30, 10, false);
addObject(new ShroomScore(), 130, 10, false);
//Level blocks
for(int i=1;i<80;i++)
{
addObject(new Block(), i*30-15, 384,true);
}
//Detector
addObject(new LLevelDetect(), -5, 400,true);
}
}