home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Puzzle / crazycube.swf / scripts / frame_4 / DoAction.as
Encoding:
Text File  |  2006-06-13  |  4.5 KB  |  184 lines

  1. function initGames()
  2. {
  3.    this._visible = true;
  4.    oScene = new com.Scene(this.engine);
  5.    this.onMouseMove = function()
  6.    {
  7.       renderScene();
  8.    };
  9.    maxVolumeSound = 100;
  10.    soundBack = new Sound(sound_mc);
  11.    soundBack.attachSound("soundBackground");
  12.    soundBack.setVolume(0);
  13.    soundBack.start(0,9999);
  14.    soundBack.onSoundComplete = function()
  15.    {
  16.       soundBack.stop();
  17.       soundBack.start(0,9999);
  18.    };
  19.    sound_UP_DOWN(true);
  20. }
  21. function sound_UP_DOWN(flag)
  22. {
  23.    sound_mc.flag = flag;
  24.    sound_mc.onEnterFrame = function()
  25.    {
  26.       var _loc2_ = soundBack.getVolume();
  27.       if(this.flag)
  28.       {
  29.          _loc2_ += 2;
  30.          soundBack.setVolume(_loc2_);
  31.          if(_loc2_ >= maxVolumeSound)
  32.          {
  33.             soundBack.setVolume(maxVolumeSound);
  34.             delete this.enterFrame;
  35.          }
  36.       }
  37.       else
  38.       {
  39.          _loc2_ = _loc2_ - 1;
  40.          soundBack.setVolume(_loc2_);
  41.          if(_loc2_ <= 0)
  42.          {
  43.             soundBack.setVolume(0);
  44.             delete this.enterFrame;
  45.          }
  46.       }
  47.    };
  48. }
  49. function startNextLevel()
  50. {
  51.    _root.level_complete = false;
  52.    this.onMouseMove = function()
  53.    {
  54.       renderScene();
  55.    };
  56.    this.engine._alpha = 0;
  57.    this.engine.useHandCursor = false;
  58.    delete this.engine.onPress;
  59.    oScene.createEngine(level);
  60.    maxLevel = oScene.maxLevel;
  61.    renderScene();
  62.    this.playGame.level_str = "Level: " + level + " of " + maxLevel;
  63.    bonus = level * 100;
  64.    timer = getTimer();
  65.    this.playGame.bonus = bonus;
  66.    this.engine.onEnterFrame = function()
  67.    {
  68.       this._alpha += 5;
  69.       if(this._alpha > 100)
  70.       {
  71.          this._alpha = 100;
  72.          delete this.onEnterFrame;
  73.          this.onEnterFrame = function()
  74.          {
  75.             var _loc2_ = Math.floor((getTimer() - this._parent.timer) / 1000);
  76.             this._parent.playGame.bonus = this._parent.bonus - this._parent.level * _loc2_;
  77.             if(this._parent.playGame.bonus < 0)
  78.             {
  79.                this._parent.playGame.bonus = 0;
  80.             }
  81.          };
  82.       }
  83.    };
  84. }
  85. function endLevel()
  86. {
  87.    delete this.onMouseMove;
  88.    this.engine.onPress = null;
  89.    this.engine.cub_mc_1._visible = this.engine.cub_mc_2._visible = this.engine.cub_mc_3._visible = false;
  90.    var _loc7_ = 1000;
  91.    for(var _loc8_ in this.engine)
  92.    {
  93.       var _loc3_ = this.engine[_loc8_];
  94.       var _loc4_ = _loc3_.getBounds(_loc3_._parent);
  95.       var _loc6_ = (_loc4_.xMin + _loc4_.xMax) / 2;
  96.       var _loc5_ = (_loc4_.yMin + _loc4_.yMax) / 2;
  97.       if(_loc4_.yMin < _loc7_)
  98.       {
  99.          _loc7_ = _loc4_.yMin;
  100.          _root.min_y_cell = _loc3_;
  101.       }
  102.       _loc3_.f_dx = _loc6_ / 30;
  103.       _loc3_.f_dy = - Math.abs(_loc5_ / 15) - Math.random() * 5;
  104.       _loc3_.fddy = 1.1 + Math.random() * 0.2 - 0.1;
  105.    }
  106.    _root.level_complete = true;
  107.    _root.score += level * 100 + this.playGame.bonus;
  108.    this.engine.onEnterFrame = function()
  109.    {
  110.       for(var _loc4_ in this)
  111.       {
  112.          var _loc3_ = this[_loc4_];
  113.          _loc3_._x += _loc3_.f_dx;
  114.          _loc3_._y += _loc3_.f_dy;
  115.          _loc3_._rotation += _loc3_.f_dx / 5;
  116.          _loc3_.f_dy += _loc3_.fddy;
  117.          if(_root.min_y_cell._y > 790)
  118.          {
  119.             this._alpha = 0;
  120.             delete this.onEnterFrame;
  121.             if(this.flag)
  122.             {
  123.                startNextLevel();
  124.             }
  125.             else
  126.             {
  127.                youWin();
  128.             }
  129.          }
  130.       }
  131.    };
  132.    level++;
  133.    if(level > maxLevel)
  134.    {
  135.       level = 1;
  136.       this.engine.flag = false;
  137.       menu.dataSave.data.level = undefined;
  138.       menu.dataSave.flush();
  139.    }
  140.    else
  141.    {
  142.       this.engine.flag = true;
  143.       if(menu.dataSave.data.level < level || menu.dataSave.data.level == undefined)
  144.       {
  145.          menu.dataSave.data.level = level;
  146.       }
  147.    }
  148. }
  149. function youWin()
  150. {
  151.    this.menu.youWin_mc._visible = true;
  152.    this.playGame.endGames();
  153. }
  154. function renderScene()
  155. {
  156.    var _loc2_ = -135 + (- this.engine._ymouse) / dec;
  157.    if(_loc2_ > -90)
  158.    {
  159.       _loc2_ = -90;
  160.    }
  161.    else if(_loc2_ < -180)
  162.    {
  163.       _loc2_ = -180;
  164.    }
  165.    var _loc3_ = -135 + (- this.engine._xmouse) / dec;
  166.    if(_loc3_ > -90)
  167.    {
  168.       _loc3_ = -90;
  169.    }
  170.    else if(_loc3_ < -180)
  171.    {
  172.       _loc3_ = -180;
  173.    }
  174.    oScene.render(_loc2_,_loc3_);
  175. }
  176. stop();
  177. Stage.scaleMode = "noScale";
  178. var maxLevel;
  179. var dec = 3.5;
  180. var level = 1;
  181. this._visible = false;
  182. initGames();
  183. stop();
  184.