import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Villian here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Villian extends Actor
{
boolean touchingherobullet = false;
public int villianRotation;
Actor SpaceStone;
Actor SoulStone;
Actor PowerStone;
Actor TimeStone;
Actor herobullet;
/**
* Act - do whatever the Villian wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKeyPress();
SpaceStone = getOneIntersectingObject(SpaceStone.class);
MyWorld myWorld = (MyWorld)getWorld();
SoulStone = getOneIntersectingObject(SoulStone.class);
if (SoulStone!=null){
myWorld.removeObject(SoulStone);
myWorld.increaseScore();
}
PowerStone = getOneIntersectingObject(PowerStone.class);
if (PowerStone!=null){
myWorld.removeObject(PowerStone);
myWorld.increaseScore();
}
SpaceStone = getOneIntersectingObject(SpaceStone.class);
if (SpaceStone!=null){
myWorld.removeObject(SpaceStone);
myWorld.increaseScore();
}
TimeStone = getOneIntersectingObject(TimeStone.class);
if (TimeStone!=null){
myWorld.removeObject(TimeStone);
myWorld.increaseScore();
}
herobullet = getOneIntersectingObject(herobullet.class);
if(herobullet !=null)
{
HealthBar healthbar = myWorld.getHealthBar();
if (touchingherobullet ==false)
{
healthbar.loseHealth();
touchingherobullet = true;
if(healthbar.health <=0)
{
myWorld.removeObject(this);
GameOver gameover = new GameOver();
myWorld.addObject(gameover, myWorld.getWidth()/2, myWorld.getHeight()/2);
}
}
} else {
touchingherobullet = false;
}
villianRotation = getRotation();
}
public void checkKeyPress()
{
if (Greenfoot.isKeyDown("up")) {
setLocation(getX(),getY()-5);
}
if (Greenfoot.isKeyDown("down")) {
setLocation(getX(),getY()+5);
}
if (Greenfoot.isKeyDown("right")) {
move(7);
}
if (Greenfoot.isKeyDown("left")) {
move(-7);
}
if (Greenfoot.isKeyDown("space")) {
shoot();
}
}
public void shoot()
{
getWorld() .addObject(new villianbullet(villianRotation), getX(), getY());
}
public void tryToEat(){
if (isTouching(SoulStone.class)) {
removeTouching(SoulStone.class);
}
if (isTouching(SpaceStone.class)) {
removeTouching(SpaceStone.class);
}
if (isTouching(TimeStone.class)) {
removeTouching(TimeStone.class);
}
if (isTouching(PowerStone.class)) {
removeTouching(PowerStone.class);
}
}
}

