diff --git a/src/de/miaurizius/jgame2d/core/UI.java b/src/de/miaurizius/jgame2d/core/UI.java index 37687bb..aa8012a 100644 --- a/src/de/miaurizius/jgame2d/core/UI.java +++ b/src/de/miaurizius/jgame2d/core/UI.java @@ -2,6 +2,7 @@ package de.miaurizius.jgame2d.core; import de.miaurizius.jgame2d.core.enums.GameState; import de.miaurizius.jgame2d.entity.Entity; +import de.miaurizius.jgame2d.entity.item.CoinObj; import de.miaurizius.jgame2d.entity.item.HeartObj; import java.awt.*; @@ -16,15 +17,20 @@ public class UI { GamePanel panel; Graphics2D graphics2d; Font font; - BufferedImage heart_full, heart_half, heart_blank; + BufferedImage heart_full, heart_half, heart_blank, coin; ArrayList messages = new ArrayList<>(); ArrayList messageCounter = new ArrayList<>(); - public OptionState optionState; public String currentDialogue; + public Entity tradingNPC; public int commandNum; - public int slotCol, slotRow; + public int playerSlotCol, playerSlotRow; + public int npcSlotCol, npcSlotRow; private int transCounter; + // SUB-STATES + public TradeState tradeState = TradeState.SELECT; + public OptionState optionState; + public UI(GamePanel panel) { this.panel = panel; font = new Font("Arial", Font.PLAIN, 40); @@ -39,6 +45,8 @@ public class UI { heart_full = heart.image; heart_half = heart.image2; heart_blank = heart.image3; + Entity coin = new CoinObj(panel); + this.coin = coin.down1; } public void draw(Graphics2D graphics2d) { @@ -55,6 +63,7 @@ public class UI { case CHARACTER -> drawCharacterScreen(); case GAMEOVER -> drawGameOverScreen(); case TRANSITION -> drawTransitionScreen(); + case TRADE -> drawTradeScreen(); } } @@ -152,12 +161,26 @@ public class UI { textY += panel.tileSize; graphics2d.drawImage(panel.player.currentShield.down1, tailX - panel.tileSize, textY-14, null); } - private void drawInventory() { + private void drawInventory(Entity entity, boolean cursor) { + int frameX, frameY, frameWidth, frameHeight; + int slotCol, slotRow; + // DRAW FRAME - int frameX = panel.tileSize*12; - int frameY = panel.tileSize; - int frameWidth = panel.tileSize*6; - int frameHeight = panel.tileSize*5; + if(entity == panel.player) { + frameX = panel.tileSize*12; + frameY = panel.tileSize; + frameWidth = panel.tileSize*6; + frameHeight = panel.tileSize*5; + slotCol = playerSlotCol; + slotRow = playerSlotRow; + } else { + frameX = panel.tileSize*2; + frameY = panel.tileSize; + frameWidth = panel.tileSize*6; + frameHeight = panel.tileSize*5; + slotCol = npcSlotCol; + slotRow = npcSlotRow; + } drawSubWindow(frameX, frameY, frameWidth, frameHeight); // SLOT @@ -167,15 +190,15 @@ public class UI { int slotY = slotYStart; int slotSize = panel.tileSize+3; - // DRAW PLAYER ITEMS - for(int i = 0; i < panel.player.inventory.size(); i++) { + // DRAW ITEMS + for(int i = 0; i < entity.inventory.size(); i++) { // EQUIP CURSOR - if(panel.player.inventory.get(i) == panel.player.currentWeapon || panel.player.inventory.get(i) == panel.player.currentShield) { + if(entity.inventory.get(i) == entity.currentWeapon || entity.inventory.get(i) == entity.currentShield) { graphics2d.setColor(new Color(240, 190,90)); graphics2d.fillRoundRect(slotX, slotY, panel.tileSize, panel.tileSize, 10, 10); } - graphics2d.drawImage(panel.player.inventory.get(i).down1, slotX, slotY, null); + graphics2d.drawImage(entity.inventory.get(i).down1, slotX, slotY, null); slotX += slotSize; if (i == 4 || i == 9 || i == 14) { slotX = slotXStart; @@ -184,17 +207,17 @@ public class UI { } // CURSOR + if(!cursor) return; int curserX = slotXStart + (slotSize*slotCol); int curserY = slotYStart + (slotSize*slotRow); int curserHeight = panel.tileSize; int curserWidth = panel.tileSize; - graphics2d.setColor(Color.white); graphics2d.setStroke(new BasicStroke(3)); graphics2d.drawRoundRect(curserX, curserY, curserWidth, curserHeight, 10, 10); // DESCRIPTION FRAME - int itemIndex = getItemIndex(); + int itemIndex = getItemIndex(slotCol, slotRow); int dFrameX = frameX; int dFrameY = frameY + frameHeight+2; int dFrameWidth = frameWidth; @@ -204,9 +227,9 @@ public class UI { int textX = dFrameX + 20; int textY = dFrameY + panel.tileSize; graphics2d.setFont(graphics2d.getFont().deriveFont(28F)); - if(itemIndex < panel.player.inventory.size()) { + if(itemIndex < entity.inventory.size()) { drawSubWindow(dFrameX, dFrameY, dFrameWidth, dFrameHeight); - for(String line : panel.player.inventory.get(itemIndex).description.split("\n")) { + for(String line : entity.inventory.get(itemIndex).description.split("\n")) { graphics2d.drawString(line, textX, textY); textY += 32; } @@ -291,7 +314,7 @@ public class UI { } private void drawCharacterScreen() { drawCharStats(); - drawInventory(); + drawInventory(panel.player, true); } private void drawPlayScreen() { drawPlayerLife(); @@ -342,6 +365,105 @@ public class UI { panel.eventH.prevEventX = panel.player.worldX; panel.eventH.prevEventY = panel.player.worldY; } + private void drawTradeScreen() { + switch(tradeState) { + case SELECT -> tradeSelect(); + case BUY -> tradeBuy(); + case SELL -> tradeSell(); + } + panel.keyH.spacePressed = false; + } + + // TRADING + private void tradeSelect() { + drawDialogueScreen(); + + int x = panel.tileSize*15; + int y = panel.tileSize*4; + int width = panel.tileSize*3; + int height = (int)(panel.tileSize*3.5); + drawSubWindow(x, y, width, height); + + // DRAW TEXTS + x += panel.tileSize; + y += panel.tileSize; + graphics2d.drawString("Buy",x , y); + if(commandNum == 0) { + graphics2d.drawString(">", x-panel.tileSize/2, y); + if(panel.keyH.spacePressed) tradeState = TradeState.BUY; + } + y += panel.tileSize; + + graphics2d.drawString("Sell",x , y); + if(commandNum == 1) { + graphics2d.drawString(">", x-panel.tileSize/2, y); + if(panel.keyH.spacePressed) tradeState = TradeState.SELL; + } + y += panel.tileSize; + + graphics2d.drawString("Leave",x , y); + if(commandNum == 2) { + graphics2d.drawString(">", x-panel.tileSize/2, y); + if(panel.keyH.spacePressed) { + commandNum = 0; + tradeState = TradeState.SELECT; + panel.gameState = GameState.DIALOGUE; + currentDialogue = "Come again, hehe!"; + } + } + } + private void tradeBuy() { + drawInventory(panel.player, false); + drawInventory(tradingNPC, true); + + // HINT WINDOW + int x = panel.tileSize*2; + int y = panel.tileSize*9; + int width = panel.tileSize*6; + int height = panel.tileSize*2; + drawSubWindow(x, y, width, height); + graphics2d.drawString("[ESC] Back", x+panel.tileSize, y+60); + + // PLAYER COINS + x = panel.tileSize*12; + drawSubWindow(x, y, width, height); + graphics2d.drawString("Your Coins: " + panel.player.coins, x+panel.tileSize, y+60); + + // PRICE WINDOW + int itemIndex = getItemIndex(npcSlotCol, npcSlotRow); + if(itemIndex < tradingNPC.inventory.size()) { + x = (int)(panel.tileSize*5.5); + y = (int)(panel.tileSize*5.5); + width = (int)(panel.tileSize*2.5); + height = panel.tileSize; + drawSubWindow(x, y, width, height); + graphics2d.drawImage(coin, x+10, y+8, 32, 32, null); + String price = String.valueOf(tradingNPC.inventory.get(itemIndex).price); + graphics2d.drawString(price, getAlignedToRightX(price, panel.tileSize*8-20), y+34); + + // BUY + if(!panel.keyH.spacePressed) return; + if(tradingNPC.inventory.get(itemIndex).price > panel.player.coins) { + tradeState = TradeState.SELECT; + panel.gameState = GameState.DIALOGUE; + currentDialogue = "You need more coins to buy that!"; + drawDialogueScreen(); + return; + } + if(panel.player.inventory.size() == panel.player.maxInvSize) { + tradeState = TradeState.SELECT; + panel.gameState = GameState.DIALOGUE; + currentDialogue = "Your inventory is full!"; + drawDialogueScreen(); + return; + } + panel.player.coins -= tradingNPC.inventory.get(itemIndex).price; + panel.player.inventory.add(tradingNPC.inventory.get(itemIndex)); + } + } + private void tradeSell() { + + } // UTILITY private void drawSubWindow(int x, int y, int width, int height) { @@ -357,8 +479,8 @@ public class UI { private int getAlignedToRightX(String text, int tailX) { return tailX - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth(); } - public int getItemIndex() { - return slotCol + slotRow*5; + public int getItemIndex(int slotCol, int slotRow) { + return slotCol + slotRow *5; } public void addMessage(String text) { messages.add(text); @@ -541,5 +663,9 @@ public class UI { CONTROLS, QUITNF; } - + public enum TradeState { + SELECT, + BUY, + SELL; + } } diff --git a/src/de/miaurizius/jgame2d/core/enums/GameState.java b/src/de/miaurizius/jgame2d/core/enums/GameState.java index bc10d60..4303973 100644 --- a/src/de/miaurizius/jgame2d/core/enums/GameState.java +++ b/src/de/miaurizius/jgame2d/core/enums/GameState.java @@ -2,12 +2,16 @@ package de.miaurizius.jgame2d.core.enums; public enum GameState { + // SCENES PLAY, PAUSE, - DIALOGUE, TITLE, - CHARACTER, + + // IN-GAME + CHARACTER, //inventory + DIALOGUE, GAMEOVER, TRANSITION, + TRADE, } diff --git a/src/de/miaurizius/jgame2d/core/handlers/AssetSetter.java b/src/de/miaurizius/jgame2d/core/handlers/AssetSetter.java index a3cc9d2..86eb7c3 100644 --- a/src/de/miaurizius/jgame2d/core/handlers/AssetSetter.java +++ b/src/de/miaurizius/jgame2d/core/handlers/AssetSetter.java @@ -3,6 +3,7 @@ package de.miaurizius.jgame2d.core.handlers; import de.miaurizius.jgame2d.core.GamePanel; import de.miaurizius.jgame2d.core.enums.Map; import de.miaurizius.jgame2d.entity.item.*; +import de.miaurizius.jgame2d.entity.npc.MerchantNPC; import de.miaurizius.jgame2d.entity.npc.OldManNPC; import de.miaurizius.jgame2d.entity.monster.GreenSlimeMON; import de.miaurizius.jgame2d.tile.interactive.DryTreeTI; @@ -48,7 +49,7 @@ public class AssetSetter { panel.npc[Map.OVERWORLD.getIndex()][0].worldX = panel.tileSize*21; panel.npc[Map.OVERWORLD.getIndex()][0].worldY = panel.tileSize*21; - panel.npc[Map.HUT.getIndex()][0] = new OldManNPC(panel); + panel.npc[Map.HUT.getIndex()][0] = new MerchantNPC(panel); panel.npc[Map.HUT.getIndex()][0].worldX = panel.tileSize*12; panel.npc[Map.HUT.getIndex()][0].worldY = panel.tileSize*7; } diff --git a/src/de/miaurizius/jgame2d/core/handlers/EventHandler.java b/src/de/miaurizius/jgame2d/core/handlers/EventHandler.java index c95dd9b..381b2e2 100644 --- a/src/de/miaurizius/jgame2d/core/handlers/EventHandler.java +++ b/src/de/miaurizius/jgame2d/core/handlers/EventHandler.java @@ -4,6 +4,7 @@ import de.miaurizius.jgame2d.core.GamePanel; import de.miaurizius.jgame2d.core.enums.Direction; import de.miaurizius.jgame2d.core.enums.GameState; import de.miaurizius.jgame2d.core.enums.Map; +import de.miaurizius.jgame2d.entity.Entity; import java.awt.*; @@ -53,18 +54,22 @@ public class EventHandler { if(distance > panel.tileSize) canTouchEvent = true; if(!canTouchEvent) return; - if(hit(Map.OVERWORLD, 27,16, Direction.RIGHT)) damagePit(GameState.DIALOGUE); - else if(hit(Map.OVERWORLD, 23,12, null)) healingPool(GameState.DIALOGUE); + // PIT/POOL TESTS + if(hit(Map.OVERWORLD, 27,16, Direction.RIGHT)) damagePit(); + else if(hit(Map.OVERWORLD, 23,12, null)) healingPool(); // HUT else if(hit(Map.OVERWORLD, 10, 39, null)) changeMap(Map.HUT, 12, 13); else if(hit(Map.HUT, 12, 13, null)) changeMap(Map.OVERWORLD, 10, 39); + + // ADVANCED SPEAKING + else if(hit(Map.HUT, 12, 9, Direction.UP)) speak(panel.npc[Map.HUT.getIndex()][0]); } /** * @param reqDirection Set to null if no direction is required */ - public boolean hit(Map map, int eventCol, int eventRow, Direction reqDirection) { + private boolean hit(Map map, int eventCol, int eventRow, Direction reqDirection) { boolean hit = false; panel.player.solidArea.x = panel.player.worldX + panel.player.solidArea.x; panel.player.solidArea.y = panel.player.worldY + panel.player.solidArea.y; @@ -86,16 +91,16 @@ public class EventHandler { return hit; } - public void damagePit(GameState gameState) { - panel.gameState = gameState; + private void damagePit() { + panel.gameState = GameState.DIALOGUE; panel.playSE(6); panel.ui.currentDialogue = "You have fallen into a pit!"; panel.player.life -= 1; canTouchEvent = false; } - public void healingPool(GameState gameState) { + private void healingPool() { if(!panel.keyH.spacePressed) return; - panel.gameState = gameState; + panel.gameState = GameState.DIALOGUE; panel.player.attackCancel = true; panel.playSE(2); panel.ui.currentDialogue = "You drank the holy water.\nYour life has been recovered!\nBut all monsters respawned... \nGood luck!"; @@ -103,7 +108,7 @@ public class EventHandler { canTouchEvent = false; panel.assetSetter.setMonster(); } - public void changeMap(Map map, int col, int row) { + private void changeMap(Map map, int col, int row) { panel.gameState = GameState.TRANSITION; tempMap = map; tempCol = col; @@ -111,6 +116,12 @@ public class EventHandler { canTouchEvent = false; panel.playSE(13); } + private void speak(Entity entity) { + if(!panel.keyH.spacePressed) return; + panel.gameState = GameState.DIALOGUE; + panel.player.attackCancel = true; + entity.speak(); + } static private class EventRect extends Rectangle { int eventRectDefaultX, eventRectDefaultY; diff --git a/src/de/miaurizius/jgame2d/core/handlers/KeyHandler.java b/src/de/miaurizius/jgame2d/core/handlers/KeyHandler.java index 0e28aeb..f15d7cc 100644 --- a/src/de/miaurizius/jgame2d/core/handlers/KeyHandler.java +++ b/src/de/miaurizius/jgame2d/core/handlers/KeyHandler.java @@ -124,38 +124,11 @@ public class KeyHandler implements KeyListener { } private void handleCharacter(int code) { switch (code) { - case KeyEvent.VK_UP: - if(panel.ui.slotRow == 0) break; - if(panel.sfx.clips[9].isRunning()) break; - panel.ui.slotRow--; - panel.playSE(9); - break; - case KeyEvent.VK_DOWN: - if(panel.ui.slotRow == 3) break; - if(panel.sfx.clips[9].isRunning()) break; - panel.ui.slotRow++; - panel.playSE(9); - break; - case KeyEvent.VK_LEFT: - if(panel.ui.slotCol == 0) break; - if(panel.sfx.clips[9].isRunning()) break; - panel.ui.slotCol--; - panel.playSE(9); - break; - case KeyEvent.VK_RIGHT: - if(panel.ui.slotCol == 4) break; - if(panel.sfx.clips[9].isRunning()) break; - panel.ui.slotCol++; - panel.playSE(9); - break; + case KeyEvent.VK_UP, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT -> playerInventory(code); + case KeyEvent.VK_SPACE -> panel.player.selectItem(); - case KeyEvent.VK_SPACE: - panel.player.selectItem(); - break; // EXIT STATE - case KeyEvent.VK_C, KeyEvent.VK_ESCAPE: - panel.gameState = GameState.PLAY; - break; + case KeyEvent.VK_C, KeyEvent.VK_ESCAPE -> panel.gameState = GameState.PLAY; } } private void handleGameOver(int code) { @@ -183,6 +156,85 @@ public class KeyHandler implements KeyListener { } } } + private void handleTrade(int code) { + if(code == KeyEvent.VK_SPACE) spacePressed = true; + if(panel.ui.tradeState == UI.TradeState.SELECT) { + switch (code) { + case KeyEvent.VK_UP: + if (panel.ui.commandNum <= 0) break; + panel.ui.commandNum--; + panel.playSE(9); + break; + case KeyEvent.VK_DOWN: + if (panel.ui.commandNum >= 2) break; + panel.ui.commandNum++; + panel.playSE(9); + break; + } + } + if(panel.ui.tradeState == UI.TradeState.BUY) { + npcInventory(code); + if(code == KeyEvent.VK_ESCAPE) panel.ui.tradeState = UI.TradeState.SELECT; + } + } + + // UTILITY + private void playerInventory(int code) { + switch (code) { + case KeyEvent.VK_UP: + if(panel.ui.playerSlotRow == 0) break; + if(panel.sfx.clips[9].isRunning()) break; + panel.ui.playerSlotRow--; + panel.playSE(9); + break; + case KeyEvent.VK_DOWN: + if(panel.ui.playerSlotRow == 3) break; + if(panel.sfx.clips[9].isRunning()) break; + panel.ui.playerSlotRow++; + panel.playSE(9); + break; + case KeyEvent.VK_LEFT: + if(panel.ui.playerSlotCol == 0) break; + if(panel.sfx.clips[9].isRunning()) break; + panel.ui.playerSlotCol--; + panel.playSE(9); + break; + case KeyEvent.VK_RIGHT: + if(panel.ui.playerSlotCol == 4) break; + if(panel.sfx.clips[9].isRunning()) break; + panel.ui.playerSlotCol++; + panel.playSE(9); + break; + } + } + private void npcInventory(int code) { + switch (code) { + case KeyEvent.VK_UP: + if(panel.ui.npcSlotRow == 0) break; + if(panel.sfx.clips[9].isRunning()) break; + panel.ui.npcSlotRow--; + panel.playSE(9); + break; + case KeyEvent.VK_DOWN: + if(panel.ui.npcSlotRow == 3) break; + if(panel.sfx.clips[9].isRunning()) break; + panel.ui.npcSlotRow++; + panel.playSE(9); + break; + case KeyEvent.VK_LEFT: + if(panel.ui.npcSlotCol == 0) break; + if(panel.sfx.clips[9].isRunning()) break; + panel.ui.npcSlotCol--; + panel.playSE(9); + break; + case KeyEvent.VK_RIGHT: + if(panel.ui.npcSlotCol == 4) break; + if(panel.sfx.clips[9].isRunning()) break; + panel.ui.npcSlotCol++; + panel.playSE(9); + break; + } + } // KEY-LISTENER @Override @@ -197,6 +249,7 @@ public class KeyHandler implements KeyListener { case PAUSE -> handlePause(code); case CHARACTER -> handleCharacter(code); case GAMEOVER -> handleGameOver(code); + case TRADE -> handleTrade(code); } } @Override diff --git a/src/de/miaurizius/jgame2d/entity/Entity.java b/src/de/miaurizius/jgame2d/entity/Entity.java index b06c127..e5eb937 100644 --- a/src/de/miaurizius/jgame2d/entity/Entity.java +++ b/src/de/miaurizius/jgame2d/entity/Entity.java @@ -13,6 +13,7 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.io.FileInputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.logging.Level; public class Entity { @@ -66,6 +67,8 @@ public class Entity { public Entity currentWeapon; public Entity currentShield; public Projectile projectile; + public ArrayList inventory = new ArrayList<>(); + public final int maxInvSize = 20; // ITEM ATTRIBUTES public EntityType.WeaponType weaponType; @@ -74,6 +77,7 @@ public class Entity { public String description; public int useCost; public int value; + public int price; public Entity(GamePanel panel) { this.panel = panel; @@ -102,7 +106,7 @@ public class Entity { } spriteCounter++; - if(spriteCounter > 12) { + if(spriteCounter > 24) { if(spriteNum == 1) spriteNum = 2; else if(spriteNum == 2) spriteNum = 1; else spriteNum = 0; diff --git a/src/de/miaurizius/jgame2d/entity/Player.java b/src/de/miaurizius/jgame2d/entity/Player.java index 7888659..718a4a7 100644 --- a/src/de/miaurizius/jgame2d/entity/Player.java +++ b/src/de/miaurizius/jgame2d/entity/Player.java @@ -4,13 +4,13 @@ import de.miaurizius.jgame2d.core.*; 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.enums.Map; import de.miaurizius.jgame2d.core.handlers.KeyHandler; import de.miaurizius.jgame2d.entity.item.ShieldWoodObj; import de.miaurizius.jgame2d.entity.item.SwordNormalObj; import de.miaurizius.jgame2d.entity.projectile.FireballObj; import java.awt.*; -import java.util.ArrayList; public class Player extends Entity { @@ -20,8 +20,6 @@ public class Player extends Entity { // STATE public boolean attackCancel; - public ArrayList inventory = new ArrayList<>(); - public final int maxInvSize = 20; public Player(GamePanel panel, KeyHandler keyH) { super(panel); @@ -264,7 +262,7 @@ public class Player extends Entity { panel.ui.currentDialogue = "You are level " + level + " now!\nYou feel stronger!"; } public void selectItem() { - int itemIndex = panel.ui.getItemIndex(); + int itemIndex = panel.ui.getItemIndex(panel.ui.playerSlotCol, panel.ui.playerSlotRow); if(itemIndex >= inventory.size()) return; Entity selectedItem = inventory.get(itemIndex); if(selectedItem.type == EntityType.WEAPON) { @@ -295,6 +293,11 @@ public class Player extends Entity { public void setDefaultValues() { worldX = panel.tileSize * 23; worldY = panel.tileSize * 21; + + worldX = panel.tileSize * 12; + worldY = panel.tileSize * 12; + panel.currentMap = Map.HUT; + speed = 4; direction = Direction.DOWN; @@ -306,7 +309,7 @@ public class Player extends Entity { dexterity = 1; exp = 0; nextLevelExp = 5; - coins = 0; + coins = 500; currentWeapon = new SwordNormalObj(panel); currentShield = new ShieldWoodObj(panel); projectile = new FireballObj(panel); diff --git a/src/de/miaurizius/jgame2d/entity/item/AxeObj.java b/src/de/miaurizius/jgame2d/entity/item/AxeObj.java index bbe75b1..aabf210 100644 --- a/src/de/miaurizius/jgame2d/entity/item/AxeObj.java +++ b/src/de/miaurizius/jgame2d/entity/item/AxeObj.java @@ -13,6 +13,7 @@ public class AxeObj extends Entity { type = EntityType.WEAPON; weaponType = EntityType.WeaponType.AXE; down1 = initEntitySprites("/objects/axe"); + price = 50; attackValue = 2; attackArea.width = 30; diff --git a/src/de/miaurizius/jgame2d/entity/item/IronShieldObj.java b/src/de/miaurizius/jgame2d/entity/item/IronShieldObj.java index aa90de5..b11ad1f 100644 --- a/src/de/miaurizius/jgame2d/entity/item/IronShieldObj.java +++ b/src/de/miaurizius/jgame2d/entity/item/IronShieldObj.java @@ -14,6 +14,8 @@ public class IronShieldObj extends Entity { type = EntityType.SHIELD; down1 = initEntitySprites("objects/shield_blue"); defenseValue = 2; + + price = 50; } } diff --git a/src/de/miaurizius/jgame2d/entity/item/KeyObj.java b/src/de/miaurizius/jgame2d/entity/item/KeyObj.java index 20f63f5..a691067 100644 --- a/src/de/miaurizius/jgame2d/entity/item/KeyObj.java +++ b/src/de/miaurizius/jgame2d/entity/item/KeyObj.java @@ -12,6 +12,8 @@ public class KeyObj extends Entity { description = "[" + name + "]\nIt opens a door."; type = EntityType.ITEM; down1 = initEntitySprites("objects/key"); + + price = 50; } } diff --git a/src/de/miaurizius/jgame2d/entity/item/PotionObj.java b/src/de/miaurizius/jgame2d/entity/item/PotionObj.java index a54b337..4cdc579 100644 --- a/src/de/miaurizius/jgame2d/entity/item/PotionObj.java +++ b/src/de/miaurizius/jgame2d/entity/item/PotionObj.java @@ -19,6 +19,8 @@ public class PotionObj extends Entity { name = "Red Potion"; down1 = initEntitySprites("objects/potion_red"); description = "[" + name + "]\nHeals your life by " + value + "."; + + price = 50; } public void use(Entity entity) { diff --git a/src/de/miaurizius/jgame2d/entity/item/ShieldWoodObj.java b/src/de/miaurizius/jgame2d/entity/item/ShieldWoodObj.java index 6bc9aa8..7646aa4 100644 --- a/src/de/miaurizius/jgame2d/entity/item/ShieldWoodObj.java +++ b/src/de/miaurizius/jgame2d/entity/item/ShieldWoodObj.java @@ -13,6 +13,8 @@ public class ShieldWoodObj extends Entity { type = EntityType.SHIELD; down1 = initEntitySprites("objects/shield_wood"); defenseValue = 1; + + price = 50; } } diff --git a/src/de/miaurizius/jgame2d/entity/item/SwordNormalObj.java b/src/de/miaurizius/jgame2d/entity/item/SwordNormalObj.java index 8b5ca0b..10b4c08 100644 --- a/src/de/miaurizius/jgame2d/entity/item/SwordNormalObj.java +++ b/src/de/miaurizius/jgame2d/entity/item/SwordNormalObj.java @@ -14,6 +14,7 @@ public class SwordNormalObj extends Entity { type = EntityType.WEAPON; weaponType = EntityType.WeaponType.SWORD; down1 = initEntitySprites("objects/sword_normal"); + price = 50; attackValue = 1; attackArea.width = 36; diff --git a/src/de/miaurizius/jgame2d/entity/npc/MerchantNPC.java b/src/de/miaurizius/jgame2d/entity/npc/MerchantNPC.java new file mode 100644 index 0000000..3319310 --- /dev/null +++ b/src/de/miaurizius/jgame2d/entity/npc/MerchantNPC.java @@ -0,0 +1,54 @@ +package de.miaurizius.jgame2d.entity.npc; + +import de.miaurizius.jgame2d.core.GamePanel; +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.entity.Entity; +import de.miaurizius.jgame2d.entity.item.*; + +public class MerchantNPC extends Entity { + + public MerchantNPC(GamePanel panel) { + super(panel); + type = EntityType.NPC; + name = "merchant-npc"; + + direction = Direction.DOWN; + speed = 0; + getImage(); + setDialogue(); + setItems(); + } + + @Override + public void speak() { + super.speak(); + panel.gameState = GameState.TRADE; + panel.ui.tradingNPC = this; + } + + // SETTING THINGS UP + private void getImage() { + up1 = initEntitySprites("npc/merchant_down_1"); + up2 = initEntitySprites("npc/merchant_down_2"); + down1 = initEntitySprites("npc/merchant_down_1"); + down2 = initEntitySprites("npc/merchant_down_2"); + left1 = initEntitySprites("npc/merchant_down_1"); + left2 = initEntitySprites("npc/merchant_down_2"); + right1 = initEntitySprites("npc/merchant_down_1"); + right2 = initEntitySprites("npc/merchant_down_2"); + } + private void setDialogue() { + dialogue[0] = "He he, so you found me. \nI have some good stuff. \nDo you want to trade?"; + } + private void setItems() { + inventory.add(new PotionObj(panel)); + inventory.add(new KeyObj(panel)); + inventory.add(new SwordNormalObj(panel)); + inventory.add(new AxeObj(panel)); + inventory.add(new ShieldWoodObj(panel)); + inventory.add(new IronShieldObj(panel)); + } + +} diff --git a/src/de/miaurizius/jgame2d/entity/npc/OldManNPC.java b/src/de/miaurizius/jgame2d/entity/npc/OldManNPC.java index 7bee942..0d24b06 100644 --- a/src/de/miaurizius/jgame2d/entity/npc/OldManNPC.java +++ b/src/de/miaurizius/jgame2d/entity/npc/OldManNPC.java @@ -20,25 +20,6 @@ public class OldManNPC extends Entity { setDialogue(); } - public void getImage() { - up1 = initEntitySprites("npc/oldman_up_1"); - up2 = initEntitySprites("npc/oldman_up_2"); - down1 = initEntitySprites("npc/oldman_down_1"); - down2 = initEntitySprites("npc/oldman_down_2"); - left1 = initEntitySprites("npc/oldman_left_1"); - left2 = initEntitySprites("npc/oldman_left_2"); - right1 = initEntitySprites("npc/oldman_right_1"); - right2 = initEntitySprites("npc/oldman_right_2"); - } - - public void setDialogue() { - dialogue[0] = "Hello, lad."; - dialogue[1] = "So you've come to this island to \nfind the treasure?"; - dialogue[2] = "I used to be a great wizard but now... \nI'm a bit too old for taking an \nadventure."; - dialogue[3] = "Well, good luck on you."; - dialogue[4] = "I heard drinking the water of the \nholy lake makes you feel fine again..."; - } - public void setAction() { actionLock++; if(actionLock != 120) return; //lock action for x frames @@ -50,4 +31,23 @@ public class OldManNPC extends Entity { if(i > 75) direction = Direction.RIGHT; actionLock = 0; } + + // SETTING THINGS UP + private void getImage() { + up1 = initEntitySprites("npc/oldman_up_1"); + up2 = initEntitySprites("npc/oldman_up_2"); + down1 = initEntitySprites("npc/oldman_down_1"); + down2 = initEntitySprites("npc/oldman_down_2"); + left1 = initEntitySprites("npc/oldman_left_1"); + left2 = initEntitySprites("npc/oldman_left_2"); + right1 = initEntitySprites("npc/oldman_right_1"); + right2 = initEntitySprites("npc/oldman_right_2"); + } + private void setDialogue() { + dialogue[0] = "Hello, lad."; + dialogue[1] = "So you've come to this island to \nfind the treasure?"; + dialogue[2] = "I used to be a great wizard but now... \nI'm a bit too old for taking an \nadventure."; + dialogue[3] = "Well, good luck on you."; + dialogue[4] = "I heard drinking the water of the \nholy lake makes you feel fine again..."; + } }