refactor dialogue handling for various game entities
This commit is contained in:
@@ -294,6 +294,19 @@ public class UI {
|
||||
x += panel.tileSize;
|
||||
y += panel.tileSize;
|
||||
|
||||
if(tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex] != null) {
|
||||
currentDialogue = tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex];
|
||||
if(panel.keyH.spacePressed) {
|
||||
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")) {
|
||||
graphics2d.drawString(line, x, y);
|
||||
y += 40;
|
||||
@@ -419,6 +432,7 @@ public class UI {
|
||||
|
||||
// TRADING
|
||||
private void tradeSelect() {
|
||||
tradingNPC.dialogueSet = 0;
|
||||
drawDialogueScreen();
|
||||
|
||||
int x = panel.tileSize*15;
|
||||
@@ -449,9 +463,8 @@ public class UI {
|
||||
graphics2d.drawString(">", x-panel.tileSize/2, y);
|
||||
if(panel.keyH.spacePressed) {
|
||||
commandNum = 0;
|
||||
tradingNPC.startDialogue(tradingNPC,1);
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "Come again, hehe!";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,9 +501,7 @@ public class UI {
|
||||
if(!panel.keyH.spacePressed) return;
|
||||
if(tradingNPC.inventory.get(itemIndex).price > panel.player.coins) {
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "You need more coins to buy that!";
|
||||
drawDialogueScreen();
|
||||
tradingNPC.startDialogue(tradingNPC,2);
|
||||
return;
|
||||
}
|
||||
if(panel.player.canObtainItem(tradingNPC.inventory.get(itemIndex))) {
|
||||
@@ -498,9 +509,7 @@ public class UI {
|
||||
return;
|
||||
}
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "Your inventory is full!";
|
||||
drawDialogueScreen();
|
||||
tradingNPC.startDialogue(tradingNPC,3);
|
||||
}
|
||||
}
|
||||
private void tradeSell() {
|
||||
@@ -537,8 +546,7 @@ public class UI {
|
||||
if(panel.player.inventory.get(itemIndex) == panel.player.currentWeapon || panel.player.inventory.get(itemIndex) == panel.player.currentShield) {
|
||||
commandNum = 0;
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "You cannot sell an equipped item!";
|
||||
tradingNPC.startDialogue(tradingNPC,4);
|
||||
return;
|
||||
}
|
||||
if(panel.player.inventory.get(itemIndex).amt <= 1) panel.player.inventory.remove(itemIndex);
|
||||
|
||||
@@ -14,6 +14,7 @@ public class EventHandler {
|
||||
|
||||
GamePanel panel;
|
||||
EventRect[][][] eventRect;
|
||||
Entity eventMaster; //Like a "voice of god"
|
||||
public int prevEventX, prevEventY;
|
||||
boolean canTouchEvent = true;
|
||||
|
||||
@@ -23,6 +24,7 @@ public class EventHandler {
|
||||
|
||||
public EventHandler(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
eventMaster = new Entity(panel);
|
||||
eventRect = new EventRect[Map.values().length][panel.maxWorldCol][panel.maxWorldRow];
|
||||
|
||||
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() {
|
||||
// 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
|
||||
@@ -95,10 +103,9 @@ public class EventHandler {
|
||||
}
|
||||
|
||||
private void damagePit() {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.playSE(6);
|
||||
panel.ui.currentDialogue = "You have fallen into a pit!";
|
||||
panel.player.life -= 1;
|
||||
eventMaster.startDialogue(eventMaster,0);
|
||||
canTouchEvent = false;
|
||||
}
|
||||
private void healingPool() {
|
||||
@@ -106,7 +113,7 @@ public class EventHandler {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.player.attackCancel = true;
|
||||
panel.playSE(2);
|
||||
panel.ui.currentDialogue = "You saved your progress!";
|
||||
eventMaster.startDialogue(eventMaster,1);
|
||||
//panel.player.life = panel.player.maxLife;
|
||||
canTouchEvent = false;
|
||||
panel.assetSetter.setMonster();
|
||||
|
||||
@@ -134,7 +134,7 @@ public class KeyHandler implements KeyListener {
|
||||
private void handleDialogue(int code) {
|
||||
// EXIT STATE
|
||||
if (code == KeyEvent.VK_SPACE) {
|
||||
panel.gameState = GameState.PLAY;
|
||||
spacePressed = true;
|
||||
}
|
||||
}
|
||||
private void handleCharacter(int code) {
|
||||
|
||||
Reference in New Issue
Block a user