konflikt

RPG Game - NPC.java - 10/31/2011

Oct 7th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class NPC extends Entity {
  4.    
  5.     //-----------------------------------------------------------------
  6.     // Variables
  7.     //-----------------------------------------------------------------
  8.     private String[] dialog1, dialog2;
  9.     public boolean talked;
  10.    
  11.     private int counterX, counterY, timeX, timeY;
  12.     private Random rand = new Random(System.currentTimeMillis());
  13.    
  14.     //-----------------------------------------------------------------
  15.     // Constructor
  16.     //-----------------------------------------------------------------
  17.     public NPC(String name, int initX, int initY, String[] dialog1, String[] dialog2, GameCanvas gc){
  18.         this.gc = gc;
  19.        
  20.         this.imageName = "enemy";
  21.         this.entityName = name;
  22.         this.health = 100;
  23.        
  24.         this.dialog1 = dialog1;
  25.         this.dialog2 = dialog2;
  26.        
  27.         this.initX = initX; //Starting point
  28.         this.initY = initY; //Starting point
  29.        
  30.         //Random Movement
  31.         this.counterX = 0;
  32.         this.counterY = 0;
  33.         this.timeX = 0;
  34.         this.timeY = 0;
  35.     }
  36.    
  37.     //-----------------------------------------------------------------
  38.     // Random Movement Methods
  39.     //-----------------------------------------------------------------
  40.  
  41.     public void randomMovement(){
  42.         int vx = 0;
  43.         int vy = 0;
  44.         if(counterX >= timeX){
  45.             vx = rand.nextInt(3) - 1;
  46.             timeX = rand.nextInt(300);
  47.             counterX = 0;
  48.             moveRight = false;
  49.             moveLeft = false;
  50.         }
  51.        
  52.         if(counterY >= timeY){
  53.             vy = rand.nextInt(3) - 1;
  54.             timeY = rand.nextInt(300);
  55.             counterY = 0;
  56.             moveUp = false;
  57.             moveDown = false;
  58.         }
  59.        
  60.         if(vx == 1){
  61.             moveRight = true;
  62.         }
  63.         else if(vx == -1){
  64.             moveLeft = true;
  65.         }
  66.        
  67.         if(vy == 1){
  68.             moveDown = true;
  69.         }
  70.         else if(vy == -1){
  71.             moveUp = true;
  72.         }
  73.        
  74.         counterX++;
  75.         counterY++;
  76.     }
  77.    
  78.     //-----------------------------------------------------------------
  79.     // Getter Methods
  80.     //-----------------------------------------------------------------
  81.     public String[] getDialog1(){
  82.         return dialog1;
  83.     }
  84.    
  85.     public String[] getDialog2(){
  86.         return dialog2;
  87.     }
  88.    
  89. }
Advertisement
Add Comment
Please, Sign In to add comment