Please bear with me, I have no idea what I'm doing.
Basically, what needs to be done is to have two variables(??) of the same class face each other every compile/reset, and with every compile/reset, the two objects spawn at random directions.
I've looked all over the net, and it seems that any code I try either mysteriously yields a syntax error or a series of errors after compiling (I usually get the ones for repeating a declaration, or that the object cannot act because it's not even in the program yet, I've forgotten what they're called but yes).
Here's the code I'm using for the world class:
and here's one one I'm using for the actor class:
Right now with the current code, my problem seems to be that I need to initialize the variables I declared, but I don't know what I can equate the variables to in order to initialize them? Please help, it's honestly been hours since I started this simple project, and I'm just getting frustrated. Thank you!
import greenfoot.*;
/**
* Write a description of class Space here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Space extends World
{
/**
* Constructor for objects of class Space.
*
*/
public Space()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1000, 600, 1);
prepare();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
Toot toot = new Toot();
addObject(toot, Greenfoot.getRandomNumber(1000), Greenfoot.getRandomNumber(600) );
Toot toots = new Toot();
addObject(toots, Greenfoot.getRandomNumber(1000), Greenfoot.getRandomNumber(600) );
}
}
import greenfoot.*;
/**
* Write a description of class Toot here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Toot extends Actor
{
/**
* Act - do whatever the Toot wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void addedToWorld(World world)
{
Toot toot;
Toot toots;
if (!world.getObjects(Toot.class).isEmpty())
{
toot = (Toot)world.getObjects(Toot.class).get(0);
toot.turnTowards(toots.getX(), toots.getY());
}
if (!world.getObjects(Toot.class).isEmpty())
{
toots = (Toot)world.getObjects(Toot.class).get(0) ;
toots.turnTowards(toot.getX(), toot.getY());
}
}
}

