This site requires JavaScript, please enable it in your browser!
Greenfoot back
manish1
manish1 wrote ...

2013/5/23

Health bar

manish1 manish1

2013/5/23

#
Hello, i am currently working on a on a tank game, and need help with the health bar, i already have the getHit() method for the wall but i need to make a health bar, this is what i have: 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 SeigeTower extends Actor { private int TowerHealth_; /** * Act - do whatever the wall wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public SeigeTower() { TowerHealth_ = 5; } public void act() { checkHealth(); checkDestroy(); } public boolean collides() { Actor a = getOneIntersectingObject(BouncingBullet.class); if(a == null) return false; getWorld().removeObject(a); return true; } public void checkHealth() { if(collides()) { TowerHealth_--; } } public void checkDestroy() { if (TowerHealth_ == 0) { World world; world = getWorld(); world.removeObject(this); } } }
You need to login to post a reply.