Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class NPC extends Entity {
- //-----------------------------------------------------------------
- // Variables
- //-----------------------------------------------------------------
- private String[] dialog1, dialog2;
- public boolean talked;
- private int counterX, counterY, timeX, timeY;
- private Random rand = new Random(System.currentTimeMillis());
- //-----------------------------------------------------------------
- // Constructor
- //-----------------------------------------------------------------
- public NPC(String name, int initX, int initY, String[] dialog1, String[] dialog2, GameCanvas gc){
- this.gc = gc;
- this.imageName = "enemy";
- this.entityName = name;
- this.health = 100;
- this.dialog1 = dialog1;
- this.dialog2 = dialog2;
- this.initX = initX; //Starting point
- this.initY = initY; //Starting point
- //Random Movement
- this.counterX = 0;
- this.counterY = 0;
- this.timeX = 0;
- this.timeY = 0;
- }
- //-----------------------------------------------------------------
- // Random Movement Methods
- //-----------------------------------------------------------------
- public void randomMovement(){
- int vx = 0;
- int vy = 0;
- if(counterX >= timeX){
- vx = rand.nextInt(3) - 1;
- timeX = rand.nextInt(300);
- counterX = 0;
- moveRight = false;
- moveLeft = false;
- }
- if(counterY >= timeY){
- vy = rand.nextInt(3) - 1;
- timeY = rand.nextInt(300);
- counterY = 0;
- moveUp = false;
- moveDown = false;
- }
- if(vx == 1){
- moveRight = true;
- }
- else if(vx == -1){
- moveLeft = true;
- }
- if(vy == 1){
- moveDown = true;
- }
- else if(vy == -1){
- moveUp = true;
- }
- counterX++;
- counterY++;
- }
- //-----------------------------------------------------------------
- // Getter Methods
- //-----------------------------------------------------------------
- public String[] getDialog1(){
- return dialog1;
- }
- public String[] getDialog2(){
- return dialog2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment