Health and Shildbar now working with Percent Values

This commit is contained in:
JJTCM 2014-11-11 14:59:37 +01:00
parent c0b62d59ac
commit e4882f1315
3 changed files with 18 additions and 2 deletions

View File

@ -13,6 +13,8 @@ import de.teamteamteam.spacescooter.utility.GameConfig;
public class Player extends ShootingEntity implements KeyboardListener {
private Keyboard keyboard = null;
private double healthPercent = 0;
private double shieldPercent = 0;
public Player(int x, int y) {
super(x, y);
@ -35,6 +37,12 @@ public class Player extends ShootingEntity implements KeyboardListener {
}
public void update() {
if (StaticValue.HealthPoints != 0) {
this.healthPercent = ((double) this.getHealthPoints() / (double) StaticValue.HealthPoints) * 100;
}
if (StaticValue.ShieldPoints != 0) {
this.shieldPercent = ((double) this.getShieldPoints() / (double) StaticValue.ShieldPoints) * 100;
}
if(this.canMove()) {
super.update();
int offset = 3;
@ -103,4 +111,12 @@ public class Player extends ShootingEntity implements KeyboardListener {
public void keyTyped(KeyEvent e) {}
public int getHealthPercent() {
return (int) this.healthPercent;
}
public int getShieldPercent() {
return (int) this.shieldPercent;
}
}

View File

@ -22,7 +22,7 @@ public class HealthBar extends Entity {
public void paint(Graphics2D g) {
Player player = GameScreen.getPlayer();
try {
this.health = player.getHealthPoints();
this.health = player.getHealthPercent();
this.healthwidth = ((this.width) * this.health) / 100;
} catch(Exception e) {
this.healthwidth = 0;

View File

@ -22,7 +22,7 @@ public class ShieldBar extends Entity {
public void paint(Graphics2D g) {
Player player = GameScreen.getPlayer();
try {
this.shield = player.getShieldPoints();
this.shield = player.getShieldPercent();
this.shieldwidth = ((this.width) * this.shield) / 100;
} catch(Exception e) {
this.shieldwidth = 0;