obstacles and chest loot
This commit is contained in:
@@ -25,9 +25,9 @@
|
||||
12 12 12 12 12 12 12 12 18 41 10 41 41 10 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 31 26 30 11 17 12 12 12 12 12 12 12 12 12 12
|
||||
12 12 12 12 12 13 12 22 21 41 10 41 41 10 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 31 26 30 10 17 12 12 12 13 12 12 12 12 12 12
|
||||
12 12 12 12 12 12 12 18 41 41 10 41 41 41 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 31 26 30 10 17 12 12 12 12 12 12 12 12 12 12
|
||||
12 12 12 13 12 12 12 18 41 41 10 41 41 41 10 41 41 41 41 41 41 41 31 26 30 41 41 10 41 41 41 41 41 41 41 31 26 30 10 17 12 13 12 12 12 12 12 12 12 12
|
||||
12 12 12 12 12 12 12 18 41 41 10 41 41 41 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 10 41 41 41 41 31 26 30 10 17 12 12 12 12 12 12 12 12 12 12
|
||||
12 12 12 12 12 12 13 18 41 41 10 10 10 10 10 10 41 41 41 41 41 41 31 26 30 41 41 41 41 41 10 41 41 41 41 37 28 38 10 17 12 12 12 12 13 12 12 12 12 12
|
||||
12 12 12 13 12 12 12 18 41 41 10 41 41 41 10 41 41 41 41 41 41 41 31 26 30 10 10 10 41 41 41 41 41 41 41 31 26 30 10 17 12 13 12 12 12 12 12 12 12 12
|
||||
12 12 12 12 12 12 12 18 41 41 10 41 41 41 10 41 41 41 41 41 41 41 31 26 30 41 41 10 41 41 10 41 41 41 41 31 26 30 10 17 12 12 12 12 12 12 12 12 12 12
|
||||
12 12 12 12 12 12 13 18 41 41 10 10 10 10 10 10 41 41 41 41 41 41 31 26 30 41 41 10 10 10 10 41 41 41 41 37 28 38 10 17 12 12 12 12 13 12 12 12 12 12
|
||||
12 12 12 12 12 12 12 18 41 41 11 10 10 10 10 10 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 10 41 14 25 12 12 13 12 12 12 12 12 12 12
|
||||
12 12 12 12 12 12 12 24 16 41 10 10 10 10 10 10 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 10 10 10 17 12 12 12 12 12 12 12 12 12 12 12
|
||||
12 12 12 12 12 13 12 12 18 41 10 10 10 11 10 10 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 10 10 10 17 12 12 12 12 12 12 12 13 12 12 12
|
||||
|
||||
@@ -6,7 +6,7 @@ public enum EntityType {
|
||||
NPC,
|
||||
MONSTER,
|
||||
ITEM,
|
||||
WORLD,
|
||||
OBSTACLE,
|
||||
PICKUP,
|
||||
PROJECTILE,
|
||||
WEAPON,
|
||||
|
||||
@@ -6,6 +6,8 @@ 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.entity.obstacle.ChestObj;
|
||||
import de.miaurizius.jgame2d.entity.obstacle.DoorObj;
|
||||
import de.miaurizius.jgame2d.tile.interactive.DryTreeTI;
|
||||
|
||||
public class AssetSetter {
|
||||
@@ -18,29 +20,24 @@ public class AssetSetter {
|
||||
|
||||
public void setObject() {
|
||||
int i = 0;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new HeartObj(panel);
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*25;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*23;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new CoinObj(panel);
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*21;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*19;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new AxeObj(panel);
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*33;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*21;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new IronShieldObj(panel);
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*35;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*21;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new DoorObj(panel);
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*14;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*28;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new PotionObj(panel);
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*22;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*27;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new DoorObj(panel);
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*12;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*12;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new ChestObj(panel, new KeyObj(panel));
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*30;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*28;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
@@ -230,6 +230,7 @@ public class Entity {
|
||||
}
|
||||
}
|
||||
public void use(Entity entity) {
|
||||
|
||||
} //If entity is consumable
|
||||
public void checkDrop() {
|
||||
|
||||
@@ -255,6 +256,36 @@ public class Entity {
|
||||
}
|
||||
}
|
||||
}
|
||||
public void interact() {
|
||||
|
||||
}
|
||||
public int getDetected(Entity user, Entity[][] target, String targetName) {
|
||||
int index = 999;
|
||||
int nextWorldX = user.getLeftX();
|
||||
int nextWorldY = user.getTopY();
|
||||
|
||||
switch(user.direction) {
|
||||
case UP -> nextWorldY = user.getTopY()-1;
|
||||
case DOWN -> nextWorldY = user.getBottomY()+1;
|
||||
case LEFT -> nextWorldX = user.getLeftX()-1;
|
||||
case RIGHT -> nextWorldX = user.getRightX()+1;
|
||||
}
|
||||
int col = nextWorldX / panel.tileSize;
|
||||
int row = nextWorldY / panel.tileSize;
|
||||
|
||||
for(int i = 0; i < target[panel.currentMap.getIndex()].length; i++) {
|
||||
if(target[panel.currentMap.getIndex()][i] == null) continue;
|
||||
if(
|
||||
target[panel.currentMap.getIndex()][i].getCol() == col &&
|
||||
target[panel.currentMap.getIndex()][i].getRow() == row &&
|
||||
target[panel.currentMap.getIndex()][i].name.equalsIgnoreCase(targetName)
|
||||
) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
// PARTICLE SETUP
|
||||
public Color getParticleColor() {
|
||||
@@ -285,6 +316,26 @@ public class Entity {
|
||||
panel.particleList.add(p4);
|
||||
}
|
||||
|
||||
// GETTERS
|
||||
public int getLeftX() {
|
||||
return worldX + solidArea.x;
|
||||
}
|
||||
public int getRightX() {
|
||||
return worldX + solidArea.x + solidArea.width;
|
||||
}
|
||||
public int getTopY() {
|
||||
return worldY + solidArea.y;
|
||||
}
|
||||
public int getBottomY() {
|
||||
return worldY + solidArea.y + solidArea.height;
|
||||
}
|
||||
public int getCol() {
|
||||
return (worldX + solidArea.x) / panel.tileSize;
|
||||
}
|
||||
public int getRow() {
|
||||
return (worldY + solidArea.y) / panel.tileSize;
|
||||
}
|
||||
|
||||
// SETTING THINGS UP
|
||||
BufferedImage parseSprite() {
|
||||
return switch (direction) {
|
||||
|
||||
@@ -5,6 +5,8 @@ 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.PotionObj;
|
||||
import de.miaurizius.jgame2d.entity.item.ShieldWoodObj;
|
||||
import de.miaurizius.jgame2d.entity.item.SwordNormalObj;
|
||||
import de.miaurizius.jgame2d.entity.projectile.FireballObj;
|
||||
@@ -135,9 +137,18 @@ public class Player extends Entity {
|
||||
public void pickObject(int index) {
|
||||
if(index == 999 || panel.obj[panel.currentMap.getIndex()][index] == null) return;
|
||||
|
||||
// PICKUP ONLY
|
||||
// PICKUP ONLY ITEMS
|
||||
if(panel.obj[panel.currentMap.getIndex()][index].type == EntityType.PICKUP) {
|
||||
panel.obj[panel.currentMap.getIndex()][index].use(this);
|
||||
panel.obj[panel.currentMap.getIndex()][index] = null;
|
||||
return;
|
||||
}
|
||||
// OBSTACLES
|
||||
if(panel.obj[panel.currentMap.getIndex()][index].type == EntityType.OBSTACLE) {
|
||||
if(!keyH.spacePressed) return;
|
||||
attackCancel = true;
|
||||
panel.obj[panel.currentMap.getIndex()][index].interact();
|
||||
return;
|
||||
}
|
||||
// INVENTORY ITEMS
|
||||
else {
|
||||
@@ -229,7 +240,7 @@ public class Player extends Entity {
|
||||
entity.speed += knockbackVal;
|
||||
entity.knockback = true;
|
||||
}
|
||||
|
||||
|
||||
public void interactTile(int index) {
|
||||
if(index == 999 || !panel.iTile[panel.currentMap.getIndex()][index].destructible || panel.iTile[panel.currentMap.getIndex()][index].invincible) return;
|
||||
if(!panel.iTile[panel.currentMap.getIndex()][index].meetItemReq(this)) return;
|
||||
@@ -282,7 +293,6 @@ public class Player extends Entity {
|
||||
}
|
||||
if(selectedItem.consumable) {
|
||||
selectedItem.use(this);
|
||||
inventory.remove(itemIndex);
|
||||
}
|
||||
}
|
||||
public void setDefaultPositions() {
|
||||
|
||||
@@ -22,5 +22,6 @@ public class CoinObj extends Entity {
|
||||
panel.playSE(1);
|
||||
panel.ui.addMessage("Coin +"+value);
|
||||
panel.player.coins += value;
|
||||
panel.player.inventory.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ 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 KeyObj extends Entity {
|
||||
@@ -11,9 +12,24 @@ public class KeyObj extends Entity {
|
||||
name = "Normal Key";
|
||||
description = "[" + name + "]\nIt opens a door.";
|
||||
type = EntityType.ITEM;
|
||||
consumable = true;
|
||||
down1 = initEntitySprites("objects/key");
|
||||
|
||||
price = 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use(Entity entity) {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
int objIndex = getDetected(entity, panel.obj, "door");
|
||||
if(objIndex == 999) {
|
||||
panel.ui.currentDialogue = "What are you doing?\nThere is no door nearby.";
|
||||
return;
|
||||
}
|
||||
panel.ui.currentDialogue = "You used a " + name + "!\nThe door is now open.";
|
||||
panel.playSE(3);
|
||||
panel.obj[panel.currentMap.getIndex()][objIndex] = null;
|
||||
entity.inventory.remove(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class PotionObj extends Entity {
|
||||
entity.life += value;
|
||||
if(panel.player.life > panel.player.maxLife) panel.player.life = panel.player.maxLife;
|
||||
panel.playSE(2);
|
||||
panel.player.inventory.remove(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
57
src/de/miaurizius/jgame2d/entity/obstacle/ChestObj.java
Normal file
57
src/de/miaurizius/jgame2d/entity/obstacle/ChestObj.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package de.miaurizius.jgame2d.entity.obstacle;
|
||||
|
||||
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 ChestObj extends Entity {
|
||||
|
||||
GamePanel panel;
|
||||
Entity loot;
|
||||
boolean opened;
|
||||
|
||||
public ChestObj(GamePanel panel, Entity loot) {
|
||||
super(panel);
|
||||
this.panel = panel;
|
||||
this.loot = loot;
|
||||
type = EntityType.OBSTACLE;
|
||||
name = "chest";
|
||||
|
||||
image = initEntitySprites("objects/chest");
|
||||
image2 = initEntitySprites("objects/chest_opened");
|
||||
down1 = image;
|
||||
collision = true;
|
||||
|
||||
solidArea.x = 4;
|
||||
solidArea.y = 16;
|
||||
solidArea.width = 40;
|
||||
solidArea.height = 32;
|
||||
solidAreaDefaultX = solidArea.x;
|
||||
solidAreaDefaultY = solidArea.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact() {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
|
||||
if(opened) {
|
||||
panel.ui.currentDialogue = "It's already empty...";
|
||||
return;
|
||||
}
|
||||
panel.playSE(3);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("You open the chest and find a ").append(loot.name).append("!");
|
||||
if(panel.player.inventory.size() == panel.player.maxInvSize) {
|
||||
sb.append("\nBut your inventory is full...");
|
||||
panel.ui.currentDialogue = sb.toString();
|
||||
return;
|
||||
}
|
||||
sb.append("\nYou obtain the ").append(loot.name).append("!");
|
||||
panel.player.inventory.add(loot);
|
||||
down1 = image2;
|
||||
opened = true;
|
||||
panel.ui.currentDialogue = sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,19 @@
|
||||
package de.miaurizius.jgame2d.entity.world;
|
||||
package de.miaurizius.jgame2d.entity.obstacle;
|
||||
|
||||
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 DoorObj extends Entity {
|
||||
|
||||
GamePanel panel;
|
||||
|
||||
public DoorObj(GamePanel panel) {
|
||||
super(panel);
|
||||
this.panel = panel;
|
||||
name = "door";
|
||||
type = EntityType.OBSTACLE;
|
||||
down1 = initEntitySprites("objects/door");
|
||||
collision = true;
|
||||
|
||||
@@ -19,4 +25,10 @@ public class DoorObj extends Entity {
|
||||
solidAreaDefaultY = solidArea.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact() {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.ui.currentDialogue = "You need a key to open this.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package de.miaurizius.jgame2d.entity.world;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
|
||||
public class ChestObj extends Entity {
|
||||
|
||||
public ChestObj(GamePanel panel) {
|
||||
super(panel);
|
||||
name = "chest";
|
||||
down1 = initEntitySprites("objects/chest");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user