make hp bar hideable

This commit is contained in:
2025-11-30 00:44:12 +01:00
parent 8ec1805877
commit 2ed21add1c

View File

@@ -35,12 +35,14 @@ public class Entity {
boolean attacking;
public boolean alive = true;
public boolean dying;
public boolean hpBarOn;
// COUNTER
public int spriteCounter;
public int actionLock;
public int invincibleCount;
int dyingCount;
int hpBarCounter;
// ATTRIBUTES
public EntityType type;
@@ -106,16 +108,26 @@ public class Entity {
) {
// MONSTER HP-BAR
if(this.type == EntityType.MONSTER) {
if(this.type == EntityType.MONSTER && hpBarOn) {
graphics2d.setColor(new Color(35, 35, 35));
graphics2d.fillRect(screenX-1, screenY-6, panel.tileSize+2, 12);
graphics2d.setColor(new Color(255, 0, 30));
graphics2d.fillRect(screenX, screenY-5, (int) ((double) panel.tileSize/maxLife)*life, 10);
hpBarCounter++;
if(hpBarCounter > 600) { //bar disappears after 10 seconds
hpBarCounter = 0;
hpBarOn = false;
}
}
// DRAW ENTITY
if(invincible) graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
if(invincible) {
hpBarOn = true;
hpBarCounter = 0;
changeOpacity(graphics2d, 0.4f);
}
if(dying) dyingAnimation(graphics2d);
if(type == EntityType.PLAYER) { // only modify sprite render position for player because I dont know yet how monster attack sprite are gonna look
if(attacking) graphics2d.drawImage(parseSpriteATK(),
@@ -124,7 +136,7 @@ public class Entity {
else graphics2d.drawImage(parseSprite(), screenX, screenY, null);
} else graphics2d.drawImage(parseSprite(), screenX, screenY, null);
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
changeOpacity(graphics2d, 1f);
}
}