8 Replies Latest reply on Sep 29, 2010 2:51 PM by Radu Cristian Dimitrie

    Fixing a game I'm working on.

    mldb88 Level 2

      Okay I've got a simple space shooter game and everything works fine except one thing.   I can't get the boss to fire.  Instead, the game recognizes the fact the bos is firing, but automatically registers the shots as connecting with the player, without firing them, causing an instant game over the moment the boss comes into play. here is the code.

       

      stop();
      lives=3;
      score=0;
      bosshp = 0;
      shot=0;

      i=0;
      a=0;
      b=0;
      c=0;
      enemies=[];
      boss=[];
      rock=[];
      ebullets=[];

      spawnEnemy = function(){
          _root.attachMovie("grunt","grunt"+i,_root.getNextHighestDepth());
          _root["grunt"+i]._x=random(Stage.width);
          _root["grunt"+i]._y=0;
          enemies.push("grunt"+i);
         
          _root["grunt"+i].onEnterFrame=function(){
              this._y+=3;
             
              if(this.hitTest(_root.player)){
                  for(e = 0; e < _root.enemies.length; e++){
                      if(_root.enemies[e] == this._name){
                          _root.enemies.splice(e, 1);
                      }
                  }
                 
                  this.removeMovieClip();
                  _root.lives--;
              }
              if(this._y > Stage.height){
                  for(e = 0; e <  _root.player.length; e++){
                      lives--;
                      if(_root.ebullets[e]==this.name){
                          _root.ebullets.splice(e, 1);
                      }
                  }
                  this.removeMovieClip();
              }
          }
          i++;
      }
      spawnAsteroid = function(){
          _root.attachMovie("asteroid","asteroid"+b,_root.getNextHighestDepth());
          _root["asteroid"+b]._x=random(Stage.width);
          _root["asteroid"+b]._y=0;
          rock.push("asteroid"+b);
         
          _root["asteroid"+b].onEnterFrame=function(){
              this._y +=7;
             
              if(this.hitTest(_root.player)){
                  for(g = 0; g < _root.rock.length; g++){
                      if(_root.rock[g] == this._name){
                          _root.rock.splice(g, 1);
                      }
                  }
                 
                  this.removeMovieClip();
                  _root.lives--;
              }
              if(this._y > Stage.height){
                  for(g = 0; g <  _root.rock.length; g++){
                      if(_root.rock[g]==this.name){
                          _root.rock.splice(g, 1);
                      }
                  }
                  this.removeMovieClip();
              }
          }
          b++;
      }
      spawnBoss = function(){
          _root.attachMovie("boss1","boss1"+a,_root.getNextHighestDepth());
          _root["boss1"+a]._x=(Stage.width/2);
          _root["boss1"+a]._y=7;
          boss.push("boss1"+a);
         
          _root["boss1"+a].onEnterFrame=function(){
              if(shot<10){
                  _root.attachMovie("ebullet","ebullet"+c,_root.getNextHighestDepth());
                  _root["ebullet"+c]._x=["boss1"+a]._x;
                  _root["ebullet"+c]._y=["boss1"+a]._y;
                  ebullets.push("ebullet"+c);
                  _root["ebullet"+c].onEnterFrame=function(){
                  this._y+=15;
                  if(this._y > 30){
                      this.removeMovieClip();
                  }
                 
                  for(h = 0; h < _root.ebullets.length; h++){
                      if(this.hitTest(_root[_root.ebullets[h]])){
                          lives--;
                          _root[_root.ebullets[h]].removeMovieClip();
                          _root.ebullets.splice(h, 1);
                      }
                  }
                  }
                  shot++;
                  if(Key.isDown(Key.SPACE)){
                      shot--;
                  }
                  if(["ebullet"+c]._y>Stage.height){
                     
                  }
              }
              if(Key.isDown(Key.LEFT)){
                  this._x+=3;
              }
              if(Key.isDown(Key.RIGHT)){
                  this._x-=3;
              }
              if(this.hitTest(root.player)){
                  for(f=0; f<root.boss.length; f++){
                      if(_root.boss[f] == this._name){
                          _root.boss.splice(f, 1);
                      }
              }
             
              _root.lives--;
          }
              if(this._x > Stage.height){
                  for(f = 0; f <  _root.boss.length; f++){
                      if(_root.boss[f]==this.name){
                          _root.boss.splice(f, 1);
                      }
                  }
                 
              }
          }
          a++;
      }
      onEnterFrame=function(){
          if(lives<=0){
             nextFrame();
             }
             }
            
      enemy_interval = setInterval (spawnEnemy, 1000);
      boss_interval = setInterval (spawnBoss, 40000);
      rock_interval= setInterval (spawnAsteroid, 500);

        • 1. Re: Fixing a game I'm working on.
          Radu Cristian Dimitrie

          i am not a pro, but i think calling  _root["boss1"+a].onEnterFrame inside the function that also spawns the boss is not very good idea..

          if you are using AS2, you could easily create a class for boss or put the actions code right into the movie clip..

           

          ALSO, the main problem is the  " if shot <10".. you are entering an onEnterFrame function that will shot++ every frame, that's why it happends so fast..

          you need to create another inteval for boss to fire, OR leave it onEnterFrame but calculate your rate of fire (shot) depending on your current framerate.

          • 2. Re: Fixing a game I'm working on.
            mldb88 Level 2

            problem with putting the actions in the movie clip is that the movie clip

            doesn't actually hit the stage till it's called from the code, not sure how

            i'd put action script in there w/o placing iton the stage.  trying to

            separate the function from the spawning function but they're so intertwined

            its giving me issues -_- ugh

            • 3. Re: Fixing a game I'm working on.
              Radu Cristian Dimitrie Level 1

              you can create only one spawn function, only one fire function, and just change the parameters sent to the function depending on what you want to spawn or fire..

               

              i checked again on some of my games, it's ok to place the function there...

              just create another way for boss to fire..

              here's an example:

               

              function fire(from, to, speed, acc, maxspeed, projectile, damage, splash, slow, poison) // 'from' and 'to' if you want guided lasers..

              {

                    ++_root.particleCount;
                  _root[projectile].duplicateMovieClip("p" + _root.particleCount, 2000 + _root.particleCount);
                  r = _root["p" + _root.particleCount];
                 
                  dir = Math.atan2(from._y - to._y, from._x - to._x) * 180 / 3.141593E+000;
                  rads = dir * 3.141593E+000 / 180;
                  r._x = from._x;
                  r._y = from._y;
                  r._x  = r._x - Math.cos(rads) * (from._width/2);
                  r._y  = r._y - Math.sin(rads) * (from._height/2);

               

                  r.targ = to;
                  if ("" + to == "")
                  {
                      r.removeMovieClip();
                  }
                 
                  r.speed = speed;
                  r.acc = acc;
                  r.maxspeed = maxspeed;
                  r.projectile = projectile;
                 
                  r.damage = damage;
                  r.splash = splash;
                  r.slow = slow;
                  r.poison = poison;
                 
                  r.onEnterFrame = function ()
                  {
                      if ("" + this.targ != "")
                      {
                          this.targX = this.targ._x;
                          this.targY = this.targ._y;
                      }
                      else
                      {
                          if ("" + this.targX == "undefined") {
                              this.removeMovieClip();
                          }
                      }
                     
                      this.dir = Math.atan2(this.targY - this._y, this.targX - this._x) * 180 / 3.141593E+000;
                      this._rotation = this.dir + 90;
                      this.rads = this.dir * 3.141593E+000 / 180;
                      this._x = this._x + Math.cos(this.rads) * this.speed;
                      this._y = this._y + Math.sin(this.rads) * this.speed;
                     
                      if (this.speed < this.maxspeed)
                      {
                          this.speed = this.speed + this.acc;
                      }
                     
                      d = Math.sqrt(Math.pow(this._x - this.targX, 2) + Math.pow(this._y - this.targY, 2));
                      if (d < 10)
                      {
                          Explosion(projectile, this._x, this._y);
                         
                          if (this.slow > 0)
                          {
                              this.targ.speed = this.targ.maxspeed / 100 * (100 - this.slow);
                          }
                             
                          if (this.poison > 0)
                          {
                              this.targ.poison = this.poison;
                          }
                         
                          if (this.splash > 0)
                          {               
                              for (i = 0; i <= _root.creepArray.length; i++)
                              {
                                  if ("" + _root.creepArray[i] != "" && _root.creepArray[i] != this.targ)
                                  {           
                                      d = Math.sqrt(Math.pow(this._x - _root.creepArray[i]._x, 2) + Math.pow(this._y - _root.creepArray[i]._y, 2));
                                      if (d < this.splash)
                                      {
                                          _root.creepArray[i].health = _root.creepArray[i].health - this.damage * (1 - (d / this.splash));
                                          if (this.slow > 0)
                                          {
                                              _root.creepArray[i].speed = _root.creepArray[i].maxspeed / 100 * (100 - this.slow);
                                          }
                                         
                                          if (this.poison > 0)
                                          {
                                              _root.creepArray[i].poison = int(this.poison * (d / this.splash));
                                          }                           
                                      }   
                                  }
                              }
                         
                          }
                             
                          this.targ.health = this.targ.health - this.damage;
                          if (targ.health <= 0)
                          {
                              targ.isDead = 1;
                          }
                         
                          this.removeMovieClip();
                     
                      }
                     
                      if (_root.particleCount > 50)
                      {
                          _root.particleCount = 0;
                      }
                  };

              }

              • 4. Re: Fixing a game I'm working on.
                mldb88 Level 2

                Ok.... you completely lost me... O_o

                • 5. Re: Fixing a game I'm working on.
                  Radu Cristian Dimitrie Level 1

                  you don't have to copy ever single letter..

                  give me link with your .fla and i'll try to help you..

                  if you want..

                  • 6. Re: Fixing a game I'm working on.
                    mldb88 Level 2

                    Ok, going to try to do the boss spawn script from scratch. If that doesn't

                    work ill upload it and send

                    • 7. Re: Fixing a game I'm working on.
                      Radu Cristian Dimitrie Level 1

                      i copied the code but is hard for me without a bit of testing..

                      send me the .fla now if you want, i am starting college tomorrow, and i won't have much time..

                      would be glad to help

                      • 8. Re: Fixing a game I'm working on.
                        mldb88 Level 2

                        Don't worry about it, there's no rush really.  I think the problem was in

                        the way i nested them together.  Shouldbe able to fix it on my own with

                        little trouble.