Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Use a loop to both move and attack.
  2.  
  3. var step = 12;
  4. var flip = true;
  5. var bottom_path = 22;
  6. var top_path = 34;
  7.  
  8. loop {
  9.    
  10.     var enemy = this.findNearestEnemy(),
  11.         item = this.findNearestItem();
  12.        
  13.     if (enemy) {
  14.                    
  15.         this.moveXY(enemy.pos.x, enemy.pos.y);
  16.         while (enemy.health > 0) this.attack(enemy);                
  17.        
  18.     } else if (item) {
  19.        
  20.         destination = item.pos;
  21.         this.moveXY(destination.x, destination.y);
  22.         this.moveXY(this.pos.x, bottom_path);
  23.        
  24.     } else {        
  25.        
  26.         if (flip) {
  27.             this.moveXY(this.pos.x + 12, bottom_path);
  28.         } else {
  29.             this.moveXY(this.pos.x, top_path);
  30.         }
  31.        
  32.         flip = !flip;
  33.        
  34.     }
  35.    
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement