
var BadGuy = new Class({
    Extends: Hero,
    initialize: function(){
		this.parent(GAMEUNITTYPE.MONSTER);
		game.heroes.push(this);
        this.currentDirection='left';
        this.horizontalStepsBeforeChangeDirection=4;
        this.verticalStepsBeforeChangeDirection =2;
        this.delayBeat=0; // to change speed , chnage this one
        this.sense = 1;
        this.delayBeatContor=0;
        this.deltaX=0;
        this.deltaY=0; // pixels made by the hero without any change in the direction it runs
        this.points = 50;
        this.cuanta=2;
    },
      moveAlongDirection: function(){
      	  /// this causes the badguys to move slower than the hero
          if(this.delayBeatContor<=this.delayBeat){
              this.delayBeatContor++;
              this.cuanta=1;
          }
          this.cuanta=2;
          this.delayBeatContor=0;
          //////////// end slow speed timer
          this.parent();
          this.badGuyMove();
          this.killTheHero();
      },
      badGuyMove: function(){
          if(this.hitWorldBoundary==true){
              this.sense=this.sense*(-1);
              this.hitWorldBoundary=false;
          }
          if(this.hitTheWall){
          	  /////// if we hit the wall we turn back or we change direction
          	  var randy=Math.round(Math.random()*8);
              if(randy>3){
              		this.sense=this.sense*(-1); /// change the sense in the same direction - this is preferred
              } else {
	              if(this.currentDirection=='left')
	                  this.currentDirection='top';
	              else
	                  this.currentDirection='left';
              }
          } else {
	          if(this.currentDirection=='left'){
	              this.deltaX+=this.cuanta;
	              if(this.deltaX>=this.horizontalStepsBeforeChangeDirection*game.standardWidth){
	                  this.deltaX=0;
	                  var randy=Math.round(Math.random()*8);
	                  if(randy>4)
	                    this.currentDirection='top';
	                    else
	                        this.sense=this.sense*(-1);
	                  this.horizontalStepsBeforeChangeDirection=Math.round(Math.random()*(game.worldWidth/game.standardWidth));
	              }
	          }
	          if(this.currentDirection=='top'){
	              this.deltaY+=this.cuanta;
	              if(this.deltaY>=this.verticalStepsBeforeChangeDirection*game.standardHeight){
	                  this.deltaY=0;
	                  var randy=Math.round(Math.random()*8);
	                  if(randy>4)
	                    this.currentDirection='left';
	                else
	                    this.sense=this.sense*(-1);
	                  this.verticalStepsBeforeChangeDirection =Math.round(Math.random()*(game.worldHeight/game.standardHeight));
	              }
	          }
          }
      },
      updateHeroSprite: function(){
          // not implemented yet
      },
        die: function(){
            util.removeElementFromArray(this,game.heroes);
            if($defined(game.hero))
                game.hero.addPointsToScore(this.points);
        },
      killTheHero: function(){
          if($defined(game.hero)){
              if(!(game.hero.x+game.standardWidth<=this.x || game.hero.x>=this.x+game.standardWidth || game.hero.y>=this.y+game.standardHeight || game.hero.y+game.standardHeight<=this.y))
                game.hero.terminate();
          }
      }
    });
