// (this is for ground)
public class ground extends World
{
/**
* Constructor for objects of class ground.
*
*/
public ground()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
prepare();
drawScore();
}
private Red theRedScore;
private Blue theBlueScore;
public void drawScore()
{
theRedScore = new Red();
addObject(theRedScore, 58,24);
theBlueScore = new Blue();
addObject(theBlueScore, 27,24);
}
public Red getRedScore()
{
return theRedScore;
}
public Blue getBlueScore()
{
return theBlueScore;
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
cars cars = new cars();
addObject(cars,1,84);
Car car = new Car();
addObject(car,2,323);
Item item = new Item();
addObject(item,106,220);
Item item2 = new Item();
addObject(item2,324,44);
Item item3 = new Item();
addObject(item3,346,373);
Item item4 = new Item();
addObject(item4,436,212);
Item item5 = new Item();
addObject(item5,574,36);
Item item6 = new Item();
addObject(item6,577,387);
item3.setLocation(341,357);
item3.setLocation(332,354);
item6.setLocation(568,380);
item4.setLocation(361,207);
Item item7 = new Item();
addObject(item7,464,127);
item4.setLocation(465,276);
item7.setLocation(451,125);
item4.setLocation(457,277);
}
}
//(This is the actor for this game)
public class cars extends Actor
{
/**
* Constructor for Car - nothing to do.
*/
public void cars()
{
act();
eat();
}
/**
* Drive and allow steering.
*/
public void act()
{
if ( Greenfoot.isKeyDown("left") )
{
turn(-2);
}
if ( Greenfoot.isKeyDown("right") )
{
turn(2);
}
if ( Greenfoot.isKeyDown("up") )
{
move(5);
}
if ( Greenfoot.isKeyDown("down") )
{
move(-4);
}
eat();
}
public void eat()
{
Actor item;
item = getOneObjectAtOffset(0, 0, Item.class);
if (item!= null)
{
ground ground;
ground = (ground) getWorld();
Blue bluecounter = ground.getBlueScore();
ground.removeObject(item);
bluecounter.bumpCount(1);
}
}
}
