3 Replies Latest reply on Sep 15, 2006 11:31 AM by crazyjoemilan

    Flash game miss counter

    Hajk
      Hi

      I've finally managed to create a game in Flash 8 following a great tutorial. Everything worked out fine except one last thing: I’ve managed to get a hit-counter to work and show up on the scene but the miss-counter still says blank even when it's exactly the same script as the hit-counter (with different names of course).

      Here's the code:

      /***********import classes*************/
      /*****declare variables and instances ******/
      var gunSpeed:Number = 10;
      var bulletSpeed:Number = 10;
      var alienSpeed:Number = 10;
      var bulletCount:Number = 1;
      var alienCount:Number = 1;
      var hits:Number = 0;
      var misses:Number = 0;
      /************create objects************/
      var keyListener:Object = new Object();
      var initBullet:Object = new Object();
      var initAlien:Object = new Object();
      var sndShoot:Sound = new Sound();
      sndShoot.attachSound("shoot");
      var sndBoom:Sound = new Sound();
      sndBoom.attachSound("explosion")
      /**********handle events**************/
      initAlien.onEnterFrame = function(){
      this._y += alienSpeed;
      if (this._y<0){
      removeMovieClip(this);
      misses ++;
      txtMisses.text = misses;
      if (misses == 5){
      mcGameOver._visible = ture;
      clearInterval(game);
      }
      }
      }
      initBullet.onEnterFrame = function(){
      this._y -= bulletSpeed;
      for (var i:Number = 1;i <=alienCount; i++){
      if (this.hitTest(this._parent["mcAlien"+i])){
      //removeMovieClip(this._parent["mcAlien"+i]);
      this._parent["mcAlien"+i].gotoAndPlay(2);
      removeMovieClip(this);
      sndBoom.start();
      hits ++;
      txtHits.text = hits;
      }
      }
      if (this._y>Stage.height){
      removeMovieClip(this);
      }
      }
      keyListener.onKeyDown = function(){
      if (Key.isDown(Key.SPACE)){
      newBullet();
      sndShoot.start();
      }
      }
      mcGun.onEnterFrame = function() {
      if (Key.isDown(Key.RIGHT)) {
      if (this._x<Stage.width-this._width) {
      this._x += gunSpeed;
      }
      }
      if (Key.isDown(Key.LEFT)) {
      if (this._x>0) {
      this._x -= gunSpeed;
      }
      }

      };
      /*************functions***************/
      function newBullet(){
      bulletName = "mcBullet"+String(bulletCount);
      bulletDepth = this.getNextHighestDepth();
      this.attachMovie("bullet",bulletName,bulletDepth,initBullet);
      this[bulletName]._x = mcGun._x+mcGun._width/2;
      this[bulletName]._y = mcGun._y;
      bulletCount ++;
      }
      function newAlien(){
      alienName = "mcAlien"+String(alienCount);
      alienDepth = this.getNextHighestDepth();
      this.attachMovie("alien",alienName,alienDepth,initAlien);
      this[alienName]._x = Math.random()*(Stage.width-this[alienName]._width)+this[alienName]._width/2;
      this[alientName]._y = -50;
      alienCount ++;
      }
      /************set properties*************/
      /**************run now***************/
      Key.addListener(keyListener);
      var game = setInterval(this,"newAlien",1000);
      mcGameOver._visible = false;

      Please help
        • 1. Re: Flash game miss counter
          crazyjoemilan Level 2
          if your hit counter is working, can't you only have either hit or miss? I'd just derrive the misses from the hit counter. Is there a reason that wouldn't work?
          • 2. Re: Flash game miss counter
            Hajk Level 1
            no not really... I need the miss-counter because when you miss five then it's game over. If I don’t have a miss-counter then the game will go on and on even if you miss every one of them.
            • 3. Flash game miss counter
              crazyjoemilan Level 2
              I'm sorry, you're right, the way you have it coded doesn't allow for that. I should've looked closer. Lets see if we can't find the problem...

              initAlien.onEnterFrame = function(){
              trace("the miss function is running");
              this._y += alienSpeed;
              if (this._y<0){
              trace("oh crap");
              removeMovieClip(this);
              misses ++;
              trace(misses);
              txtMisses.text = misses;
              if (misses == 5){
              mcGameOver._visible = ture;
              clearInterval(game);
              }
              }
              }

              Okay, run that in place of the other and it'll head us in the right direction.