I've tried to code in a method that allows the actor to be removed when the score counter is equal to 0 but I can't seem to get it working.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* This is the boss found on the "Level3World2.class" level.
* The player fights this boss, when the score counter gets to 0 the boss will disappear and
* a door will appear at the side of the level allowing the player to continue on ward.
*/
public class Boss extends Actor
{
GifImage Gif = new GifImage("BossTransform.gif"); // Grabs GIF files and plays them when certain buttons are pressed.
GifImage Right = new GifImage("Boss-Walking-Right.gif");
GifImage Left = new GifImage("Boss-Walking.gif");
private int direction = 2;
boolean ifPlayed = false;
int repeats = 0;
int score = 0;
/**
* After "Run" is clicked, the 'checkKeys' function constantly checks for what keys are being pressed
* and if the key pressed has a corresponding function to it.
*/
public void act() //Event Loop, this is a loop as it's constantly checking for something to happen.
{
play();
bossMovement();
damageright();
damageleft();
// moveAround();
// health();
// nohealth();
}
/**
* After the transforming GIF has been played, the boss will begin to move around.
*/
public void bossMovement()
{
if (ifPlayed){
moveAround();
}
}
/**
* This plays a GIF of a bad guy transforming, the boss will not begin to move until this GIF
* has been polayed fully.
*/
public void play()
{
if (!ifPlayed)
{
setImage(Gif.getCurrentImage());
repeats++;
if (repeats >= 100){
ifPlayed = true;
}
}
}
/**
* When the boss touches the side of the level, he will change his GIF to show him walking
* the correct direction.
*/
private void moveAround()
{
if ((direction == -2 && getX() <= 5) || (direction == 2 && getX() >= getWorld().getWidth()-5))
{
direction = -direction;
if (direction == 2) setImage(Right.getCurrentImage());
else setImage(Left.getCurrentImage());;
}
setLocation(getX()+direction, getY());
}
public void damageright()
{
if (isTouching(Bullet.class))
{
removeTouching(Bullet.class);
((Level3World2) getWorld()).bosshealthdmg();
}
}
public void damageleft()
{
if (isTouching(LeftBullet.class))
{
removeTouching(LeftBullet.class);
((Level3World2) getWorld()).bosshealthdmg();
}
}
// public void nohealth()
// {
// if (target == 0)
// {
// getWorld().removeObject(this);
// }
// }
}
// public void health()
// {
// if (isTouching(Bullet.class))
// {
// score++;
// }
// }
