feat: Better drop item placements
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cz.jzitnik;
|
||||
|
||||
import cz.jzitnik.annotations.injectors.InjectDependency;
|
||||
import cz.jzitnik.game.setup.GameSetup;
|
||||
import cz.jzitnik.utils.DependencyManager;
|
||||
import cz.jzitnik.utils.GlobalIOHandlerRepository;
|
||||
@@ -10,13 +11,19 @@ import org.reflections.Reflections;
|
||||
public class Game {
|
||||
private final DependencyManager dependencyManager = new DependencyManager(new Reflections("cz.jzitnik"));
|
||||
|
||||
public void start() {
|
||||
Cli cli = dependencyManager.getDependencyOrThrow(Cli.class);
|
||||
@InjectDependency
|
||||
private Cli cli;
|
||||
@InjectDependency
|
||||
private GameSetup gameSetup;
|
||||
@InjectDependency
|
||||
private ThreadManager threadManager;
|
||||
@InjectDependency
|
||||
private ScheduledTaskManager scheduledTaskManager;
|
||||
@InjectDependency
|
||||
private GlobalIOHandlerRepository globalIOHandlerRepository;
|
||||
|
||||
GameSetup gameSetup = dependencyManager.getDependencyOrThrow(GameSetup.class);
|
||||
ThreadManager threadManager = dependencyManager.getDependencyOrThrow(ThreadManager.class);
|
||||
ScheduledTaskManager scheduledTaskManager = dependencyManager.getDependencyOrThrow(ScheduledTaskManager.class);
|
||||
GlobalIOHandlerRepository globalIOHandlerRepository = dependencyManager.getDependencyOrThrow(GlobalIOHandlerRepository.class);
|
||||
public void start() {
|
||||
dependencyManager.inject(this);
|
||||
|
||||
try {
|
||||
gameSetup.setup();
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@Config
|
||||
public class PlayerConfig {
|
||||
private final double playerReach = 20;
|
||||
private final double playerReach = 50;
|
||||
private final int playerMoveDistance = 3;
|
||||
private final int playerMoveDistanceSprinting = 6;
|
||||
private final PlayerMoveEventHandler.SprintKey sprintKey = PlayerMoveEventHandler.SprintKey.CTRL;
|
||||
|
||||
@@ -130,7 +130,7 @@ public class MouseMoveEventHandler extends AbstractEventHandler<MouseMoveEvent>
|
||||
int objYEnd = cords.getY() + texture.getHeight();
|
||||
|
||||
int playerMiddleX = playerCords.getX() + (playerTexture.getWidth() / 2);
|
||||
int playerMiddleY = playerCords.getY() + (playerTexture.getHeight() / 3); // This is not middle but whatever
|
||||
int playerMiddleY = playerCords.getY() + (playerTexture.getHeight() / 2);
|
||||
|
||||
double distance = distancePointToRect(
|
||||
playerMiddleX, playerMiddleY,
|
||||
|
||||
@@ -7,7 +7,6 @@ import cz.jzitnik.game.mobs.HittableMob;
|
||||
import cz.jzitnik.game.utils.RoomCords;
|
||||
import cz.jzitnik.ui.Inventory;
|
||||
import cz.jzitnik.utils.DependencyManager;
|
||||
import cz.jzitnik.utils.StateManager;
|
||||
import cz.jzitnik.utils.events.Event;
|
||||
import cz.jzitnik.utils.events.EventManager;
|
||||
import lombok.Getter;
|
||||
@@ -115,8 +114,8 @@ public class Player {
|
||||
|
||||
// Probably in the future, there will be more logic like potions, etc.
|
||||
log.debug("Selected item: {}", selectedItem);
|
||||
if (selectedItem != null && selectedItem.getType() instanceof WeaponInterface item) {
|
||||
damage = item.getDamageDeal();
|
||||
if (selectedItem != null && selectedItem.getType() instanceof WeaponInterface weapon) {
|
||||
damage = weapon.getDamageDeal();
|
||||
}
|
||||
|
||||
return damage;
|
||||
|
||||
@@ -18,6 +18,7 @@ import cz.jzitnik.game.ResourceManager;
|
||||
import cz.jzitnik.game.items.GameItem;
|
||||
import cz.jzitnik.game.items.types.InteractableItem;
|
||||
import cz.jzitnik.game.objects.DroppedItem;
|
||||
import cz.jzitnik.game.utils.RoomCords;
|
||||
import cz.jzitnik.states.ScreenBuffer;
|
||||
import cz.jzitnik.states.TerminalState;
|
||||
import cz.jzitnik.ui.pixels.ColoredPixel;
|
||||
@@ -125,8 +126,18 @@ public class Inventory {
|
||||
var player = gameState.getPlayer();
|
||||
var inventory = player.getInventory();
|
||||
var currentRoom = gameState.getCurrentRoom();
|
||||
|
||||
RoomCords playerCords = gameState.getPlayer().getPlayerCords();
|
||||
BufferedImage playerTexture = gameState.getPlayer().getTexture(resourceManager);
|
||||
GameItem item = inventory[inventoryState.selectedItem];
|
||||
BufferedImage itemTexture = item.getTexture();
|
||||
RoomCords cords = new RoomCords(
|
||||
playerCords.getX() + (playerTexture.getWidth() / 2) - (itemTexture.getWidth() / 2),
|
||||
playerCords.getY() + playerTexture.getHeight() + 5
|
||||
);
|
||||
|
||||
// Create timer
|
||||
DroppedItem droppedItem = new DroppedItem(currentRoom, player.getPlayerCords().clone(), inventory[inventoryState.selectedItem]);
|
||||
DroppedItem droppedItem = new DroppedItem(currentRoom, cords, item);
|
||||
scheduledSerializedTaskManager.schedule(() -> {
|
||||
droppedItem.getRoom().getDroppedItems().remove(droppedItem);
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
- id: zombie1
|
||||
className: cz.jzitnik.game.setup.enemies.Zombie
|
||||
health: 10
|
||||
texture: PLAYER_FRONT
|
||||
cords:
|
||||
x: 100
|
||||
y: 100
|
||||
drops:
|
||||
- apple1
|
||||
tasks:
|
||||
- className: cz.jzitnik.game.mobs.tasks.MobFollowingPlayerTask
|
||||
args:
|
||||
speed: 1
|
||||
range: 100
|
||||
- className: cz.jzitnik.game.mobs.tasks.EnemyPlayerHittingTask
|
||||
args:
|
||||
cooldown: 500
|
||||
damage: 15
|
||||
hitSupplier:
|
||||
rules:
|
||||
- if: "health > 5"
|
||||
value: 5
|
||||
- value: 2
|
||||
@@ -1,15 +0,0 @@
|
||||
- id: sword1
|
||||
className: cz.jzitnik.game.setup.items.WoodenSword
|
||||
name: "Wooden sword"
|
||||
texture: WOODEN_SWORD
|
||||
itemType: cz.jzitnik.game.items.types.weapons.Sword
|
||||
properties:
|
||||
damageDeal: 2
|
||||
|
||||
- id: apple1
|
||||
className: cz.jzitnik.game.setup.items.Apple
|
||||
name: "Apple"
|
||||
texture: APPLE
|
||||
itemType: cz.jzitnik.game.items.types.food.Food
|
||||
properties:
|
||||
heal: 5
|
||||
@@ -1,57 +0,0 @@
|
||||
- id: room1
|
||||
className: cz.jzitnik.game.setup.rooms.MainRoom
|
||||
texture: ROOM1
|
||||
objects:
|
||||
- className: cz.jzitnik.game.objects.Chest
|
||||
cords:
|
||||
x: 100
|
||||
y: 45
|
||||
items:
|
||||
- sword1
|
||||
- apple1
|
||||
colliders:
|
||||
- from:
|
||||
x: 60
|
||||
y: 10
|
||||
to:
|
||||
x: 135
|
||||
y: 15
|
||||
mobs:
|
||||
- zombie1
|
||||
connections:
|
||||
right: room2
|
||||
|
||||
- id: room2
|
||||
className: cz.jzitnik.game.GameRoom
|
||||
texture: ROOM2
|
||||
objects: []
|
||||
colliders: []
|
||||
mobs: []
|
||||
connections:
|
||||
up: room3
|
||||
|
||||
- id: room3
|
||||
className: cz.jzitnik.game.GameRoom
|
||||
texture: ROOM3
|
||||
objects: []
|
||||
colliders: []
|
||||
mobs: []
|
||||
connections:
|
||||
up: room4
|
||||
|
||||
- id: room4
|
||||
className: cz.jzitnik.game.GameRoom
|
||||
texture: ROOM4
|
||||
objects: []
|
||||
colliders: []
|
||||
mobs: []
|
||||
connections:
|
||||
left: roomFrozen
|
||||
|
||||
- id: roomFrozen
|
||||
className: cz.jzitnik.game.GameRoom
|
||||
texture: ROOM_FROZEN
|
||||
objects: []
|
||||
colliders: []
|
||||
mobs: []
|
||||
connections: {}
|
||||
Reference in New Issue
Block a user