java - Error on greenfoot, "illegal start of expression" -
whenever hit compile says illegal start of expression wherever private located. here code:
/** * act - whatever platformjumper wants do. method called whenever * 'act' or 'run' button gets pressed in environment. */ public void act() { if(intheair) { fall(); } else { getcommand(); } move(); if(istouching(snowball.class)) { (snowball.class); } private void run (string direction) { if(direction=="left") deltax = walkspeed*-1; else deltax = walkspeed; } private void stop () { deltax = 0; } private void jump() { deltay += jumpheight; intheair = true; } /* * fall() called whenever ballguy in air. decreases deltay 1, creating * gravity. */ private void fall() { deltay-=fallspeed; } private void move() { double newx = getx() + deltax; double newy = gety() - deltay; actor platformbelow = getoneobjectatoffset(0, groundheight + 5, platform.class); actor platformabove = getoneobjectatoffset(0, -(groundheight + 5), platform.class); actor platformtoright = getoneobjectatoffset(sidewidth+5, 0, platform.class); actor platformtoleft = getoneobjectatoffset(-(sidewidth+5), 0, platform.class); if(platformbelow!=null) { if(deltay<0) { deltay = 0; intheair = false; greenfootimage platformimage = platformbelow.getimage(); int topofplatform = platformbelow.gety() - platformimage.getheight()/2; newy = topofplatform - groundheight; } }else if(gety() >= worldheight - groundheight) { if(deltay < 0) { deltay = 0; intheair = false; newy = worldheight - groundheight; } } else { intheair = true; } if(platformabove != null) { if(deltay>0) { deltay=0; greenfootimage platformimage = platformabove.getimage(); int bottomofplatform = platformabove.gety() + platformimage.getheight()/2; newy = bottomofplatform + groundheight; } } if(getx()<=sidewidth) { deltax = math.abs(deltax); } if(getx()>=worldwidth-sidewidth) { deltax = math.abs(deltax) * -1; } if(platformtoright!=null) { deltax = math.abs(deltax) * -1; } if(platformtoleft!=null) { deltax = math.abs(deltax); } setlocation((int)newx,(int)newy); } private void getcommand() { if(greenfoot.iskeydown("left")) { run("left"); } else if (greenfoot.iskeydown("right")) { run("right"); } else { stop(); } if(greenfoot.iskeydown("up")) { jump(); } } }
import greenfoot.*; /** * write description of class ballguy here. * * @author (your name) * @version (a version number or date) */ public class ballguy extends { public ballguy() { } there should looks @ top of code. right compiler thinks there brackets @ bottom of code. i'm presuming left out question.
also:
add bracket on line above first private method. act() method isn't closed.
public void act() { if(intheair) { fall(); } else { getcommand(); } move(); if(istouching(snowball.class)) { (snowball.class); } } private void run (string direction) { if(direction=="left") deltax = walkspeed*-1; else deltax = walkspeed; } like that.
Comments
Post a Comment