Hello, i am currently working on a tank game but need help with the health bar for the walls, currently i have this:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class wall here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class wall extends Actor
{
private int wallHealth_;
/**
* Act - do whatever the wall wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public wall()
{
wallHealth_ = 5;
}
public void act()
{
checkHealth();
checkDestroy();
}
public boolean collides()
{
if(getOneIntersectingObject(BouncingBullet.class)!=null);
return true;
}
public void checkHealth()
{
if(collides())
{
wallHealth_--;
}
}
public void checkDestroy()
{
if (wallHealth_ == 0)
{
World world;
world = getWorld();
world.removeObject(this);
}
}
}
But the wall gets destroyed in one hit