Move methods to increase health and shield points to LivingEntity, cap them ad their maximum value.
This commit is contained in:
parent
970ddb348f
commit
7a9766788a
@ -135,6 +135,17 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
|
||||
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.
|
||||
*/
|
||||
@ -157,6 +168,17 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
|
||||
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.
|
||||
*/
|
||||
|
@ -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.
|
||||
|
@ -11,6 +11,6 @@ public class ItemHeal extends Item {
|
||||
|
||||
@Override
|
||||
public void itemCollected(Player player) {
|
||||
player.increaseHealthPoints(15);
|
||||
player.addHealthPoints(15);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,6 @@ public class ItemShield extends Item {
|
||||
|
||||
@Override
|
||||
public void itemCollected(Player player) {
|
||||
player.increaseShieldPoints(5);
|
||||
player.addShieldPoints(5);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user