let Humanoid, Pathfinder, gameSettings;

Pathfinder = require('pathfinder');
gameSettings = require('settings');

Humanoid = function(attributes){
  this.position = attributes.position ||
    { x: (5+ Math.floor(Math.random()*591)), y: (5+ Math.floor(Math.random()*391)) };
  this.speed = attributes.speed;
  this.humanType = attributes.humanType;
  this.timeSinceInfection = 0;
  this.lastPosition = { x: this.position.x, y: this.position.y };
};

Humanoid.prototype = {
  isAttractedTo(nearestObject){
    return nearestObject.humanType === 'human' || nearestObject.humanType === 'player';
  },

  storeLastPosition(){
    this.lastPosition = {'x': this.position.x, 'y': this.position.y};
  },

  isLastMoveRepeated(potentialMove){
    return (
      (Math.abs(potentialMove.x - this.lastPosition.x) < gameSettings.repitionTolerance) &&
        (Math.abs(potentialMove.y - this.lastPosition.y) < gameSettings.repitionTolerance)
    );
  },

  getBitten(){
    this.humanType = 'infectedHuman';
    this.speed = 0;
  },

  bite(human){
    if ( human ) { human.getBitten(); }
  },

  turnToZombie(){
    this.humanType = 'zombie';
    this.speed = gameSettings.zombieSpeed;
  },

  isAbleToBite(human){
    if ( human ) {
      return (
        this.humanType === 'zombie' && (Pathfinder.distanceTo( human.position, this.position ) < 10)
      );
    }
  },

  incrementTimeSinceInfection(){
    this.timeSinceInfection ++;
    if (this.timeSinceInfection === 5){
      this.turnToZombie();
    }
  },

  moveNearest(nearestObject){
    let potentialMove;
    if (this.isAttractedTo(nearestObject)){
      potentialMove = Pathfinder.moveTowards(this.position, nearestObject.position, this.speed);
    } else {
      potentialMove = Pathfinder.moveAwayFrom(this.position, nearestObject.position, this.speed);
    }
    if (this.lastPosition.x === this.position.x && this.lastPosition.y === this.position.y){
      this.storeLastPosition();
      return Pathfinder.moveRandomly(this.position, this.speed);
    } else if (this.isLastMoveRepeated(potentialMove)){
      this.storeLastPosition();
      return Pathfinder.movePerpendicularTo(this.position, nearestObject.position, this.speed);
    } else {
      this.storeLastPosition();
      return potentialMove;
    }
  },
};
module.exports = Humanoid;

@@ -1,17 +1,7 @@
 let
- Humanoid,
  Pat
@@ -97,16 +97,22 @@
 ngs');%0A%0A
+class 
 Humanoid
@@ -116,18 +116,23 @@
 oid 
-= function
+%7B%0A  constructor
 (att
@@ -141,16 +141,18 @@
 butes)%7B%0A
+  
   this.p
@@ -188,16 +188,18 @@
  %7C%7C%0A    
+  
 %7B x: (5+
@@ -272,16 +272,18 @@
 91)) %7D;%0A
+  
   this.s
@@ -307,16 +307,18 @@
 .speed;%0A
+  
   this.h
@@ -348,24 +348,26 @@
 umanType;%0A  
+ 
+ 
 this.timeSin
@@ -383,16 +383,18 @@
 on = 0;%0A
+  
   this.l
@@ -455,34 +455,12 @@
  %7D;%0A
-%7D;%0A%0AHumanoid.prototype = %7B
+  %7D%0A
 %0A  i
@@ -575,25 +575,24 @@
 player';%0A  %7D
-,
 %0A%0A  storeLas
@@ -633,11 +633,9 @@
  = %7B
-'x'
+x
 : th
@@ -653,11 +653,9 @@
 .x, 
-'y'
+y
 : th
@@ -669,25 +669,24 @@
 tion.y%7D;%0A  %7D
-,
 %0A%0A  isLastMo
@@ -914,25 +914,24 @@
 )%0A    );%0A  %7D
-,
 %0A%0A  getBitte
@@ -992,25 +992,24 @@
 eed = 0;%0A  %7D
-,
 %0A%0A  bite(hum
@@ -1052,25 +1052,24 @@
 ten(); %7D%0A  %7D
-,
 %0A%0A  turnToZo
@@ -1149,25 +1149,24 @@
 ieSpeed;%0A  %7D
-,
 %0A%0A  isAbleTo
@@ -1327,25 +1327,24 @@
 );%0A    %7D%0A  %7D
-,
 %0A%0A  incremen
@@ -1474,17 +1474,16 @@
    %7D%0A  %7D
-,
 %0A%0A  move
@@ -2247,12 +2247,11 @@
 %0A  %7D
-,
 %0A%7D
-;
+%0A
 %0Amod

feat(humanoid) convert humanoid to es6 class