made item buyable
This commit is contained in:
@@ -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<Entity> 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;
|
||||
|
||||
@@ -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<Entity> 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -14,6 +14,8 @@ public class IronShieldObj extends Entity {
|
||||
type = EntityType.SHIELD;
|
||||
down1 = initEntitySprites("objects/shield_blue");
|
||||
defenseValue = 2;
|
||||
|
||||
price = 50;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ public class KeyObj extends Entity {
|
||||
description = "[" + name + "]\nIt opens a door.";
|
||||
type = EntityType.ITEM;
|
||||
down1 = initEntitySprites("objects/key");
|
||||
|
||||
price = 50;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -13,6 +13,8 @@ public class ShieldWoodObj extends Entity {
|
||||
type = EntityType.SHIELD;
|
||||
down1 = initEntitySprites("objects/shield_wood");
|
||||
defenseValue = 1;
|
||||
|
||||
price = 50;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
54
src/de/miaurizius/jgame2d/entity/npc/MerchantNPC.java
Normal file
54
src/de/miaurizius/jgame2d/entity/npc/MerchantNPC.java
Normal file
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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...";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user