home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / rocket_rush.swf / scripts / __Packages / AirSpace.as next >
Encoding:
Text File  |  2007-03-20  |  9.4 KB  |  315 lines

  1. class AirSpace extends MovieClip
  2. {
  3.    var my_music_vol;
  4.    var my_sfx_vol;
  5.    var master_vol;
  6.    var onEnterFrame;
  7.    var player;
  8.    var current_layout;
  9.    var player_clip;
  10.    var comments;
  11.    var enemies = [];
  12.    var enemy_types = [];
  13.    var enemy_num = 0;
  14.    var enemies_killed = 0;
  15.    var objects = [];
  16.    var clouds = [];
  17.    var layouts = {};
  18.    var timer = 0;
  19.    var timer_num = 0;
  20.    var time_count = 0;
  21.    var pickups = true;
  22.    var obstacle_types = [];
  23.    var particles = true;
  24.    var good = [2,40,80,120,160,200,2];
  25.    var bad = [240,280,320,360,400,440,240];
  26.    var last_comment = 0;
  27.    var count_to_comment = 200;
  28.    function AirSpace()
  29.    {
  30.       super();
  31.       EnemyAI.missiles_out = 0;
  32.       this.my_music_vol = new Sound(_root.music);
  33.       this.my_sfx_vol = new Sound(this);
  34.       this.master_vol = new Sound(_root);
  35.       this.onEnterFrame = function()
  36.       {
  37.          if(this.count_to_comment >= 0)
  38.          {
  39.             this.count_to_comment = this.count_to_comment - 1;
  40.          }
  41.          this.my_music_vol.setVolume(_global.music_vol * 20);
  42.          this.my_sfx_vol.setVolume(_global.sfx_vol * 20);
  43.          if(!_global.game_paused)
  44.          {
  45.             this.master_vol.setVolume(100);
  46.             if(_global.quality_set == "auto")
  47.             {
  48.                this.timer_num = getTimer() - this.timer;
  49.                this.timer = getTimer();
  50.                if(this.timer_num < 46)
  51.                {
  52.                   this.time_count = this.time_count + 1;
  53.                }
  54.                else if(this.timer_num > 52)
  55.                {
  56.                   this.time_count = this.time_count - 1;
  57.                }
  58.                else
  59.                {
  60.                   this.time_count = 0;
  61.                }
  62.                if(this.time_count > 5)
  63.                {
  64.                   if(this._quality == "MEDIUM")
  65.                   {
  66.                      this._quality = "HIGH";
  67.                   }
  68.                   else if(this._quality == "LOW")
  69.                   {
  70.                      this._quality = "MEDIUM";
  71.                   }
  72.                   this.time_count = 0;
  73.                }
  74.                else if(this.time_count < -5)
  75.                {
  76.                   if(this._quality == "HIGH")
  77.                   {
  78.                      this._quality = "MEDIUM";
  79.                   }
  80.                   else if(this._quality == "MEDIUM")
  81.                   {
  82.                      this._quality = "LOW";
  83.                   }
  84.                   this.time_count = 0;
  85.                }
  86.             }
  87.             if(this.pickups)
  88.             {
  89.                this.addPickups();
  90.                this.addObstacles();
  91.             }
  92.             this.addEnemies();
  93.             this.drawAirSpace();
  94.          }
  95.          else
  96.          {
  97.             this.master_vol.setVolume(30);
  98.          }
  99.       };
  100.    }
  101.    function drawAirSpace()
  102.    {
  103.       var _loc2_ = 0;
  104.       while(_loc2_ < this.enemies.length)
  105.       {
  106.          if(this.enemies[_loc2_]._name != undefined)
  107.          {
  108.             this.enemies[_loc2_].drawToScreen();
  109.          }
  110.          _loc2_ = _loc2_ + 1;
  111.       }
  112.       _loc2_ = 0;
  113.       while(_loc2_ < this.objects.length)
  114.       {
  115.          if(this.objects[_loc2_]._name != undefined)
  116.          {
  117.             this.objects[_loc2_].drawToScreen();
  118.          }
  119.          _loc2_ = _loc2_ + 1;
  120.       }
  121.       this.player.usePlayer();
  122.    }
  123.    function shiftToX(p_x)
  124.    {
  125.       var _loc2_ = 0;
  126.       while(_loc2_ < this.enemies.length)
  127.       {
  128.          this.enemies[_loc2_].posX += p_x;
  129.          _loc2_ = _loc2_ + 1;
  130.       }
  131.       _loc2_ = 0;
  132.       while(_loc2_ < this.objects.length)
  133.       {
  134.          this.objects[_loc2_].posX += p_x;
  135.          _loc2_ = _loc2_ + 1;
  136.       }
  137.       this.player.posX += p_x;
  138.       Position.camera_x += p_x;
  139.    }
  140.    function shiftToY(p_y)
  141.    {
  142.       var _loc2_ = 0;
  143.       while(_loc2_ < this.enemies.length)
  144.       {
  145.          this.enemies[_loc2_].posY += p_y;
  146.          _loc2_ = _loc2_ + 1;
  147.       }
  148.       _loc2_ = 0;
  149.       while(_loc2_ < this.objects.length)
  150.       {
  151.          this.objects[_loc2_].posY += p_y;
  152.          _loc2_ = _loc2_ + 1;
  153.       }
  154.       this.player.posY += p_y;
  155.       Position.camera_y += p_y;
  156.    }
  157.    function addLayout(p_layout_name, p_layout)
  158.    {
  159.       this.layouts[p_layout_name] = p_layout;
  160.    }
  161.    function setLayout(p_layout_name)
  162.    {
  163.       this.current_layout = this.layouts[p_layout_name];
  164.       this.emptyAirSpace();
  165.       this.populateAirSpace();
  166.       this.drawAirSpace();
  167.    }
  168.    function addObject(p_object)
  169.    {
  170.       this.objects.push(p_object);
  171.    }
  172.    function emptyAirSpace()
  173.    {
  174.       var _loc2_ = 0;
  175.       while(_loc2_ < this.enemies.length)
  176.       {
  177.          this.enemies[_loc2_].removeMovieClip();
  178.          _loc2_ = _loc2_ + 1;
  179.       }
  180.       this.enemies = [];
  181.    }
  182.    function populateAirSpace()
  183.    {
  184.       if(this.player_clip != this.current_layout.player_clip)
  185.       {
  186.          this.player_clip = this.current_layout.player_clip;
  187.          this.attachMovie(this.current_layout.player_clip,"player",this.getNextHighestDepth());
  188.       }
  189.       var _loc2_ = 0;
  190.       while(_loc2_ < this.current_layout.enemies.length)
  191.       {
  192.          var _loc3_ = this.current_layout.enemies[_loc2_];
  193.          if(_loc3_.pos_z < 3000)
  194.          {
  195.             this.enemy_num = this.enemy_num + 1;
  196.             this.enemies[_loc2_] = this.attachMovie(_loc3_.enemy_clip,"enemy" + _loc2_,this.getNextHighestDepth());
  197.             this.enemies[_loc2_].posX = _loc3_.pos_x;
  198.             this.enemies[_loc2_].posY = _loc3_.pos_y;
  199.             this.enemies[_loc2_].posZ = _loc3_.pos_z;
  200.          }
  201.          _loc2_ = _loc2_ + 1;
  202.       }
  203.       if(this.particles)
  204.       {
  205.          this.addParticles();
  206.       }
  207.    }
  208.    function addParticles()
  209.    {
  210.       var _loc3_ = 0;
  211.       while(_loc3_ < 20)
  212.       {
  213.          var _loc2_ = this.attachMovie("particle","particle" + _loc3_,this.getNextHighestDepth());
  214.          this.objects.push(_loc2_);
  215.          _loc2_.posX = this.player.posX + Math.round(Math.random() * 500) - 250;
  216.          _loc2_.posY = this.player.posY + Math.round(Math.random() * 500) - 250;
  217.          _loc2_.posZ = this.player.posZ + Math.round(Math.random() * 200);
  218.          _loc3_ = _loc3_ + 1;
  219.       }
  220.    }
  221.    function addPickups()
  222.    {
  223.       if(Math.random() < 0.015)
  224.       {
  225.          if(Math.random() > 0.4)
  226.          {
  227.             var _loc2_ = this.attachMovie("health","health" + this.objects.length,this.getNextHighestDepth());
  228.          }
  229.          else
  230.          {
  231.             _loc2_ = this.attachMovie("ammo","ammo" + this.objects.length,this.getNextHighestDepth());
  232.          }
  233.          this.objects.push(_loc2_);
  234.          _loc2_.posX = this.player.posX + Math.round(Math.random() * 1000) - 500;
  235.          _loc2_.posY = this.player.posY + Math.round(Math.random() * 1000) - 500;
  236.          _loc2_.posZ = this.player.posZ + 2000;
  237.       }
  238.    }
  239.    function addObstacles()
  240.    {
  241.       if(Math.random() < 0.009)
  242.       {
  243.          if(this.obstacle_types.length > 0)
  244.          {
  245.             if(Math.random() > 0.5)
  246.             {
  247.                var _loc2_ = this.attachMovie(this.obstacle_types[0],"obstacle" + this.objects.length,this.getNextHighestDepth());
  248.             }
  249.             else
  250.             {
  251.                _loc2_ = this.attachMovie(this.obstacle_types[1],"obstacle" + this.objects.length,this.getNextHighestDepth());
  252.             }
  253.          }
  254.          else
  255.          {
  256.             _loc2_ = this.attachMovie("rock_obstacle","obstacle" + this.objects.length,this.getNextHighestDepth());
  257.             _loc2_.gotoAndStop(Math.ceil(Math.random() * 6));
  258.          }
  259.          this.objects.push(_loc2_);
  260.          _loc2_.posX = this.player.posX + Math.round(Math.random() * 1000) - 500;
  261.          _loc2_.posY = this.player.posY + Math.round(Math.random() * 1000) - 500;
  262.          _loc2_.posZ = this.player.posZ + 2000;
  263.       }
  264.    }
  265.    function addEnemies()
  266.    {
  267.       var _loc2_ = 0;
  268.       while(_loc2_ < this.current_layout.enemies.length)
  269.       {
  270.          var _loc3_ = this.current_layout.enemies[_loc2_];
  271.          if(_loc3_.pos_z <= this.player.posZ + 3000 && _loc3_.pos_z > this.player.posZ + 2990)
  272.          {
  273.             this.enemies[_loc2_] = this.attachMovie(_loc3_.enemy_clip,"enemy" + _loc2_,this.getNextHighestDepth());
  274.             this.enemies[_loc2_].posX = this.player.posX + _loc3_.pos_x;
  275.             this.enemies[_loc2_].posY = this.player.posY + _loc3_.pos_y;
  276.             this.enemies[_loc2_].posZ = _loc3_.pos_z;
  277.             this.enemy_num = this.enemy_num + 1;
  278.          }
  279.          _loc2_ = _loc2_ + 1;
  280.       }
  281.    }
  282.    function goodComment()
  283.    {
  284.       if(this.comments._currentframe == 1 && this.count_to_comment <= 0)
  285.       {
  286.          if(Math.random() < 0.8)
  287.          {
  288.             var _loc2_ = Math.floor(Math.random() * 6);
  289.             if(_loc2_ == this.last_comment)
  290.             {
  291.                _loc2_ = _loc2_ + 1;
  292.             }
  293.             this.comments.gotoAndPlay(this.good[_loc2_]);
  294.             this.last_comment = _loc2_;
  295.          }
  296.       }
  297.    }
  298.    function badComment()
  299.    {
  300.       if(this.comments._currentframe == 1 && this.count_to_comment <= 0)
  301.       {
  302.          if(Math.random() < 0.8)
  303.          {
  304.             var _loc2_ = Math.floor(Math.random() * 6);
  305.             if(_loc2_ == this.last_comment)
  306.             {
  307.                _loc2_ = _loc2_ + 1;
  308.             }
  309.             this.comments.gotoAndPlay(this.bad[_loc2_]);
  310.             this.last_comment = _loc2_;
  311.          }
  312.       }
  313.    }
  314. }
  315.