From f80c6a981517aa879f97e90c19c3b276fb29f97f Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Sat, 1 Mar 2025 22:58:08 +0100 Subject: [PATCH] feat: Added sheeps --- .../java/cz/jzitnik/game/SpriteLoader.java | 9 + .../game/annotations/BlockRegistry.java | 12 + .../game/annotations/ItemRegistry.java | 12 + .../entities/items/ItemBlockSupplier.java | 22 +- .../entities/items/ItemBlockSupplierNew.java | 57 ++++ .../game/mobs/services/pig/PigLogic.java | 4 +- .../game/mobs/services/sheep/SheepData.java | 12 + .../game/mobs/services/sheep/SheepLogic.java | 278 ++++++++++++++++++ .../cz/jzitnik/game/smelting/Smelting.java | 1 + .../java/cz/jzitnik/game/sprites/Sheep.java | 80 +++++ .../textures/items/cooked_mutton.ans | 25 ++ src/main/resources/textures/items/mutton.ans | 25 ++ .../textures/mobs/sheep/black/left.ans | 25 ++ .../textures/mobs/sheep/black/lefthurt.ans | 25 ++ .../textures/mobs/sheep/black/right.ans | 25 ++ .../textures/mobs/sheep/black/righthurt.ans | 25 ++ .../textures/mobs/sheep/brown/left.ans | 25 ++ .../textures/mobs/sheep/brown/lefthurt.ans | 25 ++ .../textures/mobs/sheep/brown/right.ans | 25 ++ .../textures/mobs/sheep/brown/righthurt.ans | 25 ++ .../textures/mobs/sheep/gray/left.ans | 25 ++ .../textures/mobs/sheep/gray/lefthurt.ans | 25 ++ .../textures/mobs/sheep/gray/right.ans | 25 ++ .../textures/mobs/sheep/gray/righthurt.ans | 25 ++ .../textures/mobs/sheep/light_gray/left.ans | 25 ++ .../mobs/sheep/light_gray/lefthurt.ans | 25 ++ .../textures/mobs/sheep/light_gray/right.ans | 25 ++ .../mobs/sheep/light_gray/righthurt.ans | 25 ++ .../textures/mobs/sheep/pink/left.ans | 25 ++ .../textures/mobs/sheep/pink/lefthurt.ans | 25 ++ .../textures/mobs/sheep/pink/right.ans | 25 ++ .../textures/mobs/sheep/pink/righthurt.ans | 25 ++ .../textures/mobs/sheep/white/left.ans | 25 ++ .../textures/mobs/sheep/white/lefthurt.ans | 25 ++ .../textures/mobs/sheep/white/right.ans | 25 ++ .../textures/mobs/sheep/white/righthurt.ans | 25 ++ 36 files changed, 1132 insertions(+), 5 deletions(-) create mode 100644 src/main/java/cz/jzitnik/game/annotations/BlockRegistry.java create mode 100644 src/main/java/cz/jzitnik/game/annotations/ItemRegistry.java create mode 100644 src/main/java/cz/jzitnik/game/entities/items/ItemBlockSupplierNew.java create mode 100644 src/main/java/cz/jzitnik/game/mobs/services/sheep/SheepData.java create mode 100644 src/main/java/cz/jzitnik/game/mobs/services/sheep/SheepLogic.java create mode 100644 src/main/java/cz/jzitnik/game/sprites/Sheep.java create mode 100644 src/main/resources/textures/items/cooked_mutton.ans create mode 100644 src/main/resources/textures/items/mutton.ans create mode 100644 src/main/resources/textures/mobs/sheep/black/left.ans create mode 100644 src/main/resources/textures/mobs/sheep/black/lefthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/black/right.ans create mode 100644 src/main/resources/textures/mobs/sheep/black/righthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/brown/left.ans create mode 100644 src/main/resources/textures/mobs/sheep/brown/lefthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/brown/right.ans create mode 100644 src/main/resources/textures/mobs/sheep/brown/righthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/gray/left.ans create mode 100644 src/main/resources/textures/mobs/sheep/gray/lefthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/gray/right.ans create mode 100644 src/main/resources/textures/mobs/sheep/gray/righthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/light_gray/left.ans create mode 100644 src/main/resources/textures/mobs/sheep/light_gray/lefthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/light_gray/right.ans create mode 100644 src/main/resources/textures/mobs/sheep/light_gray/righthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/pink/left.ans create mode 100644 src/main/resources/textures/mobs/sheep/pink/lefthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/pink/right.ans create mode 100644 src/main/resources/textures/mobs/sheep/pink/righthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/white/left.ans create mode 100644 src/main/resources/textures/mobs/sheep/white/lefthurt.ans create mode 100644 src/main/resources/textures/mobs/sheep/white/right.ans create mode 100644 src/main/resources/textures/mobs/sheep/white/righthurt.ans diff --git a/src/main/java/cz/jzitnik/game/SpriteLoader.java b/src/main/java/cz/jzitnik/game/SpriteLoader.java index 7f28f39..9ab9639 100644 --- a/src/main/java/cz/jzitnik/game/SpriteLoader.java +++ b/src/main/java/cz/jzitnik/game/SpriteLoader.java @@ -52,9 +52,13 @@ public class SpriteLoader { HUNGER, PIG, + SHEEP, ITEM_PORKCHOP, ITEM_COOKED_PORKCHOP, + + ITEM_MUTTON, + ITEM_COOKED_MUTTON, } public static final HashMap SPRITES_MAP = new HashMap<>(); @@ -96,10 +100,15 @@ public class SpriteLoader { SPRITES_MAP.put(SPRITES.ITEM_PORKCHOP, new SimpleSprite("items/porkchop.ans")); SPRITES_MAP.put(SPRITES.ITEM_COOKED_PORKCHOP, new SimpleSprite("items/cooked_porkchop.ans")); + SPRITES_MAP.put(SPRITES.ITEM_MUTTON, new SimpleSprite("items/mutton.ans")); + SPRITES_MAP.put(SPRITES.ITEM_COOKED_MUTTON, new SimpleSprite("items/cooked_mutton.ans")); + SPRITES_MAP.put(SPRITES.HEART, new Heart()); SPRITES_MAP.put(SPRITES.HUNGER, new Hunger()); SPRITES_MAP.put(SPRITES.PIG, new Pig()); + SPRITES_MAP.put(SPRITES.SHEEP, new Sheep()); + } public static SpriteList load() { diff --git a/src/main/java/cz/jzitnik/game/annotations/BlockRegistry.java b/src/main/java/cz/jzitnik/game/annotations/BlockRegistry.java new file mode 100644 index 0000000..58fcd2f --- /dev/null +++ b/src/main/java/cz/jzitnik/game/annotations/BlockRegistry.java @@ -0,0 +1,12 @@ +package cz.jzitnik.game.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface BlockRegistry { + String value(); +} diff --git a/src/main/java/cz/jzitnik/game/annotations/ItemRegistry.java b/src/main/java/cz/jzitnik/game/annotations/ItemRegistry.java new file mode 100644 index 0000000..a66f144 --- /dev/null +++ b/src/main/java/cz/jzitnik/game/annotations/ItemRegistry.java @@ -0,0 +1,12 @@ +package cz.jzitnik.game.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface ItemRegistry { + String value(); +} diff --git a/src/main/java/cz/jzitnik/game/entities/items/ItemBlockSupplier.java b/src/main/java/cz/jzitnik/game/entities/items/ItemBlockSupplier.java index f84f3a6..4bfc249 100644 --- a/src/main/java/cz/jzitnik/game/entities/items/ItemBlockSupplier.java +++ b/src/main/java/cz/jzitnik/game/entities/items/ItemBlockSupplier.java @@ -6,7 +6,9 @@ import cz.jzitnik.game.entities.Block; import cz.jzitnik.game.blocks.Chest; import cz.jzitnik.game.blocks.Furnace; import cz.jzitnik.game.mobs.services.pig.PigData; +import cz.jzitnik.game.mobs.services.sheep.SheepData; import cz.jzitnik.game.sprites.Pig; +import cz.jzitnik.game.sprites.Sheep; import java.util.ArrayList; import java.util.Arrays; @@ -149,14 +151,18 @@ public class ItemBlockSupplier { public static Item oakDoor() { return Helper.oakDoor(Blocks.oakDoor()); } - public static Item porkchop() { return new Item("porkchop", "Porkchop", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_PORKCHOP, 3); } - public static Item cookedPorkchop() { return new Item("cooked_porkchop", "Cooked porkchop", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_COOKED_PORKCHOP, 4); } + public static Item mutton() { + return new Item("mutton", "Mutton", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_MUTTON, 2); + } + public static Item cookedMutton() { + return new Item("cooked_mutton", "Cooked mutton", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_COOKED_MUTTON, 6); + } } public static class Mobs { @@ -168,7 +174,17 @@ public class ItemBlockSupplier { block.setSpriteState(Pig.PigState.RIGHT); block.setMineable(false); block.setData(new PigData()); - block.setHp(3); + block.setHp(10); + return block; + } + public static Block sheep(Sheep.SheepState sheepState) { + var block = new Block("sheep", SpriteLoader.SPRITES.SHEEP); + block.setMob(true); + block.setGhost(true); + block.setSpriteState(sheepState); + block.setMineable(false); + block.setData(new SheepData()); + block.setHp(8); return block; } } diff --git a/src/main/java/cz/jzitnik/game/entities/items/ItemBlockSupplierNew.java b/src/main/java/cz/jzitnik/game/entities/items/ItemBlockSupplierNew.java new file mode 100644 index 0000000..7142959 --- /dev/null +++ b/src/main/java/cz/jzitnik/game/entities/items/ItemBlockSupplierNew.java @@ -0,0 +1,57 @@ +package cz.jzitnik.game.entities.items; + +import cz.jzitnik.game.annotations.BlockRegistry; +import cz.jzitnik.game.annotations.ItemRegistry; +import cz.jzitnik.game.entities.Block; +import org.reflections.Reflections; + +import java.util.HashMap; +import java.util.Set; + +public class ItemBlockSupplierNew { + private static final HashMap registeredBlocks = new HashMap<>(); + private static final HashMap registeredItems = new HashMap<>(); + + static { + registerBlocks(); + registerItems(); + } + + private static void registerBlocks() { + Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry"); + Set> blockClasses = reflections.getTypesAnnotatedWith(BlockRegistry.class); + + for (Class clazz : blockClasses) { + try { + Block blockInstance = (Block) clazz.getDeclaredConstructor().newInstance(); + BlockRegistry annotation = clazz.getAnnotation(BlockRegistry.class); + registeredBlocks.put(annotation.value(), blockInstance); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private static void registerItems() { + Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry"); + Set> itemClasses = reflections.getTypesAnnotatedWith(ItemRegistry.class); + + for (Class clazz : itemClasses) { + try { + Item itemInstance = (Item) clazz.getDeclaredConstructor().newInstance(); + ItemRegistry annotation = clazz.getAnnotation(ItemRegistry.class); + registeredItems.put(annotation.value(), itemInstance); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + public static Block getBlock(String id) { + return registeredBlocks.get(id); + } + + public static Item getItem(String id) { + return registeredItems.get(id); + } +} diff --git a/src/main/java/cz/jzitnik/game/mobs/services/pig/PigLogic.java b/src/main/java/cz/jzitnik/game/mobs/services/pig/PigLogic.java index e3e3811..dae62ea 100644 --- a/src/main/java/cz/jzitnik/game/mobs/services/pig/PigLogic.java +++ b/src/main/java/cz/jzitnik/game/mobs/services/pig/PigLogic.java @@ -200,8 +200,8 @@ public class PigLogic implements EntityLogicInterface, EntitySpawnInterface, Ent @Override public void killed(Game game, Block mob) { - int amount = random.nextInt(3) + 1; - InventoryItem inventoryItem = new InventoryItem(amount, ItemBlockSupplier.Items.porkchop()); + int amount = random.nextInt(2) + 1; + InventoryItem inventoryItem = new InventoryItem(amount, ItemBlockSupplier.Items.mutton()); game.getInventory().addItem(inventoryItem); } } diff --git a/src/main/java/cz/jzitnik/game/mobs/services/sheep/SheepData.java b/src/main/java/cz/jzitnik/game/mobs/services/sheep/SheepData.java new file mode 100644 index 0000000..71e089e --- /dev/null +++ b/src/main/java/cz/jzitnik/game/mobs/services/sheep/SheepData.java @@ -0,0 +1,12 @@ +package cz.jzitnik.game.mobs.services.sheep; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class SheepData { + private int lastDirection = 1; // 1 = right, -1 = left + private int movementCooldown = 0; + private int jumpAttempts = 0; +} diff --git a/src/main/java/cz/jzitnik/game/mobs/services/sheep/SheepLogic.java b/src/main/java/cz/jzitnik/game/mobs/services/sheep/SheepLogic.java new file mode 100644 index 0000000..b2fcf29 --- /dev/null +++ b/src/main/java/cz/jzitnik/game/mobs/services/sheep/SheepLogic.java @@ -0,0 +1,278 @@ +package cz.jzitnik.game.mobs.services.sheep; + +import cz.jzitnik.game.Game; +import cz.jzitnik.game.annotations.EntityHurtAnimationHandler; +import cz.jzitnik.game.annotations.EntityKillHandler; +import cz.jzitnik.game.annotations.EntityLogic; +import cz.jzitnik.game.annotations.EntitySpawn; +import cz.jzitnik.game.entities.Block; +import cz.jzitnik.game.entities.items.InventoryItem; +import cz.jzitnik.game.entities.items.ItemBlockSupplier; +import cz.jzitnik.game.mobs.*; +import cz.jzitnik.game.sprites.Sheep; +import cz.jzitnik.tui.ScreenMovingCalculationProvider; +import org.jline.terminal.Terminal; + +import java.util.*; + +import static cz.jzitnik.game.sprites.Sheep.SheepState.*; + +@EntitySpawn +@EntityLogic("sheep") +@EntityHurtAnimationHandler("sheep") +@EntityKillHandler("sheep") +public class SheepLogic implements EntityLogicInterface, EntitySpawnInterface, EntityHurtAnimationChanger, EntityKillInterface { + private final Random random = new Random(); + + @Override + public void nextIteration(EntityLogicProvider.EntityLogicMobDTO entityLogicMobDTO) { + int sheepX = entityLogicMobDTO.getX(); + int sheepY = entityLogicMobDTO.getY(); + var game = entityLogicMobDTO.getGame(); + var sheep = entityLogicMobDTO.getMob(); + var world = game.getWorld(); + var sheepData = (SheepData) sheep.getData(); + + boolean updated = false; + int newSheepX = sheepX; + int newSheepY = sheepY; + + if (sheepData.getMovementCooldown() > 0) { + sheepData.setMovementCooldown(sheepData.getMovementCooldown() - 1); + return; + } + + int direction = sheepData.getLastDirection(); + if (random.nextInt(10) < 1) { // 10% chance to change direction + direction = -direction; + } + sheepData.setLastDirection(direction); + + boolean isHurt = sheep.getSpriteState().get().name().endsWith("_HURT"); + Sheep.SheepState newState = switch (sheep.getSpriteState().get()) { + case WHITE_LEFT, WHITE_RIGHT, WHITE_LEFT_HURT, WHITE_RIGHT_HURT -> + isHurt ? (direction == 1 ? WHITE_RIGHT_HURT : WHITE_LEFT_HURT) + : (direction == 1 ? WHITE_RIGHT : WHITE_LEFT); + + case LIGHT_GRAY_LEFT, LIGHT_GRAY_RIGHT, LIGHT_GRAY_LEFT_HURT, LIGHT_GRAY_RIGHT_HURT -> + isHurt ? (direction == 1 ? LIGHT_GRAY_RIGHT_HURT : LIGHT_GRAY_LEFT_HURT) + : (direction == 1 ? LIGHT_GRAY_RIGHT : LIGHT_GRAY_LEFT); + + case GRAY_LEFT, GRAY_RIGHT, GRAY_LEFT_HURT, GRAY_RIGHT_HURT -> + isHurt ? (direction == 1 ? GRAY_RIGHT_HURT : GRAY_LEFT_HURT) + : (direction == 1 ? GRAY_RIGHT : GRAY_LEFT); + + case BLACK_LEFT, BLACK_RIGHT, BLACK_LEFT_HURT, BLACK_RIGHT_HURT -> + isHurt ? (direction == 1 ? BLACK_RIGHT_HURT : BLACK_LEFT_HURT) + : (direction == 1 ? BLACK_RIGHT : BLACK_LEFT); + + case BROWN_LEFT, BROWN_RIGHT, BROWN_LEFT_HURT, BROWN_RIGHT_HURT -> + isHurt ? (direction == 1 ? BROWN_RIGHT_HURT : BROWN_LEFT_HURT) + : (direction == 1 ? BROWN_RIGHT : BROWN_LEFT); + + case PINK_LEFT, PINK_RIGHT, PINK_LEFT_HURT, PINK_RIGHT_HURT -> + isHurt ? (direction == 1 ? PINK_RIGHT_HURT : PINK_LEFT_HURT) + : (direction == 1 ? PINK_RIGHT : PINK_LEFT); + default -> throw new IllegalStateException("Unexpected value: " + sheep.getSpriteState().get()); + }; + sheep.setSpriteState(newState); + + + List blocksAhead = world[sheepY][sheepX + direction]; + if (!game.isSolid(blocksAhead)) { + world[sheepY][sheepX].remove(sheep); + world[sheepY][sheepX + direction].add(sheep); + newSheepX = sheepX + direction; + updated = true; + sheepData.setJumpAttempts(0); + } else { + List blocksAboveAhead = world[sheepY - 1][sheepX + direction]; + List blocksTwoAboveAhead = world[sheepY - 2][sheepX + direction]; + + if (!game.isSolid(blocksAboveAhead) && game.isSolid(blocksAhead) && !game.isSolid(blocksTwoAboveAhead)) { + if (sheepData.getJumpAttempts() < 2) { + world[sheepY][sheepX].remove(sheep); + world[sheepY - 1][sheepX + direction].add(sheep); + newSheepX = sheepX + direction; + newSheepY = sheepY - 1; + updated = true; + sheepData.setJumpAttempts(sheepData.getJumpAttempts() + 1); + } + } + } + + while (updated) { + if (!game.isSolid(world[newSheepY + 1][newSheepX])) { + if (newSheepY - sheepY < 3) { + world[newSheepY][newSheepX].remove(sheep); + world[newSheepY + 1][newSheepX].add(sheep); + newSheepY++; + } else { + updated = false; + } + } else { + updated = false; + } + } + + sheepData.setMovementCooldown(random.nextInt(3) + 1); // 1-3 iterations cooldown + } + + @Override + public void spawn(int playerX, int playerY, Game game, Terminal terminal) { + // Cordinates where player can see + int[] data = ScreenMovingCalculationProvider.calculate(playerX, playerY, terminal.getHeight(), terminal.getWidth(), game.getWorld()[0].length, game.getWorld().length); + var world = game.getWorld(); + int startX = data[0]; + int endX = data[1]; + + // Left side + int lstartX = startX - 20; + int lendX = startX - 5; + int lstartY = playerY - 15; + int lendY = playerY + 15; + + if (countSheep(lstartX, lendX, lstartY, lendY, game) < 3 && random.nextInt(100) < 2) { + var spawnLocations = sheepCanSpawn(lstartX, lendX, playerY, game); + if (!spawnLocations.isEmpty()) { + System.out.println(spawnLocations.size()); + for (int i = 0; i < Math.min(4, spawnLocations.size()); i++) { + var randomLocation = getRandomEntry(spawnLocations); + int x = randomLocation.getKey(); + int y = randomLocation.getValue(); + + world[y][x].add(getSheep()); + } + } + } + + // Right side + int rstartX = endX + 5; + int rendX = endX + 20; + int rstartY = playerY - 15; + int rendY = playerY + 15; + + if (countSheep(rstartX, rendX, rstartY, rendY, game) < 3 && random.nextInt(100) < 2) { + var spawnLocations = sheepCanSpawn(rstartX, rendX, playerY, game); + if (!spawnLocations.isEmpty()) { + System.out.println(spawnLocations.size()); + for (int i = 0; i < Math.min(random.nextInt(3) + 2, spawnLocations.size()); i++) { + var randomLocation = getRandomEntry(spawnLocations); + int x = randomLocation.getKey(); + int y = randomLocation.getValue(); + + world[y][x].add(getSheep()); + } + } + } + } + + public static Map.Entry getRandomEntry(HashMap map) { + List> entryList = new ArrayList<>(map.entrySet()); + Random random = new Random(); + return entryList.get(random.nextInt(entryList.size())); + } + + private HashMap sheepCanSpawn(int startX, int endX, int playerY, Game game) { + var map = new HashMap(); + var world = game.getWorld(); + for (int x = startX; x <= endX; x++) { + for (int y = Math.max(0, playerY - 30); y < Math.min(world.length, playerY + 30); y++) { + if (world[y][x].stream().anyMatch(i -> i.getBlockId().equals("grass"))) { + map.put(x, y - 1); + } + } + } + + return map; + } + + private long countSheep(int startX, int endX, int startY, int endY, Game game) { + long sheepAmount = 0; + for (int y = startY; y <= endY; y++) { + for (int x = startX; x <= endX; x++) { + sheepAmount += game.getWorld()[y][x].stream().filter(i -> i.getBlockId().equals("sheep")).count(); + } + } + + return sheepAmount; + } + + private Block getSheep() { + int num = random.nextInt(100); + + if (num < 1) { + return ItemBlockSupplier.Mobs.sheep(PINK_RIGHT); + } + + if (num < 4) { + return ItemBlockSupplier.Mobs.sheep(BROWN_RIGHT); + } + + if (num < 15) { + int num1 = random.nextInt(3); + return switch (num1) { + case 0 -> ItemBlockSupplier.Mobs.sheep(LIGHT_GRAY_RIGHT); + case 1 -> ItemBlockSupplier.Mobs.sheep(GRAY_RIGHT); + case 2 -> ItemBlockSupplier.Mobs.sheep(BLACK_RIGHT); + default -> throw new IllegalStateException("Unexpected value: " + num1); + }; + } + + return ItemBlockSupplier.Mobs.sheep(WHITE_RIGHT); + } + + public Sheep.SheepState setHurtAnimation(boolean hurt, Enum current) { + if (hurt) { + return switch (current) { + case WHITE_LEFT, WHITE_LEFT_HURT -> WHITE_LEFT_HURT; + case WHITE_RIGHT, WHITE_RIGHT_HURT -> WHITE_RIGHT_HURT; + + case LIGHT_GRAY_LEFT, LIGHT_GRAY_LEFT_HURT -> LIGHT_GRAY_LEFT_HURT; + case LIGHT_GRAY_RIGHT, LIGHT_GRAY_RIGHT_HURT -> LIGHT_GRAY_RIGHT_HURT; + + case GRAY_LEFT, GRAY_LEFT_HURT -> GRAY_LEFT_HURT; + case GRAY_RIGHT, GRAY_RIGHT_HURT -> GRAY_RIGHT_HURT; + + case BLACK_LEFT, BLACK_LEFT_HURT -> BLACK_LEFT_HURT; + case BLACK_RIGHT, BLACK_RIGHT_HURT -> BLACK_RIGHT_HURT; + + case BROWN_LEFT, BROWN_LEFT_HURT -> BROWN_LEFT_HURT; + case BROWN_RIGHT, BROWN_RIGHT_HURT -> BROWN_RIGHT_HURT; + + case PINK_LEFT, PINK_LEFT_HURT -> PINK_LEFT_HURT; + case PINK_RIGHT, PINK_RIGHT_HURT -> PINK_RIGHT_HURT; + default -> throw new IllegalStateException("Unexpected value: " + current); + }; + } else { + return switch (current) { + case WHITE_LEFT, WHITE_LEFT_HURT -> WHITE_LEFT; + case WHITE_RIGHT, WHITE_RIGHT_HURT -> WHITE_RIGHT; + + case LIGHT_GRAY_LEFT, LIGHT_GRAY_LEFT_HURT -> LIGHT_GRAY_LEFT; + case LIGHT_GRAY_RIGHT, LIGHT_GRAY_RIGHT_HURT -> LIGHT_GRAY_RIGHT; + + case GRAY_LEFT, GRAY_LEFT_HURT -> GRAY_LEFT; + case GRAY_RIGHT, GRAY_RIGHT_HURT -> GRAY_RIGHT; + + case BLACK_LEFT, BLACK_LEFT_HURT -> BLACK_LEFT; + case BLACK_RIGHT, BLACK_RIGHT_HURT -> BLACK_RIGHT; + + case BROWN_LEFT, BROWN_LEFT_HURT -> BROWN_LEFT; + case BROWN_RIGHT, BROWN_RIGHT_HURT -> BROWN_RIGHT; + + case PINK_LEFT, PINK_LEFT_HURT -> PINK_LEFT; + case PINK_RIGHT, PINK_RIGHT_HURT -> PINK_RIGHT; + default -> throw new IllegalStateException("Unexpected value: " + current); + }; + } + } + + + @Override + public void killed(Game game, Block mob) { + int amount = random.nextInt(3) + 1; + InventoryItem inventoryItem = new InventoryItem(amount, ItemBlockSupplier.Items.porkchop()); + game.getInventory().addItem(inventoryItem); + } +} diff --git a/src/main/java/cz/jzitnik/game/smelting/Smelting.java b/src/main/java/cz/jzitnik/game/smelting/Smelting.java index b2fec07..3410986 100644 --- a/src/main/java/cz/jzitnik/game/smelting/Smelting.java +++ b/src/main/java/cz/jzitnik/game/smelting/Smelting.java @@ -12,6 +12,7 @@ public class Smelting { static { smeltingList.put("cobblestone", ItemBlockSupplier.Items::stone); smeltingList.put("porkchop", ItemBlockSupplier.Items::cookedPorkchop); + smeltingList.put("mutton", ItemBlockSupplier.Items::cookedMutton); } public static final HashMap fuelList = new HashMap<>(); diff --git a/src/main/java/cz/jzitnik/game/sprites/Sheep.java b/src/main/java/cz/jzitnik/game/sprites/Sheep.java new file mode 100644 index 0000000..29602b4 --- /dev/null +++ b/src/main/java/cz/jzitnik/game/sprites/Sheep.java @@ -0,0 +1,80 @@ +package cz.jzitnik.game.sprites; + +import cz.jzitnik.tui.ResourceLoader; +import cz.jzitnik.tui.Sprite; + +public class Sheep extends Sprite { + public enum SheepState { + WHITE_LEFT, + WHITE_RIGHT, + WHITE_LEFT_HURT, + WHITE_RIGHT_HURT, + + LIGHT_GRAY_LEFT, + LIGHT_GRAY_RIGHT, + LIGHT_GRAY_LEFT_HURT, + LIGHT_GRAY_RIGHT_HURT, + + GRAY_LEFT, + GRAY_RIGHT, + GRAY_LEFT_HURT, + GRAY_RIGHT_HURT, + + BLACK_LEFT, + BLACK_RIGHT, + BLACK_LEFT_HURT, + BLACK_RIGHT_HURT, + + BROWN_LEFT, + BROWN_RIGHT, + BROWN_LEFT_HURT, + BROWN_RIGHT_HURT, + + PINK_LEFT, + PINK_RIGHT, + PINK_LEFT_HURT, + PINK_RIGHT_HURT, + } + + public String getSprite() { + return getSprite(SheepState.WHITE_RIGHT); + } + + public String getSprite(Enum e) { + return ResourceLoader.loadResource( + switch (e) { + case SheepState.WHITE_LEFT -> "mobs/sheep/white/left.ans"; + case SheepState.WHITE_RIGHT -> "mobs/sheep/white/right.ans"; + case SheepState.WHITE_LEFT_HURT -> "mobs/sheep/white/lefthurt.ans"; + case SheepState.WHITE_RIGHT_HURT -> "mobs/sheep/white/righthurt.ans"; + + case SheepState.LIGHT_GRAY_LEFT -> "mobs/sheep/light_gray/left.ans"; + case SheepState.LIGHT_GRAY_RIGHT -> "mobs/sheep/light_gray/right.ans"; + case SheepState.LIGHT_GRAY_LEFT_HURT -> "mobs/sheep/light_gray/lefthurt.ans"; + case SheepState.LIGHT_GRAY_RIGHT_HURT -> "mobs/sheep/light_gray/righthurt.ans"; + + case SheepState.GRAY_LEFT -> "mobs/sheep/gray/left.ans"; + case SheepState.GRAY_RIGHT -> "mobs/sheep/gray/right.ans"; + case SheepState.GRAY_LEFT_HURT -> "mobs/sheep/gray/lefthurt.ans"; + case SheepState.GRAY_RIGHT_HURT -> "mobs/sheep/gray/righthurt.ans"; + + case SheepState.BLACK_LEFT -> "mobs/sheep/black/left.ans"; + case SheepState.BLACK_RIGHT -> "mobs/sheep/black/right.ans"; + case SheepState.BLACK_LEFT_HURT -> "mobs/sheep/black/lefthurt.ans"; + case SheepState.BLACK_RIGHT_HURT -> "mobs/sheep/black/righthurt.ans"; + + case SheepState.BROWN_LEFT -> "mobs/sheep/brown/left.ans"; + case SheepState.BROWN_RIGHT -> "mobs/sheep/brown/right.ans"; + case SheepState.BROWN_LEFT_HURT -> "mobs/sheep/brown/lefthurt.ans"; + case SheepState.BROWN_RIGHT_HURT -> "mobs/sheep/brown/righthurt.ans"; + + case SheepState.PINK_LEFT -> "mobs/sheep/pink/left.ans"; + case SheepState.PINK_RIGHT -> "mobs/sheep/pink/right.ans"; + case SheepState.PINK_LEFT_HURT -> "mobs/sheep/pink/lefthurt.ans"; + case SheepState.PINK_RIGHT_HURT -> "mobs/sheep/pink/righthurt.ans"; + + default -> throw new IllegalStateException("Unexpected value: " + e); + } + ); + } +} \ No newline at end of file diff --git a/src/main/resources/textures/items/cooked_mutton.ans b/src/main/resources/textures/items/cooked_mutton.ans new file mode 100644 index 0000000..76d7c1f --- /dev/null +++ b/src/main/resources/textures/items/cooked_mutton.ans @@ -0,0 +1,25 @@ +                                                   +                                                   +                                              +                                           +                                           +                                           +                                        +                                        +                                        +                                     +                                     +                                    +                                  +                                  +                              +                              +                             +                         +                         +                            +                            +                            +                          +                                  +                                  diff --git a/src/main/resources/textures/items/mutton.ans b/src/main/resources/textures/items/mutton.ans new file mode 100644 index 0000000..5f14329 --- /dev/null +++ b/src/main/resources/textures/items/mutton.ans @@ -0,0 +1,25 @@ +                                                   +                                                   +                                               +                                            +                                           +                                            +                                        +                                          +                                           +                                         +                                        +                                     +                                    +                                    +                              +                               +                                 +                             +                             +                             +                            +                              +                            +                                +                                  diff --git a/src/main/resources/textures/mobs/sheep/black/left.ans b/src/main/resources/textures/mobs/sheep/black/left.ans new file mode 100644 index 0000000..bac49e5 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/black/left.ans @@ -0,0 +1,25 @@ +                                                   +                                        +                                        +                                        +               +           +                  +              +                  +                     +                         +                          +                        +                        +                                      +                                   +                                     +                                    +                                    +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/black/lefthurt.ans b/src/main/resources/textures/mobs/sheep/black/lefthurt.ans new file mode 100644 index 0000000..e93bab4 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/black/lefthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                     +                                   +                                   +    +     +     +     +    +            +             +             +               +               +                              +                                +                              +                              +                                 +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/black/right.ans b/src/main/resources/textures/mobs/sheep/black/right.ans new file mode 100644 index 0000000..0869ad4 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/black/right.ans @@ -0,0 +1,25 @@ +                                                   +                                      +                                      +                                      +       +     +       +          +             +              +                     +                      +                      +                       +                                  +                                   +                                   +                                     +                                 +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/black/righthurt.ans b/src/main/resources/textures/mobs/sheep/black/righthurt.ans new file mode 100644 index 0000000..2b8947f --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/black/righthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                      +                                        +                                         +              +             +            +                 +                 +                   +                    +                        +                     +                  +                              +                                 +                                   +                                 +                                   +                                         +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/brown/left.ans b/src/main/resources/textures/mobs/sheep/brown/left.ans new file mode 100644 index 0000000..276e9aa --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/brown/left.ans @@ -0,0 +1,25 @@ +                                                   +                                          +                                       +                                        +                 +                   +               +                +                    +                        +                         +                         +                        +                          +                                   +                                    +                                 +                                 +                                  +                                           +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/brown/lefthurt.ans b/src/main/resources/textures/mobs/sheep/brown/lefthurt.ans new file mode 100644 index 0000000..b1f076c --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/brown/lefthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                        +                                       +                                        +               +                    +              +                     +                    +                       +                         +                          +                        +                       +                                    +                                  +                                 +                                   +                                   +                                           +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/brown/right.ans b/src/main/resources/textures/mobs/sheep/brown/right.ans new file mode 100644 index 0000000..a508ba2 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/brown/right.ans @@ -0,0 +1,25 @@ +                                                   +                                         +                                       +                                        +                +                +               +                 +                   +                     +                          +                        +                      +                         +                                     +                                  +                                 +                                 +                                   +                                           +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/brown/righthurt.ans b/src/main/resources/textures/mobs/sheep/brown/righthurt.ans new file mode 100644 index 0000000..79356e0 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/brown/righthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                        +                                        +                                         +                 +               +                 +                  +                  +                        +                          +                        +                          +                          +                                     +                                    +                                   +                                    +                                     +                                           +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/gray/left.ans b/src/main/resources/textures/mobs/sheep/gray/left.ans new file mode 100644 index 0000000..e5453ce --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/gray/left.ans @@ -0,0 +1,25 @@ +                                                   +                                         +                                        +                                         +                 +                   +                   +              +                 +                     +                         +                          +                          +                        +                                   +                                     +                                   +                                   +                                    +                                         +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/gray/lefthurt.ans b/src/main/resources/textures/mobs/sheep/gray/lefthurt.ans new file mode 100644 index 0000000..03164f8 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/gray/lefthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                           +                                         +                                         +                  +                +                  +                    +                  +                           +                        +                           +                          +                        +                                     +                                    +                                      +                                      +                                     +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/gray/right.ans b/src/main/resources/textures/mobs/sheep/gray/right.ans new file mode 100644 index 0000000..c8c73a1 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/gray/right.ans @@ -0,0 +1,25 @@ +                                                   +                                         +                                       +                                         +               +                +               +              +               +                    +                        +                         +                     +                     +                                  +                                   +                                   +                                    +                                   +                                       +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/gray/righthurt.ans b/src/main/resources/textures/mobs/sheep/gray/righthurt.ans new file mode 100644 index 0000000..b9dac99 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/gray/righthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                           +                                         +                                          +                  +                  +                     +                     +                       +                          +                           +                          +                       +                           +                                    +                                     +                                     +                                   +                                       +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/light_gray/left.ans b/src/main/resources/textures/mobs/sheep/light_gray/left.ans new file mode 100644 index 0000000..a57f911 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/light_gray/left.ans @@ -0,0 +1,25 @@ +                                                   +                                         +                                      +                                          +                 +                    +                       +                   +                       +                          +                          +                            +                          +                          +                                     +                                  +                                   +                                    +                                     +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/light_gray/lefthurt.ans b/src/main/resources/textures/mobs/sheep/light_gray/lefthurt.ans new file mode 100644 index 0000000..52433cf --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/light_gray/lefthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                        +                                      +                                        +                 +              +              +               +               +                   +                       +                       +                       +                     +                                  +                                  +                                 +                                 +                                  +                                       +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/light_gray/right.ans b/src/main/resources/textures/mobs/sheep/light_gray/right.ans new file mode 100644 index 0000000..4e63533 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/light_gray/right.ans @@ -0,0 +1,25 @@ +                                                   +                                         +                                        +                                         +                      +                   +                    +                    +                   +                            +                            +                            +                        +                        +                                     +                                  +                                     +                                   +                                    +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/light_gray/righthurt.ans b/src/main/resources/textures/mobs/sheep/light_gray/righthurt.ans new file mode 100644 index 0000000..263ca3e --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/light_gray/righthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                        +                                       +                                        +                   +                 +                +                +                +                     +                         +                        +                       +                       +                                    +                                  +                                 +                                 +                                  +                                       +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/pink/left.ans b/src/main/resources/textures/mobs/sheep/pink/left.ans new file mode 100644 index 0000000..eb8d58d --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/pink/left.ans @@ -0,0 +1,25 @@ +                                                   +                                          +                                          +                                          +                   +                    +                   +                     +                       +                      +                           +                            +                              +                          +                                       +                                    +                                    +                                     +                                     +                                         +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/pink/lefthurt.ans b/src/main/resources/textures/mobs/sheep/pink/lefthurt.ans new file mode 100644 index 0000000..c800b19 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/pink/lefthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                        +                                       +                                         +                    +                  +               +                        +                 +                     +                           +                          +                     +                       +                                    +                                   +                                  +                                   +                                    +                                         +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/pink/right.ans b/src/main/resources/textures/mobs/sheep/pink/right.ans new file mode 100644 index 0000000..f82d83f --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/pink/right.ans @@ -0,0 +1,25 @@ +                                                   +                                         +                                        +                                        +                      +                    +                    +                 +                     +                       +                           +                             +                          +                      +                                    +                                    +                                     +                                     +                                     +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/pink/righthurt.ans b/src/main/resources/textures/mobs/sheep/pink/righthurt.ans new file mode 100644 index 0000000..1ef01f0 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/pink/righthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                        +                                      +                                        +                   +                 +              +                 +                  +                       +                           +                           +                          +                     +                                  +                                    +                                    +                                   +                                    +                                         +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/white/left.ans b/src/main/resources/textures/mobs/sheep/white/left.ans new file mode 100644 index 0000000..d8f5327 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/white/left.ans @@ -0,0 +1,25 @@ +                                                   +                                           +                                          +                       +                     +                     +                    +                  +                       +                      +                          +                            +                          +                         +                                   +                                     +                                     +                                     +                                       +                                         +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/white/lefthurt.ans b/src/main/resources/textures/mobs/sheep/white/lefthurt.ans new file mode 100644 index 0000000..8c1b205 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/white/lefthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                           +                                         +                                         +                  +                   +                 +                 +                       +                        +                        +                        +                        +                          +                                    +                                  +                                    +                                     +                                    +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/white/right.ans b/src/main/resources/textures/mobs/sheep/white/right.ans new file mode 100644 index 0000000..636a64a --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/white/right.ans @@ -0,0 +1,25 @@ +                                                   +                                          +                                         +                 +                    +               +                +               +                  +                       +                         +                           +                      +                      +                                 +                                    +                                   +                                    +                                     +                                        +                                           +                                           +                                           +                                           +                                     diff --git a/src/main/resources/textures/mobs/sheep/white/righthurt.ans b/src/main/resources/textures/mobs/sheep/white/righthurt.ans new file mode 100644 index 0000000..0ab2d97 --- /dev/null +++ b/src/main/resources/textures/mobs/sheep/white/righthurt.ans @@ -0,0 +1,25 @@ +                                                   +                                          +                                          +                                         +                 +                 +             +               +                   +                   +                        +                       +                     +                      +                                 +                                    +                                  +                                   +                                    +                                         +                                           +                                           +                                           +                                           +