this.maxHp = 100;
this.hp = this.maxHp;
it's mean objeact got 100hp and if we hit object, it's subtracted 5 hp from object.
here is method th check if object take damage:
public boolean takeDamage(int dmg) {
hp -= dmg;
reddish += 1.0f;
if (hp <= 0) {
return true;
}
return false;
}
here is method to check if bullet hit object:
public void checkCollisions() {
List<Bullet> b = bulletEmitter.getActiveList();
for (int i = 0; i < b.size(); i++) {
for (int j = 0; j < players.size(); j++) {
if (b.get(i).isArmed() && players.get(j).getHitArea().contains(b.get(i).getPosition())) {
b.get(i).deactivate();
players.get(j).takeDamage(5);
map.clearGround(b.get(i).getPosition().x, b.get(i).getPosition().y, 8);
continue;
}
}
I need to show taking damage (int dmg), damage might be any variable which we put in method takeDamage(int dmg). int this case int dmg = 5;
I can't calculate it this:
result = maxHp - hp
increase result on 5hp with evry hit
5.. 10.. 15.. 20..
here is method, which i put font in:
damageFont.draw(batch, "" + (maxHp - hp), position.x, position.y + 130, 85, 1, false);
}
}
(maxHp - hp) - increase result on 5hp with evry hit 5.. 10.. 15.. 20..
instead this, i need to calculate ammount of deal damage, but not with constant values.
(maxHp - hp) something instead this just should return 5, if we put 5 in takeDamage(int dmg) or 10, if we put 10.
it's amount of damage take with evry hit:
should be 5, 5, 5, 5
not: 5... 10... 15... 20
Just like MarsAtomic mentioned you allready have your damage per hit, just save it as a new instance variable and display it instead of (maxHp - hp):
private int damageTaken;
public boolean takeDamage(int dmg) {
damageTaken = dmg;
hp -= dmg;
reddish += 1.0f;
if (hp <= 0) {
return true;
}
return false;
}
and when you draw your font:
damageFont.draw(batch, "" + damageTaken, position.x, position.y + 130, 85, 1, false);