import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class Terrorist here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Enemy extends Actor
{
private int i;
public int time;
MyWorld world =(MyWorld)getWorld();
//HealthBar health = world.getHealthBar();
/**
* Act - do whatever the Terrorist wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Enemy()
{
}
public void act()
{
Moving();
Damage();
time--;
if(time <= 0)
{
setImage("Terrorist.png");
}
}
public void Moving()
{
if(getY() == 400)
{
while (i < 30)
{
setLocation(getX()-1, getY());
i++;
}
}
}
public void Damage()
{
int number = getWorld().numberOfObjects();
MyWorld world =(MyWorld)getWorld();
HealthBar1 healthbar = world.getHealthBar1();
HealthBar2 healthbar2 = world.getHealthBar2();
HealthBar3 healthbar3 = world.getHealthBar3();
if(Greenfoot.getRandomNumber(20000) < number)
{
getWorld().addObject(new Damage(), 500, 250);
world.addLife(-1);
setImage("ShootingT.png");
time = 50;
Greenfoot.playSound("MP5_SMG-GunGuru-703432894.wav");
}
if(number >= 1)
{
if(healthbar.Health <= 0)
if(getX() < 400 && getX() > 200)
world.removeObject(this);
}
if(number >= 1)
{
if(healthbar2.Health <= 0)
{
if(getX() < 500 && getX() > 400)
world.removeObject(this);
}
}
if(number >= 1)
{
if(healthbar3.Health <= 0)
{
if(getX() < 700 && getX() > 500)
world.removeObject(this);
}
}
}
}

