Hey guys so all i need now to finish my plants vs zombies game is letting the zombies spawn after a certain time. With this i mean that once the first zombie spawns, wait for 5 seconds to let the second one spawn. Can anybody help me?
// instance field in world class
private int zombieSpawnTimer;
// in act method of world class
runZombieSpawnTimer();
// new method in world class
private void runZombieSpawnTimer()
{
zombieSpawnTimer = (zombieSpawnTimer+1)%300; // adjust '300' as desired
if (zombieSpawnTimer == 0) spawnZombie();
}
private void spawnZombie()
{
// add code spawning zombie here
}public void shoot()
{
Actor Parent = getParentInRange();
if (Parent!= null)
{
WaterBall wb = new WaterBall();
getWorld().addObject(wb, getX(), getY());
wb.turnTowards(Parent.getX(), Parent.getY());
wb.move(10);
}
}// add instance field private boolean shotTaken; // in act, replace 'shoot();' with if (!shotTaken) shoot(); // in 'shoot' method shotTaken = true;