added health bar to monster

This commit is contained in:
2025-11-30 00:38:00 +01:00
parent 9aae9ad20f
commit 8ec1805877
3 changed files with 18 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ public class Sound {
soundURL[4] = new File("assets/sounds/fanfare.wav").toURI().toURL();
soundURL[5] = new File("assets/sounds/hitmonster.wav").toURI().toURL();
soundURL[6] = new File("assets/sounds/receivedamage.wav").toURI().toURL();
soundURL[7] = new File("assets/sounds/blocked.wav").toURI().toURL();
} catch(MalformedURLException e) {
Boot.logger.log(Level.SEVERE, e.getMessage());
}

View File

@@ -65,6 +65,7 @@ public class Entity {
if(this.type == EntityType.MONSTER && contactPlayer) {
if(panel.player.invincible) return;
panel.playSE(6);
panel.player.life -= 1;
panel.player.invincible = true;
}
@@ -103,12 +104,20 @@ public class Entity {
worldY + panel.tileSize > panel.player.worldY - panel.player.screenY &&
worldY - panel.tileSize < panel.player.worldY + panel.player.screenY
) {
// MONSTER HP-BAR
if(this.type == EntityType.MONSTER) {
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);
}
// DRAW ENTITY
if(invincible) graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
if(dying) dyingAnimation(graphics2d);
// only modify sprite render position for player because I dont know yet how monster attack sprite are gonna look
if(type == EntityType.PLAYER) {
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(),
(direction == Direction.LEFT) ? screenX - panel.tileSize : screenX,
(direction == Direction.UP) ? screenY - panel.tileSize : screenY, null);

View File

@@ -160,7 +160,10 @@ public class Player extends Entity {
public void interactNPC(int index) {
if(index == 999) {
if(panel.keyH.spacePressed) attacking = true;
if(panel.keyH.spacePressed) {
attacking = true;
//panel.playSE(7); //remains disabled because game does weird things while playing the sound
}
return;
}
//if(!panel.keyH.spacePressed) return; //Only uncomment if text should only appear if player hits space