player can now choose between different shields and weapons. added consumable items (healing potion)
This commit is contained in:
@@ -175,6 +175,12 @@ public class UI {
|
|||||||
|
|
||||||
// DRAW PLAYER ITEMS
|
// DRAW PLAYER ITEMS
|
||||||
for(int i = 0; i < panel.player.inventory.size(); i++) {
|
for(int i = 0; i < panel.player.inventory.size(); i++) {
|
||||||
|
|
||||||
|
// EQUIP CURSOR
|
||||||
|
if(panel.player.inventory.get(i) == panel.player.currentWeapon || panel.player.inventory.get(i) == panel.player.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(panel.player.inventory.get(i).down1, slotX, slotY, null);
|
||||||
slotX += slotSize;
|
slotX += slotSize;
|
||||||
if (i == 4 || i == 9 || i == 14) {
|
if (i == 4 || i == 9 || i == 14) {
|
||||||
@@ -230,7 +236,7 @@ public class UI {
|
|||||||
int height = panel.tileSize*4;
|
int height = panel.tileSize*4;
|
||||||
drawSubWindow(x, y, width, height);
|
drawSubWindow(x, y, width, height);
|
||||||
|
|
||||||
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.PLAIN, 28F));
|
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.PLAIN, 30F));
|
||||||
x += panel.tileSize;
|
x += panel.tileSize;
|
||||||
y += panel.tileSize;
|
y += panel.tileSize;
|
||||||
|
|
||||||
@@ -300,12 +306,12 @@ public class UI {
|
|||||||
public int getAlignedToRightX(String text, int tailX) {
|
public int getAlignedToRightX(String text, int tailX) {
|
||||||
return tailX - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth();
|
return tailX - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth();
|
||||||
}
|
}
|
||||||
|
public int getItemIndex() {
|
||||||
|
return slotCol + slotRow*5;
|
||||||
|
}
|
||||||
public void addMessage(String text) {
|
public void addMessage(String text) {
|
||||||
messages.add(text);
|
messages.add(text);
|
||||||
messageCounter.add(0);
|
messageCounter.add(0);
|
||||||
}
|
}
|
||||||
public int getItemIndex() {
|
|
||||||
return slotCol + slotRow*5;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,13 @@ public enum EntityType {
|
|||||||
NPC,
|
NPC,
|
||||||
MONSTER,
|
MONSTER,
|
||||||
ITEM,
|
ITEM,
|
||||||
WORLD
|
WORLD,
|
||||||
|
WEAPON,
|
||||||
|
SHIELD;
|
||||||
|
|
||||||
|
public enum WeaponType {
|
||||||
|
SWORD,
|
||||||
|
AXE
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package de.miaurizius.jgame2d.core.handlers;
|
package de.miaurizius.jgame2d.core.handlers;
|
||||||
|
|
||||||
import de.miaurizius.jgame2d.core.GamePanel;
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.entity.item.AxeObj;
|
||||||
|
import de.miaurizius.jgame2d.entity.item.IronShieldObj;
|
||||||
import de.miaurizius.jgame2d.entity.item.KeyObj;
|
import de.miaurizius.jgame2d.entity.item.KeyObj;
|
||||||
|
import de.miaurizius.jgame2d.entity.item.PotionObj;
|
||||||
import de.miaurizius.jgame2d.entity.npc.OldManNPC;
|
import de.miaurizius.jgame2d.entity.npc.OldManNPC;
|
||||||
import de.miaurizius.jgame2d.entity.monster.GreenSlimeMON;
|
import de.miaurizius.jgame2d.entity.monster.GreenSlimeMON;
|
||||||
|
|
||||||
@@ -25,10 +28,20 @@ public class AssetSetter {
|
|||||||
panel.obj[i].worldY = panel.tileSize*19;
|
panel.obj[i].worldY = panel.tileSize*19;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
panel.obj[i] = new KeyObj(panel);
|
panel.obj[i] = new AxeObj(panel);
|
||||||
panel.obj[i].worldX = panel.tileSize*26;
|
panel.obj[i].worldX = panel.tileSize*33;
|
||||||
panel.obj[i].worldY = panel.tileSize*21;
|
panel.obj[i].worldY = panel.tileSize*21;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
panel.obj[i] = new IronShieldObj(panel);
|
||||||
|
panel.obj[i].worldX = panel.tileSize*35;
|
||||||
|
panel.obj[i].worldY = panel.tileSize*21;
|
||||||
|
i++;
|
||||||
|
|
||||||
|
panel.obj[i] = new PotionObj(panel);
|
||||||
|
panel.obj[i].worldX = panel.tileSize*22;
|
||||||
|
panel.obj[i].worldY = panel.tileSize*27;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNPC() {
|
public void setNPC() {
|
||||||
|
|||||||
@@ -95,8 +95,12 @@ public class KeyHandler implements KeyListener {
|
|||||||
panel.ui.slotCol++;
|
panel.ui.slotCol++;
|
||||||
panel.playSE(9);
|
panel.playSE(9);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case KeyEvent.VK_SPACE:
|
||||||
|
panel.player.selectItem();
|
||||||
|
break;
|
||||||
// EXIT STATE
|
// EXIT STATE
|
||||||
case KeyEvent.VK_C:
|
case KeyEvent.VK_C, KeyEvent.VK_ESCAPE:
|
||||||
panel.gameState = GameState.PLAY;
|
panel.gameState = GameState.PLAY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import de.miaurizius.jgame2d.core.enums.Direction;
|
|||||||
import de.miaurizius.jgame2d.core.GamePanel;
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
import de.miaurizius.jgame2d.core.Utility;
|
import de.miaurizius.jgame2d.core.Utility;
|
||||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -36,6 +37,7 @@ public class Entity {
|
|||||||
public boolean alive = true;
|
public boolean alive = true;
|
||||||
public boolean dying;
|
public boolean dying;
|
||||||
public boolean hpBarOn;
|
public boolean hpBarOn;
|
||||||
|
public boolean consumable;
|
||||||
|
|
||||||
// COUNTER
|
// COUNTER
|
||||||
public int spriteCounter;
|
public int spriteCounter;
|
||||||
@@ -62,6 +64,7 @@ public class Entity {
|
|||||||
public Entity currentShield;
|
public Entity currentShield;
|
||||||
|
|
||||||
// ITEM ATTRIBUTES
|
// ITEM ATTRIBUTES
|
||||||
|
public EntityType.WeaponType weaponType;
|
||||||
public int attackValue;
|
public int attackValue;
|
||||||
public int defenseValue;
|
public int defenseValue;
|
||||||
public String description;
|
public String description;
|
||||||
@@ -189,6 +192,8 @@ public class Entity {
|
|||||||
alive = false;
|
alive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void use(Entity entity) {
|
||||||
|
} //If entity is consumable
|
||||||
|
|
||||||
// SETTING THINGS UP
|
// SETTING THINGS UP
|
||||||
BufferedImage parseSprite() {
|
BufferedImage parseSprite() {
|
||||||
|
|||||||
@@ -41,9 +41,6 @@ public class Player extends Entity {
|
|||||||
solidArea.width = 24;
|
solidArea.width = 24;
|
||||||
solidArea.height = 24;
|
solidArea.height = 24;
|
||||||
|
|
||||||
attackArea.width = 36;
|
|
||||||
attackArea.height = 36;
|
|
||||||
|
|
||||||
setDefaultValues();
|
setDefaultValues();
|
||||||
getPlayerImage();
|
getPlayerImage();
|
||||||
getPlayerAttackImage();
|
getPlayerAttackImage();
|
||||||
@@ -128,7 +125,7 @@ public class Player extends Entity {
|
|||||||
}
|
}
|
||||||
inventory.add(panel.obj[index]);
|
inventory.add(panel.obj[index]);
|
||||||
panel.playSE(1);
|
panel.playSE(1);
|
||||||
panel.ui.addMessage("Picked up " + panel.obj[index].name);
|
panel.ui.addMessage("Picked up " + panel.obj[index].name + "!");
|
||||||
panel.obj[index] = null;
|
panel.obj[index] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,6 +226,24 @@ public class Player extends Entity {
|
|||||||
panel.gameState = GameState.DIALOGUE;
|
panel.gameState = GameState.DIALOGUE;
|
||||||
panel.ui.currentDialogue = "You are level " + level + " now!\nYou feel stronger!";
|
panel.ui.currentDialogue = "You are level " + level + " now!\nYou feel stronger!";
|
||||||
}
|
}
|
||||||
|
public void selectItem() {
|
||||||
|
int itemIndex = panel.ui.getItemIndex();
|
||||||
|
if(itemIndex >= inventory.size()) return;
|
||||||
|
Entity selectedItem = inventory.get(itemIndex);
|
||||||
|
if(selectedItem.type == EntityType.WEAPON) {
|
||||||
|
currentWeapon = selectedItem;
|
||||||
|
getAttack();
|
||||||
|
getPlayerAttackImage();
|
||||||
|
}
|
||||||
|
if(selectedItem.type == EntityType.SHIELD) {
|
||||||
|
currentShield = selectedItem;
|
||||||
|
getDefense();
|
||||||
|
}
|
||||||
|
if(selectedItem.consumable) {
|
||||||
|
selectedItem.use(this);
|
||||||
|
inventory.remove(itemIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SETTING THINGS UP
|
// SETTING THINGS UP
|
||||||
public void setDefaultValues() {
|
public void setDefaultValues() {
|
||||||
@@ -256,6 +271,7 @@ public class Player extends Entity {
|
|||||||
inventory.add(currentShield);
|
inventory.add(currentShield);
|
||||||
}
|
}
|
||||||
public int getAttack() {
|
public int getAttack() {
|
||||||
|
attackArea = currentWeapon.attackArea;
|
||||||
return attack = strength * currentWeapon.attackValue;
|
return attack = strength * currentWeapon.attackValue;
|
||||||
}
|
}
|
||||||
public int getDefense() {
|
public int getDefense() {
|
||||||
@@ -272,14 +288,28 @@ public class Player extends Entity {
|
|||||||
right2 = initEntitySprites("player/boy_right_2");
|
right2 = initEntitySprites("player/boy_right_2");
|
||||||
}
|
}
|
||||||
public void getPlayerAttackImage() {
|
public void getPlayerAttackImage() {
|
||||||
attackUp1 = initEntitySprites("player/attack/boy_attack_up_1", panel.tileSize, panel.tileSize*2);
|
switch(currentWeapon.weaponType) {
|
||||||
attackUp2 = initEntitySprites("player/attack/boy_attack_up_2", panel.tileSize, panel.tileSize*2);
|
case SWORD:
|
||||||
attackDown1 = initEntitySprites("player/attack/boy_attack_down_1", panel.tileSize, panel.tileSize*2);
|
attackUp1 = initEntitySprites("player/attack/boy_attack_up_1", panel.tileSize, panel.tileSize * 2);
|
||||||
attackDown2 = initEntitySprites("player/attack/boy_attack_down_2", panel.tileSize, panel.tileSize*2);
|
attackUp2 = initEntitySprites("player/attack/boy_attack_up_2", panel.tileSize, panel.tileSize * 2);
|
||||||
attackLeft1 = initEntitySprites("player/attack/boy_attack_left_1", panel.tileSize*2, panel.tileSize);
|
attackDown1 = initEntitySprites("player/attack/boy_attack_down_1", panel.tileSize, panel.tileSize * 2);
|
||||||
attackLeft2 = initEntitySprites("player/attack/boy_attack_left_2", panel.tileSize*2, panel.tileSize);
|
attackDown2 = initEntitySprites("player/attack/boy_attack_down_2", panel.tileSize, panel.tileSize * 2);
|
||||||
attackRight1 = initEntitySprites("player/attack/boy_attack_right_1", panel.tileSize*2, panel.tileSize);
|
attackLeft1 = initEntitySprites("player/attack/boy_attack_left_1", panel.tileSize * 2, panel.tileSize);
|
||||||
attackRight2 = initEntitySprites("player/attack/boy_attack_right_2", panel.tileSize*2, panel.tileSize);
|
attackLeft2 = initEntitySprites("player/attack/boy_attack_left_2", panel.tileSize * 2, panel.tileSize);
|
||||||
|
attackRight1 = initEntitySprites("player/attack/boy_attack_right_1", panel.tileSize * 2, panel.tileSize);
|
||||||
|
attackRight2 = initEntitySprites("player/attack/boy_attack_right_2", panel.tileSize * 2, panel.tileSize);
|
||||||
|
break;
|
||||||
|
case AXE:
|
||||||
|
attackUp1 = initEntitySprites("player/attack/boy_axe_up_1", panel.tileSize, panel.tileSize * 2);
|
||||||
|
attackUp2 = initEntitySprites("player/attack/boy_axe_up_2", panel.tileSize, panel.tileSize * 2);
|
||||||
|
attackDown1 = initEntitySprites("player/attack/boy_axe_down_1", panel.tileSize, panel.tileSize * 2);
|
||||||
|
attackDown2 = initEntitySprites("player/attack/boy_axe_down_2", panel.tileSize, panel.tileSize * 2);
|
||||||
|
attackLeft1 = initEntitySprites("player/attack/boy_axe_left_1", panel.tileSize * 2, panel.tileSize);
|
||||||
|
attackLeft2 = initEntitySprites("player/attack/boy_axe_left_2", panel.tileSize * 2, panel.tileSize);
|
||||||
|
attackRight1 = initEntitySprites("player/attack/boy_axe_right_1", panel.tileSize * 2, panel.tileSize);
|
||||||
|
attackRight2 = initEntitySprites("player/attack/boy_axe_right_2", panel.tileSize * 2, panel.tileSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/de/miaurizius/jgame2d/entity/item/AxeObj.java
Normal file
22
src/de/miaurizius/jgame2d/entity/item/AxeObj.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package de.miaurizius.jgame2d.entity.item;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
|
|
||||||
|
public class AxeObj extends Entity {
|
||||||
|
|
||||||
|
public AxeObj(GamePanel panel) {
|
||||||
|
super(panel);
|
||||||
|
name = "Woodcutter's Axe";
|
||||||
|
description = "[" + name + "]\nA bit rusty but still can \ncut some trees.";
|
||||||
|
type = EntityType.WEAPON;
|
||||||
|
weaponType = EntityType.WeaponType.AXE;
|
||||||
|
down1 = initEntitySprites("/objects/axe");
|
||||||
|
|
||||||
|
attackValue = 2;
|
||||||
|
attackArea.width = 30;
|
||||||
|
attackArea.height = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ public class BootsObj extends Entity {
|
|||||||
|
|
||||||
public BootsObj(GamePanel panel) {
|
public BootsObj(GamePanel panel) {
|
||||||
super(panel);
|
super(panel);
|
||||||
name = "boots";
|
name = "Boots";
|
||||||
type = EntityType.ITEM;
|
type = EntityType.ITEM;
|
||||||
down1 = initEntitySprites("objects/boots.png");
|
down1 = initEntitySprites("objects/boots.png");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class HeartObj extends Entity {
|
|||||||
|
|
||||||
public HeartObj(GamePanel panel) {
|
public HeartObj(GamePanel panel) {
|
||||||
super(panel);
|
super(panel);
|
||||||
name = "heart";
|
name = "Heart Container";
|
||||||
type = EntityType.ITEM;
|
type = EntityType.ITEM;
|
||||||
image = initEntitySprites("objects/heart_full");
|
image = initEntitySprites("objects/heart_full");
|
||||||
image2 = initEntitySprites("objects/heart_half");
|
image2 = initEntitySprites("objects/heart_half");
|
||||||
|
|||||||
19
src/de/miaurizius/jgame2d/entity/item/IronShieldObj.java
Normal file
19
src/de/miaurizius/jgame2d/entity/item/IronShieldObj.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package de.miaurizius.jgame2d.entity.item;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
|
|
||||||
|
public class IronShieldObj extends Entity {
|
||||||
|
|
||||||
|
public IronShieldObj(GamePanel panel) {
|
||||||
|
super(panel);
|
||||||
|
|
||||||
|
name = "Iron Shield";
|
||||||
|
description = "[" + name + "]\nAn iron shield. It's very\nheavy.";
|
||||||
|
type = EntityType.SHIELD;
|
||||||
|
down1 = initEntitySprites("objects/shield_blue");
|
||||||
|
defenseValue = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
33
src/de/miaurizius/jgame2d/entity/item/PotionObj.java
Normal file
33
src/de/miaurizius/jgame2d/entity/item/PotionObj.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package de.miaurizius.jgame2d.entity.item;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||||
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
|
|
||||||
|
public class PotionObj extends Entity {
|
||||||
|
|
||||||
|
GamePanel panel;
|
||||||
|
int value = 2;
|
||||||
|
|
||||||
|
public PotionObj(GamePanel panel) {
|
||||||
|
super(panel);
|
||||||
|
this.panel = panel;
|
||||||
|
|
||||||
|
type = EntityType.ITEM;
|
||||||
|
consumable = true;
|
||||||
|
name = "Red Potion";
|
||||||
|
down1 = initEntitySprites("objects/potion_red");
|
||||||
|
description = "[" + name + "]\nHeals your life by " + value + ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void use(Entity entity) {
|
||||||
|
panel.gameState = GameState.DIALOGUE;
|
||||||
|
panel.ui.currentDialogue = "You drank a " + name + "!\n" +
|
||||||
|
"Your life has been recovered by " + value + ".";
|
||||||
|
entity.life += value;
|
||||||
|
if(panel.player.life > panel.player.maxLife) panel.player.life = panel.player.maxLife;
|
||||||
|
panel.playSE(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ public class ShieldWoodObj extends Entity {
|
|||||||
super(panel);
|
super(panel);
|
||||||
name = "Wooden Shield";
|
name = "Wooden Shield";
|
||||||
description = "[" + name + "]\nAn old shield. It's not\nthat strong but its okay.";
|
description = "[" + name + "]\nAn old shield. It's not\nthat strong but its okay.";
|
||||||
type = EntityType.ITEM;
|
type = EntityType.SHIELD;
|
||||||
down1 = initEntitySprites("objects/shield_wood");
|
down1 = initEntitySprites("objects/shield_wood");
|
||||||
defenseValue = 1;
|
defenseValue = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,13 @@ public class SwordNormalObj extends Entity {
|
|||||||
|
|
||||||
name = "Normal Sword";
|
name = "Normal Sword";
|
||||||
description = "[" + name + "]\nAn old sword.";
|
description = "[" + name + "]\nAn old sword.";
|
||||||
type = EntityType.ITEM;
|
type = EntityType.WEAPON;
|
||||||
|
weaponType = EntityType.WeaponType.SWORD;
|
||||||
down1 = initEntitySprites("objects/sword_normal");
|
down1 = initEntitySprites("objects/sword_normal");
|
||||||
|
|
||||||
attackValue = 1;
|
attackValue = 1;
|
||||||
|
attackArea.width = 36;
|
||||||
|
attackArea.height = 36;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user