It still doesn't work this is what i did
public class Car extends Cars
{
private boolean stoppedAtStation;
Lives life;
int pauseTimer=0;
private int timer = 100;
public Car(Lives liven){
life=liven;
}
public void act() {
checkMeter();
checkLives();
followroad();
placeroad();
atStation();
crashing();
checkEdges();
}
public void checkLives(){
if(life.getValue()== 2){
Greenfoot.stop();}
}
public void checkEdges() {
if(atWorldEdge()){
getWorld().removeObject(this);
if(getWorld() == null) return;
}
}
private void runAtStationTimer()
{
if (pauseTimer > 0)
{ pauseTimer--;
if (pauseTimer == 0)
{ setImage("car.png");
// play required sound
// anything else that needs done at this time
}
}
}
public void atStation(){
Actor station = getOneIntersectingObject(Dijk.class);
if (pauseTimer == 0 && station != null) // with possible other conditions
{
pauseTimer = 180;
}
if (!stoppedAtStation && pauseTimer == 0 && station != null)
// inside the 'if' block for the previous line, add
stoppedAtStation = true;
}
private void checkMeter(){
if (timer > 0){
timer--;
if( timer == 0){
createNewCar();
}
}
}
public void createNewCar(){
World myWorld;
myWorld = getWorld();
int worldHeight = myWorld.getHeight();
int y = Greenfoot.getRandomNumber(worldHeight);
myWorld.addObject(new Car(live),100, y);
}
public void crashing(){
Actor car;
car = getOneObjectAtOffset(0, 0, Car.class);
if (car != null){
getWorld().removeObject(car);
leven.add(1);
}
}
public boolean atWorldEdge() {
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false; }
}
