import greenfoot.*;
import java.awt.Color;
import java.awt.Font;
public class Welt extends World
{
public static int actionType, actionDistance; // the world bounds action fields for the chasers
public static Chased chased; // the player
public int score; // the score
HealthBar healthbar = new HealthBar();
AmmoBar ammobar = new AmmoBar();
private int timer = 1200;
public Welt()
{
super(1000, 600, 1, false);
Greenfoot.setSpeed(60);
// create background texts
GreenfootImage bg = getBackground();
// create player and reset game
chased = new Chased();
setAction(0);
if (timer>0)
{
timer--;
if(timer == 0) Greenfoot.stop();
}
}
public void act()
{
if (numberOfObjects() >= 20+score/10) return;
if (Greenfoot.getRandomNumber(1000) > 30+score/10) return;
int x = Greenfoot.getRandomNumber(getWidth());
int y = Greenfoot.getRandomNumber(getHeight());
int rand = Greenfoot.getRandomNumber(4);
if (rand < 2) x = (getWidth()-3+actionDistance*2)*rand+1-actionDistance;
else y = (getHeight()-3+actionDistance*2)*(rand-2)+1-actionDistance;
// if (Math.abs(x-chased.getX())+Math.abs(y-chased.getY()) < 200) return;
Chaser chaser = new Chaser();
addObject(chaser, x, y);
chaser.turnTowards(400, 300);
}
public AmmoBar getAmmoBar()
{
return ammobar;
}
public HealthBar getHealthBar()
{
return healthbar;
}
private void setAction(int action)
{
addObject (healthbar, 100, 20);
addObject (ammobar, 100, 40);
int[] distances = { 0, 0, -10, 0, -15 }; // bound ranges
actionDistance = distances[actionType]; // the range for this action
GreenfootImage bg = getBackground();
score = 0;
// ensure player is in world
if (chased.getWorld() == null) addObject(chased, 400, 300);
}
public void getActorCounts()
{
java.util.List<Object> objects = getObjects(null);
int n = 0;
while (!objects.isEmpty())
{
String name = objects.get(n).getClass().getName();
int count = 1;
int index = 1;
while (index < objects.size())
{
if (name.equals(objects.get(index).getClass().getName()))
{
count++;
objects.remove(index);
}
else index++;
}
System.out.println(name+": "+count);
objects.remove(0);
}
}
}

