So I can't figure out how to get an actor to run a method from the world.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class TestWorld extends World
{
// Defines the center of the screen.
public int midWidth = getWidth() / 2;
public int midHeight = getHeight() / 2;
TestActor myTest = new TestActor();
Splode mySplosion = new Splode();
Mplode myMplosion = new Mplode();
Lplode myLplosion = new Lplode();
public TestWorld()
{
super(100, 100, 10);
addObject(myTest, midWidth, midHeight);
int xPos = myTest.getX();
int yPos = myTest.getY();
}
public void explode(){
// if(Greenfoot.mouseClicked(myTest)){
removeObject(myTest);
addObject(mySplosion, myTest.getX(), myTest.getY());
wait(1500);
removeObject(mySplosion);
addObject(myMplosion, myTest.getX(), myTest.getY());
wait(1500);
removeObject(myMplosion);
addObject(myLplosion, myTest.getX(), myTest.getY());
wait(1500);
removeObject(myLplosion);
wait(1000);
reset();
// }
}
public void reset(){
removeObjects(getObjects(null));
addObject(myTest, midWidth, midHeight);
}
public static void wait (int n){
long t0,t1;
t0=System.currentTimeMillis();
do{
t1=System.currentTimeMillis();
}
while (t1-t0<1000);
}
}
World code ^
Actor code\/
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class TestActor extends Actor
{
//The rate at which the object moves
public int speed = 3;
public void act()
{
move();
if(Greenfoot.mouseClicked(myTest)){
explode();
}
}
public void move(){ if(Greenfoot.isKeyDown("w")){ setLocation(getX(), getY() - speed);}
if(Greenfoot.isKeyDown("s")){ setLocation(getX(), getY() + speed);}
if(Greenfoot.isKeyDown("a")){ setLocation(getX() - speed, getY());}
if(Greenfoot.isKeyDown("d")){ setLocation(getX() + speed, getY());}
}
}