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?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // 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 } |
1 2 3 4 5 6 7 8 9 10 11 | 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 ); } } |
1 2 3 4 5 6 | // add instance field private boolean shotTaken; // in act, replace 'shoot();' with if (!shotTaken) shoot(); // in 'shoot' method shotTaken = true ; |