i have called each timer, but the car1 is spawning randomly, the car3 is spawning randomly then too far apart and car2 and car4 donot spawn at all
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
// int getX() x = Car3X;
int fastcarTimer = 75;
int slowcarTimer = 100;
Lives life1 = new Lives();
Lives life2 = new Lives();
Lives life3 = new Lives();
Frog frog = new Frog();
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1000, 900, 1);
addObject(new Finish(), 305, 32); // adding the finish lilypad
addObject(new Finish(), 515, 32); // adding the finish lilypad
addObject(new Finish(), 713, 32); // adding the finish lilypad
addObject(new Finish(), 905, 32); // adding the finish lilypad
addObject(new Finish(), 95, 32); // adding the finish lilypad
addObject(new Car1(), 10, 630);
addObject(new Car1(), 500, 630);
addObject(new Car1(), 900, 630);
addObject(new Car1(), 300, 630);
addObject(new Car3(), 995, 537);
addObject(new Car3(), 750, 537);
addObject(new Car3(), 395, 537);
addObject(new Car3(), 195, 537);
addObject(new Car3(), 95, 537);
addObject(new Car4(), 195, 736);
addObject(new Car2(), 300, 736);
addObject(new Car4(), 600, 736);
addObject(new Car2(), 994, 736);
addObject(new Car2(), 800, 736);
addObject(new Frog(), 500, 850);
showText("Lives : " , 40, 880);
}
public void act()
{
// if (Car3X == 0)
// {
// }
randomslowCarSpawner();
randomfastCarSpawner();
createLives();
}
public void slowCarSpawn()
{
}
public void fastCarSpawn()
{
}
public void createLives()
{
if(frog.getLives() == 3)
{
addObject(life1, 90, 880);
addObject(life2, 120, 880);
addObject(life3, 150, 880);
}else if(frog.getLives() == 2)
{
addObject(life1, 90, 880);
addObject(life2, 120, 880);
}else if(frog.getLives() == 1)
{
addObject(life1, 90, 880);
}
// public void removeAtWorldEdge()
// {
// if (isAtEdge(Car3()))
// {
// removeObject(Car3());
// spawnTimer();
// }
// }
// public void spawnTimer()
// {
// spawnTimer++;
// if (spawnTimer == 0)
// {
// addObject(new Car3(), 36, 36);
// }
// }
}
public void randomfastCarSpawner()
{
fastcarTimer++;
if(Greenfoot.getRandomNumber(75)<60&&fastcarTimer == 75)
{
addObject(new Car1(),10, 630);
}
if(Greenfoot.getRandomNumber(75)<50&&fastcarTimer == 75)
{
addObject(new Car3(),995, 537);
}
if(fastcarTimer == 76)
{
fastcarTimer = 0;
}
}
public void randomslowCarSpawner()
{
slowcarTimer++;
if(Greenfoot.getRandomNumber(100)<40&&slowcarTimer == 100)
{
addObject(new Car4(),995, 736);
}
if(Greenfoot.getRandomNumber(100)<30&&slowcarTimer == 100)
{
addObject(new Car2(),995, 736);
}
}
}