3 Replies Latest reply on Oct 4, 2012 9:36 AM by alaStickman

    My variable isn't changing to false on hitTest?

    Shockeey

      My code... ((Alot is irrelitive) important part in green, not working in red)

       

      stop();

      var speed_var:Number = 15;
      var shooting_var:Boolean = false;
      var enSpeed_var:Number = 20;
      var score_var:Number = 0;
      var bulletSpeed_var:Number = 20;


      player1_mc.onEnterFrame = function()
      {
      //Ship movement

      if ((Key.isDown(Key.LEFT)) && (this._x > 30))
      {
        this._x -= speed_var;
      }
      if ((Key.isDown(Key.RIGHT)) && (this._x < Stage.width - 30))
      {
        this._x += speed_var;
      }

      };

       


      //Enemy movement
      enemy_mc.onEnterFrame = function()
      {
      this._y += enSpeed_var;
      if (this._y > 570)
      {
        this._x = random(Stage.width);
        this._y = -20;
        score_var -= 50;
        score_txt.text = score_var;
      }
      if (this.hitTest(player1_mc))
      {
        score_txt.text = "Game Over";
        unloadMovie(player1_mc);
        unloadMovie(this);
      }
      if(this.hitTest(bullet_mc)){
        score_var +=50;
        score_txt.text = score_var;
        this._x = random(Stage.width);
        this._y = -20;
        unloadMovie(bullet_mc);

      shooting_var = false;                               **This isn't changing instantly or at all so I can't shoot again** (It works if the bulet is off screen just not here)

      }
      };

       

       

      //shooting
      onEnterFrame = function ()
      {
      if (Key.isDown(Key.SPACE) && shooting_var == false)
      {
        trace("test");
        shooting_var = true;
        attachMovie("bullet","bullet_mc",_root.getNextHighestDepth());
        bullet_mc._x = player1_mc._x;
        bullet_mc._y = player1_mc._y;
        bullet_mc.onEnterFrame = function()
        {
         this._y -= bulletSpeed_var;
         this._x = player1_mc._x;
         if (this._y < 0)
         {
          removeMovieClip(bullet_mc);
          shooting_var = false;
         }
        
        };
      }
      };