Compare commits

...

2 Commits

11 changed files with 113 additions and 49 deletions

View File

@@ -28,6 +28,8 @@ public class UI {
public int npcSlotCol, npcSlotRow; public int npcSlotCol, npcSlotRow;
private int transCount; private int transCount;
private int sleepCount; private int sleepCount;
private int charIndex;
private String combinedText;
// SUB-STATES // SUB-STATES
public TradeState tradeState = TradeState.SELECT; public TradeState tradeState = TradeState.SELECT;
@@ -294,6 +296,28 @@ public class UI {
x += panel.tileSize; x += panel.tileSize;
y += panel.tileSize; y += panel.tileSize;
if(tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex] != null) {
currentDialogue = tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex];
char[] characters = tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex].toCharArray();
if(charIndex < characters.length) {
String s = String.valueOf(characters[charIndex]);
combinedText = combinedText + s;
currentDialogue = combinedText;
charIndex++;
}
if(panel.keyH.spacePressed) {
charIndex = 0;
combinedText = "";
if(panel.gameState == GameState.DIALOGUE) {
tradingNPC.dialogueIndex++;
panel.keyH.spacePressed = false;
}
}
} else {
tradingNPC.dialogueIndex = 0;
if(panel.gameState == GameState.DIALOGUE) panel.gameState = GameState.PLAY;
}
for(String line : currentDialogue.split("\n")) { for(String line : currentDialogue.split("\n")) {
graphics2d.drawString(line, x, y); graphics2d.drawString(line, x, y);
y += 40; y += 40;
@@ -419,6 +443,7 @@ public class UI {
// TRADING // TRADING
private void tradeSelect() { private void tradeSelect() {
tradingNPC.dialogueSet = 0;
drawDialogueScreen(); drawDialogueScreen();
int x = panel.tileSize*15; int x = panel.tileSize*15;
@@ -449,9 +474,8 @@ public class UI {
graphics2d.drawString(">", x-panel.tileSize/2, y); graphics2d.drawString(">", x-panel.tileSize/2, y);
if(panel.keyH.spacePressed) { if(panel.keyH.spacePressed) {
commandNum = 0; commandNum = 0;
tradingNPC.startDialogue(tradingNPC,1);
tradeState = TradeState.SELECT; tradeState = TradeState.SELECT;
panel.gameState = GameState.DIALOGUE;
currentDialogue = "Come again, hehe!";
} }
} }
} }
@@ -488,9 +512,7 @@ public class UI {
if(!panel.keyH.spacePressed) return; if(!panel.keyH.spacePressed) return;
if(tradingNPC.inventory.get(itemIndex).price > panel.player.coins) { if(tradingNPC.inventory.get(itemIndex).price > panel.player.coins) {
tradeState = TradeState.SELECT; tradeState = TradeState.SELECT;
panel.gameState = GameState.DIALOGUE; tradingNPC.startDialogue(tradingNPC,2);
currentDialogue = "You need more coins to buy that!";
drawDialogueScreen();
return; return;
} }
if(panel.player.canObtainItem(tradingNPC.inventory.get(itemIndex))) { if(panel.player.canObtainItem(tradingNPC.inventory.get(itemIndex))) {
@@ -498,9 +520,7 @@ public class UI {
return; return;
} }
tradeState = TradeState.SELECT; tradeState = TradeState.SELECT;
panel.gameState = GameState.DIALOGUE; tradingNPC.startDialogue(tradingNPC,3);
currentDialogue = "Your inventory is full!";
drawDialogueScreen();
} }
} }
private void tradeSell() { private void tradeSell() {
@@ -537,8 +557,7 @@ public class UI {
if(panel.player.inventory.get(itemIndex) == panel.player.currentWeapon || panel.player.inventory.get(itemIndex) == panel.player.currentShield) { if(panel.player.inventory.get(itemIndex) == panel.player.currentWeapon || panel.player.inventory.get(itemIndex) == panel.player.currentShield) {
commandNum = 0; commandNum = 0;
tradeState = TradeState.SELECT; tradeState = TradeState.SELECT;
panel.gameState = GameState.DIALOGUE; tradingNPC.startDialogue(tradingNPC,4);
currentDialogue = "You cannot sell an equipped item!";
return; return;
} }
if(panel.player.inventory.get(itemIndex).amt <= 1) panel.player.inventory.remove(itemIndex); if(panel.player.inventory.get(itemIndex).amt <= 1) panel.player.inventory.remove(itemIndex);

View File

@@ -14,6 +14,7 @@ public class EventHandler {
GamePanel panel; GamePanel panel;
EventRect[][][] eventRect; EventRect[][][] eventRect;
Entity eventMaster; //Like a "voice of god"
public int prevEventX, prevEventY; public int prevEventX, prevEventY;
boolean canTouchEvent = true; boolean canTouchEvent = true;
@@ -23,6 +24,7 @@ public class EventHandler {
public EventHandler(GamePanel panel) { public EventHandler(GamePanel panel) {
this.panel = panel; this.panel = panel;
eventMaster = new Entity(panel);
eventRect = new EventRect[Map.values().length][panel.maxWorldCol][panel.maxWorldRow]; eventRect = new EventRect[Map.values().length][panel.maxWorldCol][panel.maxWorldRow];
int map = 0; int map = 0;
@@ -46,8 +48,14 @@ public class EventHandler {
} }
} }
} }
setDialogue();
} }
public void setDialogue() {
eventMaster.dialogue[0][0] = "You have fallen into a pit!";
eventMaster.dialogue[1][0] = "You saved your progress!";
}
public void checkEvent() { public void checkEvent() {
// Check if the player char is more than 1 tile away from the last event // Check if the player char is more than 1 tile away from the last event
int xDistance = Math.abs(panel.player.worldX - prevEventX); //return absolute number int xDistance = Math.abs(panel.player.worldX - prevEventX); //return absolute number
@@ -95,10 +103,9 @@ public class EventHandler {
} }
private void damagePit() { private void damagePit() {
panel.gameState = GameState.DIALOGUE;
panel.playSE(6); panel.playSE(6);
panel.ui.currentDialogue = "You have fallen into a pit!";
panel.player.life -= 1; panel.player.life -= 1;
eventMaster.startDialogue(eventMaster,0);
canTouchEvent = false; canTouchEvent = false;
} }
private void healingPool() { private void healingPool() {
@@ -106,7 +113,7 @@ public class EventHandler {
panel.gameState = GameState.DIALOGUE; panel.gameState = GameState.DIALOGUE;
panel.player.attackCancel = true; panel.player.attackCancel = true;
panel.playSE(2); panel.playSE(2);
panel.ui.currentDialogue = "You saved your progress!"; eventMaster.startDialogue(eventMaster,1);
//panel.player.life = panel.player.maxLife; //panel.player.life = panel.player.maxLife;
canTouchEvent = false; canTouchEvent = false;
panel.assetSetter.setMonster(); panel.assetSetter.setMonster();

View File

@@ -134,7 +134,7 @@ public class KeyHandler implements KeyListener {
private void handleDialogue(int code) { private void handleDialogue(int code) {
// EXIT STATE // EXIT STATE
if (code == KeyEvent.VK_SPACE) { if (code == KeyEvent.VK_SPACE) {
panel.gameState = GameState.PLAY; spacePressed = true;
} }
} }
private void handleCharacter(int code) { private void handleCharacter(int code) {

View File

@@ -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 de.miaurizius.jgame2d.entity.particle.Particle; import de.miaurizius.jgame2d.entity.particle.Particle;
import de.miaurizius.jgame2d.entity.projectile.Projectile; import de.miaurizius.jgame2d.entity.projectile.Projectile;
@@ -30,13 +31,14 @@ public class Entity {
public Entity attacker; public Entity attacker;
public int solidAreaDefaultX, solidAreaDefaultY; public int solidAreaDefaultX, solidAreaDefaultY;
public boolean collision; public boolean collision;
protected String[] dialogue = new String[20]; public String[][] dialogue = new String[20][20];
// STATE // STATE
public int worldX, worldY; public int worldX, worldY;
public Direction direction = Direction.DOWN; public Direction direction = Direction.DOWN;
public int spriteNum = 1; public int spriteNum = 1;
int dialogueIndex; public int dialogueSet;
public int dialogueIndex;
public boolean collisionOn; public boolean collisionOn;
public boolean invincible; public boolean invincible;
public boolean transparent; public boolean transparent;
@@ -267,10 +269,9 @@ public class Entity {
panel.player.invincible = true; panel.player.invincible = true;
} }
public void speak() { public void speak() {
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
panel.ui.currentDialogue = dialogue[dialogueIndex];
dialogueIndex++;
}
public void facePlayer() {
switch(panel.player.direction) { switch(panel.player.direction) {
case UP -> direction = Direction.DOWN; case UP -> direction = Direction.DOWN;
case DOWN -> direction = Direction.UP; case DOWN -> direction = Direction.UP;
@@ -278,6 +279,11 @@ public class Entity {
case RIGHT -> direction = Direction.LEFT; case RIGHT -> direction = Direction.LEFT;
} }
} }
public void startDialogue(Entity entity, int setNum) {
panel.gameState = GameState.DIALOGUE;
panel.ui.tradingNPC = entity;
dialogueSet = setNum;
}
public void dyingAnimation(Graphics2D graphics2d) { public void dyingAnimation(Graphics2D graphics2d) {
dyingCount++; dyingCount++;
int incr = 5; int incr = 5;

View File

@@ -46,6 +46,7 @@ public class Player extends Entity {
getPlayerImage(); getPlayerImage();
getPlayerAttackImage(); getPlayerAttackImage();
getGuardImages(); getGuardImages();
setDialogue();
} }
// DEFAULT // DEFAULT
@@ -262,7 +263,6 @@ public class Player extends Entity {
if(index == 999) return; if(index == 999) return;
//if(!panel.keyH.spacePressed) return; //Only uncomment if text should only appear if player hits space //if(!panel.keyH.spacePressed) return; //Only uncomment if text should only appear if player hits space
attackCancel = true; attackCancel = true;
panel.gameState = GameState.DIALOGUE;
panel.npc[panel.currentMap.getIndex()][index].speak(); panel.npc[panel.currentMap.getIndex()][index].speak();
} }
public void speak() { public void speak() {
@@ -281,9 +281,7 @@ public class Player extends Entity {
attack = getAttack(); attack = getAttack();
defense = getDefense(); defense = getDefense();
panel.playSE(8); panel.playSE(8);
startDialogue(this,0);
panel.gameState = GameState.DIALOGUE;
panel.ui.currentDialogue = "You are level " + level + " now!\nYou feel stronger!";
} }
public void selectItem() { public void selectItem() {
int itemIndex = panel.ui.getItemIndex(panel.ui.playerSlotCol, panel.ui.playerSlotRow); int itemIndex = panel.ui.getItemIndex(panel.ui.playerSlotCol, panel.ui.playerSlotRow);
@@ -363,6 +361,9 @@ public class Player extends Entity {
inventory.add(currentShield); inventory.add(currentShield);
inventory.add(new KeyObj(panel)); inventory.add(new KeyObj(panel));
} }
public void setDialogue() {
dialogue[0][0] = "You are level " + level + " now!\nYou feel stronger!";
}
public int getAttack() { public int getAttack() {
attackArea = currentWeapon.attackArea; attackArea = currentWeapon.attackArea;
return attack = strength * currentWeapon.attackValue; return attack = strength * currentWeapon.attackValue;

View File

@@ -17,19 +17,25 @@ public class KeyObj extends Entity {
price = 50; price = 50;
stackable = true; stackable = true;
setDialogue();
}
public void setDialogue() {
dialogue[0][0] = "What are you doing?\nThere is no door nearby.";
dialogue[1][0] = "You used a " + name + "!\nThe door is now open.";
} }
@Override @Override
public boolean use(Entity entity) { public boolean use(Entity entity) {
panel.gameState = GameState.DIALOGUE;
int objIndex = getDetected(entity, panel.obj, "door"); int objIndex = getDetected(entity, panel.obj, "door");
if(objIndex == 999) { if(objIndex == 999) {
panel.ui.currentDialogue = "What are you doing?\nThere is no door nearby."; startDialogue(this,0);
return false; return false;
} }
panel.ui.currentDialogue = "You used a " + name + "!\nThe door is now open.";
panel.playSE(3); panel.playSE(3);
panel.obj[panel.currentMap.getIndex()][objIndex] = null; panel.obj[panel.currentMap.getIndex()][objIndex] = null;
startDialogue(this,1);
return true; return true;
} }

View File

@@ -22,12 +22,16 @@ public class PotionObj extends Entity {
price = 50; price = 50;
stackable = true; stackable = true;
setDialogue();
}
public void setDialogue() {
dialogue[0][0] = "You drank a " + name + "!\nYour life has been recovered by " + value + ".";
} }
public boolean use(Entity entity) { public boolean use(Entity entity) {
panel.gameState = GameState.DIALOGUE; startDialogue(this,0);
panel.ui.currentDialogue = "You drank a " + name + "!\n" +
"Your life has been recovered by " + value + ".";
entity.life += value; entity.life += value;
if(panel.player.life > panel.player.maxLife) panel.player.life = panel.player.maxLife; if(panel.player.life > panel.player.maxLife) panel.player.life = panel.player.maxLife;
panel.playSE(2); panel.playSE(2);

View File

@@ -23,7 +23,7 @@ public class MerchantNPC extends Entity {
@Override @Override
public void speak() { public void speak() {
super.speak(); facePlayer();
panel.gameState = GameState.TRADE; panel.gameState = GameState.TRADE;
panel.ui.tradingNPC = this; panel.ui.tradingNPC = this;
} }
@@ -40,7 +40,11 @@ public class MerchantNPC extends Entity {
right2 = initEntitySprites("npc/merchant_down_2"); right2 = initEntitySprites("npc/merchant_down_2");
} }
private void setDialogue() { private void setDialogue() {
dialogue[0] = "He he, so you found me. \nI have some good stuff. \nDo you want to trade?"; dialogue[0][0] = "He he, so you found me. \nI have some good stuff. \nDo you want to trade?";
dialogue[1][0] = "Come again, hehe!";
dialogue[2][0] = "You need more coins to buy that!";
dialogue[3][0] = "Your inventory is full!";
dialogue[4][0] = "You cannot sell an equipped item!";
} }
private void setItems() { private void setItems() {
inventory.add(new PotionObj(panel)); inventory.add(new PotionObj(panel));

View File

@@ -20,6 +20,8 @@ public class OldManNPC extends Entity {
getImage(); getImage();
setDialogue(); setDialogue();
dialogueSet = -1;
solidArea.x = 8; solidArea.x = 8;
solidArea.y = 16; solidArea.y = 16;
solidAreaDefaultX = solidArea.x; solidAreaDefaultX = solidArea.x;
@@ -48,8 +50,11 @@ public class OldManNPC extends Entity {
} }
@Override @Override
public void speak() { public void speak() {
super.speak(); super.facePlayer();
super.onPath = true; super.startDialogue(this,super.dialogueSet);
dialogueSet++;
if(dialogue[dialogueSet][0] == null) dialogueSet = 0;
// super.onPath = true;
} }
// SETTING THINGS UP // SETTING THINGS UP
@@ -64,10 +69,16 @@ public class OldManNPC extends Entity {
right2 = initEntitySprites("npc/oldman_right_2"); right2 = initEntitySprites("npc/oldman_right_2");
} }
private void setDialogue() { private void setDialogue() {
dialogue[0] = "Hello, lad."; dialogue[0][0] = "Hello, lad.";
dialogue[1] = "So you've come to this island to \nfind the treasure?"; dialogue[0][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[0][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[0][3] = "Well, good luck on you.";
dialogue[4] = "I heard drinking the water of the \nholy lake makes you feel fine again..."; dialogue[0][4] = "I heard drinking the water of the \nholy lake makes you feel fine again...";
dialogue[1][0] = "If you become tired, reset at the water.";
dialogue[1][1] = "However, the monsters reappear if you rest.\nI don't know why but that's how it works.";
dialogue[1][2] = "In any case, don't push yourself too hard.";
dialogue[2][0] = "I wonder how to open that door...";
} }
} }

View File

@@ -28,31 +28,32 @@ public class ChestObj extends Entity {
solidAreaDefaultY = solidArea.y; solidAreaDefaultY = solidArea.y;
} }
public void setDialogue() {
dialogue[0][0] = "You open the chest and find a " + loot.name + "!\nBut your inventory is full...";
dialogue[1][0] = "You open the chest and find a " + loot.name + "!\nYou obtain the " + loot.name + "!";
dialogue[2][0] = "It's already empty...";
}
@Override @Override
public void setLoot(Entity loot) { public void setLoot(Entity loot) {
this.loot = loot; this.loot = loot;
setDialogue();
} }
@Override @Override
public void interact() { public void interact() {
panel.gameState = GameState.DIALOGUE;
if(this.opened) { if(this.opened) {
panel.ui.currentDialogue = "It's already empty..."; startDialogue(this,2);
return; return;
} }
panel.playSE(3); panel.playSE(3);
StringBuilder sb = new StringBuilder();
sb.append("You open the chest and find a ").append(loot.name).append("!");
if(!panel.player.canObtainItem(loot)) { if(!panel.player.canObtainItem(loot)) {
sb.append("\nBut your inventory is full..."); startDialogue(this,0);
panel.ui.currentDialogue = sb.toString();
return; return;
} }
sb.append("\nYou obtain the ").append(loot.name).append("!");
down1 = image2; down1 = image2;
opened = true; opened = true;
panel.ui.currentDialogue = sb.toString(); startDialogue(this,1);
} }
} }

View File

@@ -23,12 +23,17 @@ public class DoorObj extends Entity {
solidArea.height = 32; solidArea.height = 32;
solidAreaDefaultX = solidArea.x; solidAreaDefaultX = solidArea.x;
solidAreaDefaultY = solidArea.y; solidAreaDefaultY = solidArea.y;
setDialogue();
}
public void setDialogue() {
dialogue[0][0] = "You need a key to open this.";
} }
@Override @Override
public void interact() { public void interact() {
panel.gameState = GameState.DIALOGUE; startDialogue(this,0);
panel.ui.currentDialogue = "You need a key to open this.";
} }
} }