Guest User

Untitled

a guest
Aug 19th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ZombieController extends Script {
  2.     int state = 0; //0 - delay 1 - run 2 - attack
  3.     MoveComponent move;
  4.     SearchTargetComponent search;
  5.  
  6.     public void initialize() {
  7.         move = gameObject.getScript(MoveComponent.class);
  8.         search = gameObject.getScript(SearchTargetComponent.class);    
  9.     }
  10.  
  11.     public void update(float delta) {
  12.         if(!move.inMotion())
  13.             if(search.haveTarget()) {
  14.                 if(search.targetIsClose(0.5f)) {
  15.                     state = 2;
  16.                 } else {
  17.                     move.moveTo(search.getTarget());
  18.                     state = 1;
  19.                 }
  20.             } else {
  21.                 state = 0;
  22.             }
  23.         }
  24.         //run animation, damage on the target, etc...
  25.     }
  26.  
  27.     public void move(int x, int y) {
  28.         if(state == 2) return;
  29.         move.moveTo(x, y);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment