feat: Include health bar

This commit is contained in:
2026-01-03 00:33:48 +01:00
parent 4136696c83
commit 070d4fa0f8
2 changed files with 24 additions and 7 deletions

View File

@@ -18,18 +18,24 @@ import java.util.concurrent.TimeUnit;
@Slf4j
public class Player {
public static final int MAX_STAMINA = 20;
public static final int MAX_HEALTH = 30;
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private final RoomCords playerCords;
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private final GameItem[] inventory = new GameItem[Inventory.ITEMS_X * Inventory.ITEMS_Y];
private int stamina = MAX_STAMINA;
@Setter
private PlayerRotation playerRotation = PlayerRotation.FRONT;
@Setter
private GameItem selectedItem;
@Setter
private int health = MAX_HEALTH;
private int stamina = MAX_STAMINA;
private boolean swinging = false;
public void increaseStamina() {
stamina++;
}
public void decreaseStamina() {
stamina--;
}
@@ -59,9 +65,6 @@ public class Player {
return added;
}
@Setter
private PlayerRotation playerRotation = PlayerRotation.FRONT;
public void swing(int delayMs) {
if (swinging) {
return;

View File

@@ -14,7 +14,7 @@ import lombok.Getter;
@Getter
@Dependency
public class Stats {
public static final int BARS_COUNT = 1;
public static final int BARS_COUNT = 2;
public static final int BAR_WIDTH = 72;
public static final int BAR_HEIGHT = 8;
public static final int BAR_PADDING = 2;
@@ -24,6 +24,7 @@ public class Stats {
public static final int OFFSET_X = 5;
public static final int OFFSET_Y = 5;
private static final Pixel HEALTH_COLOR = new ColoredPixel(new TextColor.RGB(205, 0, 0));
private static final Pixel STAMINA_COLOR = new ColoredPixel(new TextColor.RGB(207, 175, 89));
@InjectState
@@ -38,9 +39,22 @@ public class Stats {
float staminaDelta = (float) gameState.getPlayer().getStamina() / Player.MAX_STAMINA;
float staminaAmount = (BAR_WIDTH - 2) * staminaDelta;
float healthDelts = (float) gameState.getPlayer().getHealth() / Player.MAX_HEALTH;
float healthAmount = (BAR_WIDTH - 2) * healthDelts;
for (int x = 0; x < BAR_WIDTH; x++) {
for (int y = 0; y < BAR_HEIGHT; y++) {
if (x == 0 || y == 0 || x == BAR_WIDTH - 1 || y == BAR_HEIGHT - 1 || x - 1 < staminaAmount) {
if (x == 0 || y == 0 || x == BAR_WIDTH - 1 || y == BAR_HEIGHT - 1 || x - 1 < healthAmount) {
buffer[y + OFFSET_Y][x + OFFSET_X] = HEALTH_COLOR;
} else {
buffer[y + OFFSET_Y][x + OFFSET_X] = new Empty();
}
}
}
for (int x = 0; x < BAR_WIDTH; x++) {
for (int y = BAR_HEIGHT + BAR_PADDING; y < BAR_PADDING + BAR_HEIGHT * 2; y++) {
if (x == 0 || y == BAR_HEIGHT + BAR_PADDING || x == BAR_WIDTH - 1 || y == BAR_PADDING + BAR_HEIGHT * 2 - 1 || x - 1 < staminaAmount) {
buffer[y + OFFSET_Y][x + OFFSET_X] = STAMINA_COLOR;
} else {
buffer[y + OFFSET_Y][x + OFFSET_X] = new Empty();