I am doing a game that you need a checkpoint on and I have no idea how to code it.Can someone help?
//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));
}// 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;
//...
}
}