added player inventory

This commit is contained in:
2025-11-30 17:06:31 +01:00
parent 46b8c66ff5
commit cfea57e542
9 changed files with 166 additions and 54 deletions

View File

@@ -64,6 +64,7 @@ public class Entity {
// ITEM ATTRIBUTES
public int attackValue;
public int defenseValue;
public String description;
public Entity(GamePanel panel) {
this.panel = panel;

View File

@@ -5,10 +5,12 @@ import de.miaurizius.jgame2d.core.enums.Direction;
import de.miaurizius.jgame2d.core.enums.EntityType;
import de.miaurizius.jgame2d.core.enums.GameState;
import de.miaurizius.jgame2d.core.handlers.KeyHandler;
import de.miaurizius.jgame2d.entity.item.KeyObj;
import de.miaurizius.jgame2d.entity.item.ShieldWoodObj;
import de.miaurizius.jgame2d.entity.item.SwordNormalObj;
import java.awt.*;
import java.util.ArrayList;
public class Player extends Entity {
@@ -18,6 +20,7 @@ public class Player extends Entity {
// STATE
public boolean attackCancel;
public ArrayList<Entity> inventory = new ArrayList<>();
public Player(GamePanel panel, KeyHandler keyH) {
super(panel);
@@ -238,6 +241,16 @@ public class Player extends Entity {
currentShield = new ShieldWoodObj(panel);
attack = getAttack();
defense = getDefense();
// INVENTORY
inventory.add(currentWeapon);
inventory.add(currentShield);
inventory.add(new KeyObj(panel));
inventory.add(new KeyObj(panel));
inventory.add(new KeyObj(panel));
inventory.add(new KeyObj(panel));
inventory.add(new KeyObj(panel));
inventory.add(new KeyObj(panel));
}
public int getAttack() {
return attack = strength * currentWeapon.attackValue;

View File

@@ -8,7 +8,8 @@ public class KeyObj extends Entity {
public KeyObj(GamePanel panel) {
super(panel);
name = "key";
name = "Normal Key";
description = "[" + name + "]\nIt opens a door.";
type = EntityType.ITEM;
down1 = initEntitySprites("objects/key");
}

View File

@@ -8,7 +8,8 @@ public class ShieldWoodObj extends Entity {
public ShieldWoodObj(GamePanel panel) {
super(panel);
name = "shield-wood";
name = "Wooden Shield";
description = "[" + name + "]\nAn old shield.\nIt's not that strong but\nit does its job.";
type = EntityType.ITEM;
down1 = initEntitySprites("objects/shield_wood");
defenseValue = 1;

View File

@@ -9,7 +9,8 @@ public class SwordNormalObj extends Entity {
public SwordNormalObj(GamePanel panel) {
super(panel);
name = "sword-normal";
name = "Normal Sword";
description = "[" + name + "]\nAn old sword.";
type = EntityType.ITEM;
down1 = initEntitySprites("objects/sword_normal");
attackValue = 1;