feat: Show icons in stats
This commit is contained in:
@@ -36,7 +36,10 @@ public class ResourceManager {
|
||||
|
||||
APPLE("food/apple.png"),
|
||||
|
||||
DOORS("rooms/doors.png");
|
||||
DOORS("rooms/doors.png"),
|
||||
|
||||
STAMINA("ui/stamina.png"),
|
||||
HEART("ui/heart.png");
|
||||
|
||||
private final String path;
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package cz.jzitnik.game.setup.config;
|
||||
|
||||
import cz.jzitnik.game.ResourceManager;
|
||||
|
||||
public class EnemiesConfigSetup {
|
||||
private class Enemy {
|
||||
private ResourceManager.Resource texture;
|
||||
private int initialHealth;
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import cz.jzitnik.game.mobs.DialogMob;
|
||||
import cz.jzitnik.game.utils.RoomCords;
|
||||
import cz.jzitnik.utils.roomtasks.RoomTask;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class Pepa extends DialogMob {
|
||||
public Pepa(ResourceManager resourceManager, RoomCords cords) {
|
||||
super(resourceManager.getResource(ResourceManager.Resource.PLAYER_FRONT), new RoomTask[]{}, cords,
|
||||
@@ -17,14 +15,20 @@ public class Pepa extends DialogMob {
|
||||
new OnEnd.Continue(new Dialog(
|
||||
"Pepa: Never gonna let you down",
|
||||
new OnEnd.Continue(new Dialog(
|
||||
"Pepa: How it continues?", new OnEnd.AskQuestion(
|
||||
new OnEnd.AskQuestion.Answer[]{
|
||||
new OnEnd.AskQuestion.Answer("And desert you", new Dialog("Pepa: You are god damn right!", new OnEnd.Continue(null))),
|
||||
new OnEnd.AskQuestion.Answer("You are a dessert", new Dialog("Pepa: WRONG!", new OnEnd.Continue(null)))
|
||||
}
|
||||
)))
|
||||
"Pepa: Never gonna run around",
|
||||
new OnEnd.Continue(new Dialog(
|
||||
"Pepa: How it continues?", new OnEnd.AskQuestion(
|
||||
new OnEnd.AskQuestion.Answer[]{
|
||||
new OnEnd.AskQuestion.Answer("And desert you", new Dialog("Pepa: You are god damn right!", new OnEnd.Continue(null))),
|
||||
new OnEnd.AskQuestion.Answer("You are a dessert", new Dialog("Pepa: WRONG!", new OnEnd.Continue(null)))
|
||||
}
|
||||
)))
|
||||
))
|
||||
))
|
||||
)
|
||||
);
|
||||
|
||||
setTasks(new RoomTask[]{
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cz.jzitnik.game.setup;
|
||||
package cz.jzitnik.game.setup.scenes;
|
||||
|
||||
import com.googlecode.lanterna.input.KeyType;
|
||||
import cz.jzitnik.annotations.injectors.InjectDependency;
|
||||
@@ -1,4 +1,4 @@
|
||||
package cz.jzitnik.game.setup;
|
||||
package cz.jzitnik.game.setup.scenes;
|
||||
|
||||
import cz.jzitnik.screens.Screen;
|
||||
import cz.jzitnik.screens.scenes.Scene;
|
||||
@@ -2,27 +2,34 @@ package cz.jzitnik.ui;
|
||||
|
||||
import com.googlecode.lanterna.TextColor;
|
||||
import cz.jzitnik.annotations.Dependency;
|
||||
import cz.jzitnik.annotations.injectors.InjectDependency;
|
||||
import cz.jzitnik.annotations.injectors.InjectState;
|
||||
import cz.jzitnik.annotations.ui.Render;
|
||||
import cz.jzitnik.annotations.ui.UI;
|
||||
import cz.jzitnik.game.GameState;
|
||||
import cz.jzitnik.game.Player;
|
||||
import cz.jzitnik.game.ResourceManager;
|
||||
import cz.jzitnik.states.ScreenBuffer;
|
||||
import cz.jzitnik.ui.pixels.ColoredPixel;
|
||||
import cz.jzitnik.ui.pixels.Empty;
|
||||
import cz.jzitnik.ui.pixels.Pixel;
|
||||
import cz.jzitnik.utils.RerenderUtils;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
@Getter
|
||||
@UI
|
||||
@Dependency
|
||||
public class Stats {
|
||||
public static final int BARS_COUNT = 2;
|
||||
public static final int BAR_WIDTH = 72;
|
||||
public static final int ICON_SIZE = 9;
|
||||
public static final int ICON_BAR_MARGIN = 2;
|
||||
public static final int BAR_HEIGHT = 8;
|
||||
public static final int BAR_PADDING = 2;
|
||||
public static final int HEIGHT = BAR_HEIGHT * BARS_COUNT + (BAR_PADDING * (BARS_COUNT - 1));
|
||||
public static final int WIDTH = BAR_WIDTH;
|
||||
public static final int WIDTH = BAR_WIDTH + ICON_SIZE + ICON_BAR_MARGIN;
|
||||
|
||||
public static final int OFFSET_X = 5;
|
||||
public static final int OFFSET_Y = 5;
|
||||
@@ -36,6 +43,9 @@ public class Stats {
|
||||
@InjectState
|
||||
private ScreenBuffer screenBuffer;
|
||||
|
||||
@InjectDependency
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
@Render
|
||||
public void rerender() {
|
||||
var buffer = screenBuffer.getRenderedBuffer();
|
||||
@@ -49,21 +59,39 @@ public class Stats {
|
||||
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 < healthAmount) {
|
||||
buffer[y + OFFSET_Y][x + OFFSET_X] = HEALTH_COLOR;
|
||||
buffer[y + OFFSET_Y][x + OFFSET_X + ICON_SIZE + ICON_BAR_MARGIN] = HEALTH_COLOR;
|
||||
} else {
|
||||
buffer[y + OFFSET_Y][x + OFFSET_X] = new Empty();
|
||||
buffer[y + OFFSET_Y][x + OFFSET_X + ICON_SIZE + ICON_BAR_MARGIN] = new Empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BufferedImage heartImage = resourceManager.getResource(ResourceManager.Resource.HEART);
|
||||
for (int x = 0; x < heartImage.getWidth(); x++) {
|
||||
for (int y = 0; y < heartImage.getHeight(); y++) {
|
||||
var pixelData = RerenderUtils.getPixelData(heartImage.getRGB(x, y));
|
||||
|
||||
buffer[y + OFFSET_Y][x + OFFSET_X] = new ColoredPixel(new TextColor.RGB(pixelData.r(), pixelData.g(), pixelData.b()));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
buffer[y + OFFSET_Y][x + OFFSET_X + ICON_SIZE + ICON_BAR_MARGIN] = STAMINA_COLOR;
|
||||
} else {
|
||||
buffer[y + OFFSET_Y][x + OFFSET_X] = new Empty();
|
||||
buffer[y + OFFSET_Y][x + OFFSET_X + ICON_SIZE + ICON_BAR_MARGIN] = new Empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BufferedImage staminaImage = resourceManager.getResource(ResourceManager.Resource.STAMINA);
|
||||
for (int x = 0; x < staminaImage.getWidth(); x++) {
|
||||
for (int y = 0; y < staminaImage.getHeight(); y++) {
|
||||
var pixelData = RerenderUtils.getPixelData(staminaImage.getRGB(x, y));
|
||||
|
||||
buffer[y + OFFSET_Y + BAR_HEIGHT + BAR_PADDING][x + OFFSET_X] = new ColoredPixel(new TextColor.RGB(pixelData.r(), pixelData.g(), pixelData.b()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,17 +95,15 @@ public class RerenderUtils {
|
||||
RoomCords endObjectCords = new RoomCords(startObjectCords.getX() + texture.getWidth() - 1, startObjectCords.getY() + texture.getHeight() - 1);
|
||||
if (x >= startObjectCords.getX() && x <= endObjectCords.getX() && y >= startObjectCords.getY() && y <= endObjectCords.getY()) {
|
||||
int pixel = texture.getRGB(x - startObjectCords.getX(), y - startObjectCords.getY());
|
||||
int alpha = (pixel >> 24) & 0xff;
|
||||
int r = (pixel >> 16) & 0xff;
|
||||
int g = (pixel >> 8) & 0xff;
|
||||
int b = pixel & 0xff;
|
||||
var pixelData = getPixelData(pixel);
|
||||
int r, g, b;
|
||||
|
||||
if (alpha != 0) {
|
||||
if (pixelData.alpha != 0) {
|
||||
if (isSelected) {
|
||||
r = Math.min(255, (int) (r * factor));
|
||||
g = Math.min(255, (int) (g * factor));
|
||||
b = Math.min(255, (int) (b * factor));
|
||||
pixel = (alpha << 24) | (r << 16) | (g << 8) | b;
|
||||
r = Math.min(255, (int) (pixelData.r * factor));
|
||||
g = Math.min(255, (int) (pixelData.g * factor));
|
||||
b = Math.min(255, (int) (pixelData.b * factor));
|
||||
pixel = (pixelData.alpha << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
return new PixelResult(pixel, false);
|
||||
@@ -121,17 +119,15 @@ public class RerenderUtils {
|
||||
|
||||
if (x >= startDroppedItemCords.getX() && x <= endDroppedItemCords.getX() && y >= startDroppedItemCords.getY() && y <= endDroppedItemCords.getY()) {
|
||||
int pixel = texture.getRGB(x - startDroppedItemCords.getX(), y - startDroppedItemCords.getY());
|
||||
int alpha = (pixel >> 24) & 0xff;
|
||||
int r = (pixel >> 16) & 0xff;
|
||||
int g = (pixel >> 8) & 0xff;
|
||||
int b = pixel & 0xff;
|
||||
var pixelData = getPixelData(pixel);
|
||||
int r, g, b;
|
||||
|
||||
if (alpha != 0) {
|
||||
if (pixelData.alpha != 0) {
|
||||
if (isSelected) {
|
||||
r = Math.min(255, (int) (r * factor));
|
||||
g = Math.min(255, (int) (g * factor));
|
||||
b = Math.min(255, (int) (b * factor));
|
||||
pixel = (alpha << 24) | (r << 16) | (g << 8) | b;
|
||||
r = Math.min(255, (int) (pixelData.r * factor));
|
||||
g = Math.min(255, (int) (pixelData.g * factor));
|
||||
b = Math.min(255, (int) (pixelData.b * factor));
|
||||
pixel = (pixelData.alpha << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
return new PixelResult(pixel, false);
|
||||
@@ -147,17 +143,15 @@ public class RerenderUtils {
|
||||
RoomCords endObjectCords = new RoomCords(startObjectCords.getX() + texture.getWidth() - 1, startObjectCords.getY() + texture.getHeight() - 1);
|
||||
if (x >= startObjectCords.getX() && x <= endObjectCords.getX() && y >= startObjectCords.getY() && y <= endObjectCords.getY()) {
|
||||
int pixel = texture.getRGB(x - startObjectCords.getX(), y - startObjectCords.getY());
|
||||
int alpha = (pixel >> 24) & 0xff;
|
||||
int r = (pixel >> 16) & 0xff;
|
||||
int g = (pixel >> 8) & 0xff;
|
||||
int b = pixel & 0xff;
|
||||
var pixelData = getPixelData(pixel);
|
||||
int r, g, b;
|
||||
|
||||
if (alpha != 0) {
|
||||
if (pixelData.alpha != 0) {
|
||||
if (isSelected) {
|
||||
r = Math.min(255, (int) (r * factor));
|
||||
g = Math.min(255, (int) (g * factor));
|
||||
b = Math.min(255, (int) (b * factor));
|
||||
pixel = (alpha << 24) | (r << 16) | (g << 8) | b;
|
||||
r = Math.min(255, (int) (pixelData.r * factor));
|
||||
g = Math.min(255, (int) (pixelData.g * factor));
|
||||
b = Math.min(255, (int) (pixelData.b * factor));
|
||||
pixel = (pixelData.alpha << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
return new PixelResult(pixel, false);
|
||||
@@ -197,4 +191,16 @@ public class RerenderUtils {
|
||||
|
||||
return doorPositions;
|
||||
}
|
||||
|
||||
public record ColorData(int r, int g, int b, int alpha) {
|
||||
}
|
||||
|
||||
public static ColorData getPixelData(int pixel) {
|
||||
int alpha = (pixel >> 24) & 0xff;
|
||||
int r = (pixel >> 16) & 0xff;
|
||||
int g = (pixel >> 8) & 0xff;
|
||||
int b = pixel & 0xff;
|
||||
|
||||
return new ColorData(r, g, b, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
src/main/resources/textures/ui/heart.png
Normal file
BIN
src/main/resources/textures/ui/heart.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 262 B |
BIN
src/main/resources/textures/ui/stamina.png
Normal file
BIN
src/main/resources/textures/ui/stamina.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 138 B |
Reference in New Issue
Block a user