Hi i'm trying to program a boss fight where the boss will die once you shoot it 10 times. I'm testing my code but the boss never dies even if i set the amount of hits it takes before dying to 1.
Heres my Boss class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Boss here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class BossEnemy extends Actor {
private boolean down = true;
private int minShotDelay = 40;
private int maxShotDelay = 160;
private int shotTimer = minShotDelay;
public void act() {
if(getY() >= getWorld().getHeight()) {
down = false;
}
else if(getY() <= 0) {
down = true;
}
if(down) {
setLocation(getX(), getY()+4);
}
else {
setLocation (getX(), getY()-4);
}
shootRandomly();
if (shotTimer == 0)
{
getWorld().addObject(new Fireball(), getX(), getY());
shotTimer = minShotDelay+Greenfoot.getRandomNumber(1+maxShotDelay-minShotDelay);
}
else shotTimer--;
Health();
}
public void shootRandomly()
{
if (shotTimer == 0)
{
getWorld().addObject(new Fireball(), getX(), getY());
shotTimer = minShotDelay+Greenfoot.getRandomNumber(1+maxShotDelay-minShotDelay);
}
else shotTimer--;
}
public void Health(){
Actor a = getOneIntersectingObject(Bullet.class);
if(a != null)
{
MyWorld5 myWorld5 =(MyWorld5) getWorld();
BossHealth bosshealth = myWorld5.getBossHealth();
bosshealth.addHit();
}
}
public void Death(){
MyWorld5 myWorld5 =(MyWorld5) getWorld();
BossHealth bosshealth = myWorld5.getBossHealth();
bosshealth.act();
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Boss here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class BossEnemy extends Actor {
private boolean down = true;
private int minShotDelay = 40;
private int maxShotDelay = 160;
private int shotTimer = minShotDelay;
public void act() {
if(getY() >= getWorld().getHeight()) {
down = false;
}
else if(getY() <= 0) {
down = true;
}
if(down) {
setLocation(getX(), getY()+4);
}
else {
setLocation (getX(), getY()-4);
}
shootRandomly();
if (shotTimer == 0)
{
getWorld().addObject(new Fireball(), getX(), getY());
shotTimer = minShotDelay+Greenfoot.getRandomNumber(1+maxShotDelay-minShotDelay);
}
else shotTimer--;
Health();
}
public void shootRandomly()
{
if (shotTimer == 0)
{
getWorld().addObject(new Fireball(), getX(), getY());
shotTimer = minShotDelay+Greenfoot.getRandomNumber(1+maxShotDelay-minShotDelay);
}
else shotTimer--;
}
public void Health(){
Actor a = getOneIntersectingObject(Bullet.class);
if(a != null)
{
MyWorld5 myWorld5 =(MyWorld5) getWorld();
BossHealth bosshealth = myWorld5.getBossHealth();
bosshealth.addHit();
}
}
public void Death(){
getWorld().removeObject(this);
}
}