I have a little maze game. If the main touches eind.class, it is supposed to get teleported to level 2.
when i type the code below, it keeps saying the variable level_2 is undeclared. Where am I supposed to declare it?
public class movers extends Actor
{
/**
* Act - do whatever the movers wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveAround();
teleportNewLevel();
}
public void moveAround() {
int oldX=getX();
int oldY=getY();
int oldRotation=getRotation();
if (Greenfoot.isKeyDown("left")) {
setRotation(180); move(1);
} if (Greenfoot.isKeyDown("right")) {
setRotation(0);
setLocation(getX()+1, getY());
} if (Greenfoot.isKeyDown("up")) {
setRotation(270); move(1);
} if (Greenfoot.isKeyDown("down")) {
setRotation(90); move(1);
}
if (isTouching(wall.class))
{
setLocation(oldX, oldY);
setRotation(oldRotation);}
if (isTouching(wall_2.class))
{
setLocation(oldX, oldY);
setRotation(oldRotation);}
}
public void teleportNewLevel()
{
if(isTouching (eind.class))
{
Greenfoot.setWorld(level_2);
}
}
}
