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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 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); } } } |