diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 77ae16e..5d9c7d2 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -134,6 +134,17 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable public void setHealthPoints(int hp) { this.healthPoints = hp; } + + /** + * Add the given number of points to the current health points. + * Capped at maximum health points. + */ + public void addHealthPoints(int hp) { + this.healthPoints += hp; + if(this.healthPoints > this.maximumHealthPoints) { + this.healthPoints = this.maximumHealthPoints; + } + } /** * Get the current health points. @@ -156,6 +167,17 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable public void setShieldPoints(int sp) { this.shieldPoints = sp; } + + /** + * Add the given number of points to the current shield points. + * Capped at maximum shield points. + */ + public void addShieldPoints(int sp) { + this.shieldPoints += sp; + if(this.shieldPoints > this.maximumShieldPoints) { + this.shieldPoints = this.maximumShieldPoints; + } + } /** * Get the current shield points. diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 4a52b3b..8c48a57 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -17,7 +17,7 @@ import de.teamteamteam.spacescooter.sound.SoundSystem; public class Player extends ShootingEntity implements KeyboardListener { /** - * the Player's Keyboard + * the Players Keyboard */ private Keyboard keyboard = null; @@ -164,27 +164,6 @@ public class Player extends ShootingEntity implements KeyboardListener { */ public void keyTyped(KeyEvent e) {} - /** - * method for increasing the HealthPoints with the Heal-Item - */ - public void increaseHealthPoints(int inc) { - if (this.getHealthPoints() <= (PlayerSession.getShipHealthPoints() - 15)) { - this.setHealthPoints(getHealthPoints() + inc); - } else { - this.setHealthPoints(PlayerSession.getShipHealthPoints()); - } - } - - /** - * method for increasing the ShieldPoints with the Shield-Item - */ - public void increaseShieldPoints(int inc) { - if (this.getShieldPoints() <= (PlayerSession.getShipShieldPoints() - 5)) { - this.setShieldPoints(getShieldPoints() + inc); - } else { - this.setShieldPoints(PlayerSession.getShipShieldPoints()); - } - } /** * Get the current rocket amount. diff --git a/src/de/teamteamteam/spacescooter/entity/item/ItemHeal.java b/src/de/teamteamteam/spacescooter/entity/item/ItemHeal.java index 6dc11a9..e9fe589 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/ItemHeal.java +++ b/src/de/teamteamteam/spacescooter/entity/item/ItemHeal.java @@ -11,6 +11,6 @@ public class ItemHeal extends Item { @Override public void itemCollected(Player player) { - player.increaseHealthPoints(15); + player.addHealthPoints(15); } } diff --git a/src/de/teamteamteam/spacescooter/entity/item/ItemShield.java b/src/de/teamteamteam/spacescooter/entity/item/ItemShield.java index 6a0386f..a3e3838 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/ItemShield.java +++ b/src/de/teamteamteam/spacescooter/entity/item/ItemShield.java @@ -11,6 +11,6 @@ public class ItemShield extends Item { @Override public void itemCollected(Player player) { - player.increaseShieldPoints(5); + player.addShieldPoints(5); } }