I want the program put an object in the World every 5 seconds or whatever elapsed time I set.
I created a method Act within the Dojo class but I cannot figure this out.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Karate fighter will kick watermelons
*
* @author Tom
* @version 1.0
*/
public class Dojo extends World
{
long initialTime = System.currentTimeMillis();
long elapsedTime = 0;
/**
* Constructor for objects of class Dojo.
*
*/
public Dojo()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
addObject(new Standing(), 250, 270);
WaterMelon w1 = new WaterMelon();
addObject(w1, 5, 180);
WaterMelon w2 = new WaterMelon();
addObject(w2, 5, 250);
}
public void Act(){
addMelonToWorld(5000);
}
public void addMelonToWorld(long elipsedTimeSet){
elapsedTime = System.currentTimeMillis() - initialTime;
if(elapsedTime >elipsedTimeSet){
WaterMelon wm = new WaterMelon();
addObject(wm, 5, 330);
elapsedTime =0;
initialTime = System.currentTimeMillis();
}
}
}

