diff --git a/src/de/teamteamteam/spacescooter/gui/HealthBar.java b/src/de/teamteamteam/spacescooter/gui/HealthBar.java index 279adf7..462244e 100644 --- a/src/de/teamteamteam/spacescooter/gui/HealthBar.java +++ b/src/de/teamteamteam/spacescooter/gui/HealthBar.java @@ -14,6 +14,7 @@ public class HealthBar extends Entity { private int width = 150; private int height = 14; private int health = 0; + private int healthwidth = 0; private ConcurrentIterator entityIterator; @@ -31,18 +32,23 @@ public class HealthBar extends Entity { player = ((Player) e); } } - this.health = ((this.width) * player.getHealthPoints()); + try { + this.health = player.getHealthPoints(); + this.healthwidth = ((this.width) * this.health) / 100; + } catch(Exception e) { + this.healthwidth = 0; + } g.setColor(Color.WHITE); g.setFont(new Font("Monospace", 0, 16)); g.drawString("Health:", this.getX(), this.getY()+12); - if (player.getHealthPoints() <= 15) { + if (this.health <= 15) { g.setColor(Color.RED); - } else if (player.getHealthPoints() <= 50) { + } else if (this.health <= 50) { g.setColor(Color.YELLOW); } else { g.setColor(Color.GREEN); } - g.fillRect(this.getX()+70, this.getY(), this.health / 100, this.height); + g.fillRect(this.getX()+70, this.getY(), this.healthwidth, this.height); g.setColor(Color.WHITE); g.drawRect(this.getX()+70, this.getY(), this.width, this.height); } diff --git a/src/de/teamteamteam/spacescooter/gui/ShieldBar.java b/src/de/teamteamteam/spacescooter/gui/ShieldBar.java index 1b7bbdd..856c925 100644 --- a/src/de/teamteamteam/spacescooter/gui/ShieldBar.java +++ b/src/de/teamteamteam/spacescooter/gui/ShieldBar.java @@ -14,6 +14,7 @@ public class ShieldBar extends Entity { private int width = 150; private int height = 14; private int shield = 0; + private int shieldwidth = 0; private ConcurrentIterator entityIterator; @@ -31,12 +32,17 @@ public class ShieldBar extends Entity { player = ((Player) e); } } - this.shield = ((this.width) * player.getShieldPoints()); + try { + this.shield = player.getShieldPoints(); + this.shieldwidth = ((this.width) * this.shield) / 100; + } catch(Exception e) { + this.shieldwidth = 0; + } g.setColor(Color.WHITE); g.setFont(new Font("Monospace", 0, 16)); g.drawString("Shield:", this.getX(), this.getY()+12); g.setColor(Color.BLUE); - g.fillRect(this.getX()+70, this.getY(), this.shield / 100, this.height); + g.fillRect(this.getX()+70, this.getY(), this.shieldwidth, this.height); g.setColor(Color.WHITE); g.drawRect(this.getX()+70, this.getY(), this.width, this.height); }