player can now choose between different shields and weapons. added consumable items (healing potion)
This commit is contained in:
@@ -5,6 +5,7 @@ import de.miaurizius.jgame2d.core.enums.Direction;
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.Utility;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
@@ -36,6 +37,7 @@ public class Entity {
|
||||
public boolean alive = true;
|
||||
public boolean dying;
|
||||
public boolean hpBarOn;
|
||||
public boolean consumable;
|
||||
|
||||
// COUNTER
|
||||
public int spriteCounter;
|
||||
@@ -62,6 +64,7 @@ public class Entity {
|
||||
public Entity currentShield;
|
||||
|
||||
// ITEM ATTRIBUTES
|
||||
public EntityType.WeaponType weaponType;
|
||||
public int attackValue;
|
||||
public int defenseValue;
|
||||
public String description;
|
||||
@@ -189,6 +192,8 @@ public class Entity {
|
||||
alive = false;
|
||||
}
|
||||
}
|
||||
public void use(Entity entity) {
|
||||
} //If entity is consumable
|
||||
|
||||
// SETTING THINGS UP
|
||||
BufferedImage parseSprite() {
|
||||
|
||||
@@ -41,9 +41,6 @@ public class Player extends Entity {
|
||||
solidArea.width = 24;
|
||||
solidArea.height = 24;
|
||||
|
||||
attackArea.width = 36;
|
||||
attackArea.height = 36;
|
||||
|
||||
setDefaultValues();
|
||||
getPlayerImage();
|
||||
getPlayerAttackImage();
|
||||
@@ -128,7 +125,7 @@ public class Player extends Entity {
|
||||
}
|
||||
inventory.add(panel.obj[index]);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -229,6 +226,24 @@ public class Player extends Entity {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
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
|
||||
public void setDefaultValues() {
|
||||
@@ -256,6 +271,7 @@ public class Player extends Entity {
|
||||
inventory.add(currentShield);
|
||||
}
|
||||
public int getAttack() {
|
||||
attackArea = currentWeapon.attackArea;
|
||||
return attack = strength * currentWeapon.attackValue;
|
||||
}
|
||||
public int getDefense() {
|
||||
@@ -272,14 +288,28 @@ public class Player extends Entity {
|
||||
right2 = initEntitySprites("player/boy_right_2");
|
||||
}
|
||||
public void getPlayerAttackImage() {
|
||||
attackUp1 = initEntitySprites("player/attack/boy_attack_up_1", panel.tileSize, panel.tileSize*2);
|
||||
attackUp2 = initEntitySprites("player/attack/boy_attack_up_2", panel.tileSize, panel.tileSize*2);
|
||||
attackDown1 = initEntitySprites("player/attack/boy_attack_down_1", panel.tileSize, panel.tileSize*2);
|
||||
attackDown2 = initEntitySprites("player/attack/boy_attack_down_2", panel.tileSize, panel.tileSize*2);
|
||||
attackLeft1 = initEntitySprites("player/attack/boy_attack_left_1", 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);
|
||||
switch(currentWeapon.weaponType) {
|
||||
case SWORD:
|
||||
attackUp1 = initEntitySprites("player/attack/boy_attack_up_1", panel.tileSize, panel.tileSize * 2);
|
||||
attackUp2 = initEntitySprites("player/attack/boy_attack_up_2", panel.tileSize, panel.tileSize * 2);
|
||||
attackDown1 = initEntitySprites("player/attack/boy_attack_down_1", panel.tileSize, panel.tileSize * 2);
|
||||
attackDown2 = initEntitySprites("player/attack/boy_attack_down_2", panel.tileSize, panel.tileSize * 2);
|
||||
attackLeft1 = initEntitySprites("player/attack/boy_attack_left_1", 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) {
|
||||
super(panel);
|
||||
name = "boots";
|
||||
name = "Boots";
|
||||
type = EntityType.ITEM;
|
||||
down1 = initEntitySprites("objects/boots.png");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public class HeartObj extends Entity {
|
||||
|
||||
public HeartObj(GamePanel panel) {
|
||||
super(panel);
|
||||
name = "heart";
|
||||
name = "Heart Container";
|
||||
type = EntityType.ITEM;
|
||||
image = initEntitySprites("objects/heart_full");
|
||||
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);
|
||||
name = "Wooden Shield";
|
||||
description = "[" + name + "]\nAn old shield. It's not\nthat strong but its okay.";
|
||||
type = EntityType.ITEM;
|
||||
type = EntityType.SHIELD;
|
||||
down1 = initEntitySprites("objects/shield_wood");
|
||||
defenseValue = 1;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,13 @@ public class SwordNormalObj extends Entity {
|
||||
|
||||
name = "Normal Sword";
|
||||
description = "[" + name + "]\nAn old sword.";
|
||||
type = EntityType.ITEM;
|
||||
type = EntityType.WEAPON;
|
||||
weaponType = EntityType.WeaponType.SWORD;
|
||||
down1 = initEntitySprites("objects/sword_normal");
|
||||
|
||||
attackValue = 1;
|
||||
attackArea.width = 36;
|
||||
attackArea.height = 36;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user