open NPC dialogue if you collide with it
This commit is contained in:
@@ -25,12 +25,15 @@ public class Entity {
|
||||
public int solidAreaDefaultX, solidAreaDefaultY;
|
||||
public boolean collisionOn = false;
|
||||
public int actionLock = 0;
|
||||
String[] dialogue = new String[20];
|
||||
int dialogueIndex = 0;
|
||||
|
||||
public Entity(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
public void setAction() {}
|
||||
public void speak() {}
|
||||
public void update() {
|
||||
setAction();
|
||||
collisionOn = false;
|
||||
|
||||
@@ -13,6 +13,7 @@ public class OldManNPC extends Entity {
|
||||
direction = Direction.DOWN;
|
||||
speed = 1;
|
||||
getImage();
|
||||
setDialogue();
|
||||
}
|
||||
|
||||
public void getImage() {
|
||||
@@ -26,6 +27,13 @@ public class OldManNPC extends Entity {
|
||||
right2 = initEntitySprites("npc/oldman_right_2");
|
||||
}
|
||||
|
||||
public void setDialogue() {
|
||||
dialogue[0] = "Hello, lad.";
|
||||
dialogue[1] = "So you've come to this island to find the treasure?";
|
||||
dialogue[2] = "I used to be a great wizard but now... I'm a bit too old for taking an adventure";
|
||||
dialogue[3] = "Well, good luck on you.";
|
||||
}
|
||||
|
||||
public void setAction() {
|
||||
actionLock++;
|
||||
if(actionLock != 120) return; //lock action for x frames
|
||||
@@ -36,7 +44,19 @@ public class OldManNPC extends Entity {
|
||||
if(i > 50 && i <= 75) direction = Direction.LEFT;
|
||||
if(i > 75) direction = Direction.RIGHT;
|
||||
actionLock = 0;
|
||||
}
|
||||
|
||||
public void speak() {
|
||||
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
||||
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
||||
dialogueIndex++;
|
||||
|
||||
switch(panel.player.direction) {
|
||||
case UP -> direction = Direction.DOWN;
|
||||
case DOWN -> direction = Direction.UP;
|
||||
case LEFT -> direction = Direction.RIGHT;
|
||||
case RIGHT -> direction = Direction.LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package de.miaurizius.jgame2d.entity;
|
||||
|
||||
import de.miaurizius.jgame2d.core.*;
|
||||
import de.miaurizius.jgame2d.core.enums.Direction;
|
||||
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||
import de.miaurizius.jgame2d.core.handlers.KeyHandler;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class Player extends Entity {
|
||||
|
||||
@@ -91,12 +91,12 @@ public class Player extends Entity {
|
||||
|
||||
public void pickObject(int index) {
|
||||
if(index == 999) return;
|
||||
|
||||
}
|
||||
|
||||
public void interactNPC(int index) {
|
||||
if(index == 999) return;
|
||||
System.out.println("npc collision detected");
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.npc[index].speak();
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphics2d) {
|
||||
|
||||
Reference in New Issue
Block a user