import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Main player. Gets controlled by user. * * @author (Quinn Sapp) * @version (5 July 2013) */ public class MainPlayer extends Animal { private Counter counter; public MainPlayer(Counter pointCounter) { counter = pointCounter; } public void act() { checkKeyPress(); lookForPoint(); checkNextLevel(); checkNextLevel2(); checkNextLevel3(); checkNextLevel4(); checkNextLevel5(); }// end act public void checkKeyPress(){ if (Greenfoot.isKeyDown("left")){ turn(-4); } if (Greenfoot.isKeyDown("right")){ turn(4); } if (Greenfoot.isKeyDown("up")){ turn(4); } if (Greenfoot.isKeyDown("down")){ turn(4); } if (Greenfoot.isKeyDown("space")){ move(2); } }//end checkKeys public void lookForPoint(){ if (canSee(Point.class)){ eat(Point.class); counter.add(2); Greenfoot.playSound("au.wav"); } if(counter.getValue() >= 80){ gameOver(); } } //end lookForPoint public void checkNextLevel(){ if (getOneIntersectingObject(Finish.class) != null) { //reached the end object; //start the new level; Greenfoot.setWorld(new Level2()); } }//end MainPlayer Class public void checkNextLevel2(){ if (getOneIntersectingObject(Finish2.class) != null) { //reached the end object; //start the new level; Greenfoot.setWorld(new Level3()); } } public void checkNextLevel3(){ if (getOneIntersectingObject(Finish3.class) != null) { //reached the end object; //start the new level; Greenfoot.setWorld(new Level4()); } } public void checkNextLevel4(){ if (getOneIntersectingObject(Finish4.class) != null) { //reached the end object; //start the new level; Greenfoot.setWorld(new Level5()); } } public void checkNextLevel5(){ if (getOneIntersectingObject(Finish5.class) != null) { //reached the end object; //start the new level; Greenfoot.setWorld(new WINNER()); } } }