//My World: Real Game
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class RealGame here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class RealGame extends World
{
HealthBar healthBar = new HealthBar();//access healthbar info from the public healthbar method
Counter counter = new Counter();
/**
* Constructor for objects of class RealGame.
*
*/
int trashCount = 0;
public RealGame()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
prepare();
}
public HealthBar gethealthBar(){
return healthBar;
}
public Counter getCounter(){
return counter;
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
addObject(counter, 108,125);
Back back = new Back();
addObject(back,75,40);
Cheese cheese = new Cheese();
addObject(cheese,404,62);
addObject(healthBar,639,50);
healthBar.setLocation(706,39);
healthBar.setLocation(702,36);
Chef chef = new Chef();
addObject(chef,377,495);
Trash trash = new Trash();
addObject(trash,315,56);
}
int iCounter = 0;
public void act()
{
trashCount++; //30 times per second
if(trashCount>59) //happens 60 times per second
{ addTrash();
trashCount = 0;
}
}
public void addTrash(){
Trash myTrash = new Trash();
addObject(new Trash(), Greenfoot.getRandomNumber(getWidth()),0);
}
}

