diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index d7290bf..c5a10b9 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -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; + } + } diff --git a/src/de/teamteamteam/spacescooter/gui/HealthBar.java b/src/de/teamteamteam/spacescooter/gui/HealthBar.java index 80ad595..f121f18 100644 --- a/src/de/teamteamteam/spacescooter/gui/HealthBar.java +++ b/src/de/teamteamteam/spacescooter/gui/HealthBar.java @@ -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; diff --git a/src/de/teamteamteam/spacescooter/gui/ShieldBar.java b/src/de/teamteamteam/spacescooter/gui/ShieldBar.java index 6dc14b8..ea80ca9 100644 --- a/src/de/teamteamteam/spacescooter/gui/ShieldBar.java +++ b/src/de/teamteamteam/spacescooter/gui/ShieldBar.java @@ -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;