49 lines
1.6 KiB
Java
49 lines
1.6 KiB
Java
package de.miaurizius.jgame2d.entity;
|
|
|
|
import de.miaurizius.jgame2d.core.enums.Direction;
|
|
import de.miaurizius.jgame2d.core.GamePanel;
|
|
|
|
import java.util.Random;
|
|
|
|
public class OldManNPC extends Entity {
|
|
|
|
public OldManNPC(GamePanel panel) {
|
|
super(panel);
|
|
|
|
direction = Direction.DOWN;
|
|
speed = 1;
|
|
getImage();
|
|
setDialogue();
|
|
}
|
|
|
|
public void getImage() {
|
|
up1 = initEntitySprites("npc/oldman_up_1");
|
|
up2 = initEntitySprites("npc/oldman_up_2");
|
|
down1 = initEntitySprites("npc/oldman_down_1");
|
|
down2 = initEntitySprites("npc/oldman_down_2");
|
|
left1 = initEntitySprites("npc/oldman_left_1");
|
|
left2 = initEntitySprites("npc/oldman_left_2");
|
|
right1 = initEntitySprites("npc/oldman_right_1");
|
|
right2 = initEntitySprites("npc/oldman_right_2");
|
|
}
|
|
|
|
public void setDialogue() {
|
|
dialogue[0] = "Hello, lad.";
|
|
dialogue[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[3] = "Well, good luck on you.";
|
|
}
|
|
|
|
public void setAction() {
|
|
actionLock++;
|
|
if(actionLock != 120) return; //lock action for x frames
|
|
Random rand = new Random();
|
|
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
|
|
if(i <= 25) direction = Direction.UP;
|
|
if(i > 25 && i <= 50) direction = Direction.DOWN;
|
|
if(i > 50 && i <= 75) direction = Direction.LEFT;
|
|
if(i > 75) direction = Direction.RIGHT;
|
|
actionLock = 0;
|
|
}
|
|
}
|