I am doing a game that you need a checkpoint on and I have no idea how to code it.Can someone help?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | //in main actor class private int checkpoint = 0 ; public NameOfTheActor( int c) { checkpoint = c; } //in act if (--reached checkpoint-- && didn't already reach this checkpoint) //either save the coordinates or have a checkpoint actor to create a condition here { checkpoint++; } if (--gameLost--) { ((WorldName) getWorld()).restart(checkpoint); //or Greenfoot.setWorld( new WorldName(checkpoint)); } |
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 | // in the world public WorldName() { this ( 0 ); } public WorldName( int checkpoint) { super ... createWorld(checkpoint); } public void restart( int checkpoint) { removeObjects(getObjects); createWorld(checkpoint); } public void createWorld( int checkpoint) { //add objects which are always there no matter if a checkpoint is reached switch (checkpoint) { case 0 : //add objects which are there when no checkpoint was reached already, like: addObject( new NameOfActor(checkpoint), 100 , 100 ); break ; case 1 : //add objects which are there when the first checkpoint was reached addObejct( new NameOfActor(checkpoint), 200 , 100 ); break ; //... } } |