home *** CD-ROM | disk | FTP | other *** search
/ Champak 112 / jogo-disk-112.iso / Games / jmonkey.swf / scripts / frame_1 / DoAction.as
Text File  |  2010-07-14  |  17KB  |  529 lines

  1. if(!§§pop())
  2. {
  3.    _global.setDelay = function()
  4.    {
  5.       var a = arguments;
  6.       var obj = a[0];
  7.       var fnc = a[1];
  8.       var delay = a[2];
  9.       if(typeof obj == "function" && typeof fnc == "number")
  10.       {
  11.          delay = fnc;
  12.          fnc = obj;
  13.          obj = null;
  14.          var cut = 2;
  15.       }
  16.       else
  17.       {
  18.          if(!(obj instanceof Object && typeof (fnc = obj[fnc]) == "function" && typeof delay == "number"))
  19.          {
  20.             trace("Warning : [setDelay] invalid parameter types.");
  21.             return false;
  22.          }
  23.          var cut = 3;
  24.       }
  25.       a.splice(0,cut);
  26.       var f = function(array)
  27.       {
  28.          fnc.apply(obj,array);
  29.          clearInterval(id);
  30.       };
  31.       var id = setInterval(f,delay,a);
  32.       return id;
  33.    };
  34.    _global.EF = {Old:{},OnEF:{},SetOnEF:{}};
  35.    _global.EF.traceTable = function(t)
  36.    {
  37.       var i = 0;
  38.       while(i <= t.length - 1)
  39.       {
  40.          trace(t[i].toString());
  41.          i++;
  42.       }
  43.    };
  44.    _global.EF.Old.oldrandom = _global.random;
  45.    _global.random = function(intval)
  46.    {
  47.       var a = Math.floor(Math.random());
  48.       return a;
  49.    };
  50.    ASSetPropFlags(_global,["setDelay","EF"],1);
  51.    SoundMaster = function(base, n)
  52.    {
  53.       this.base = base;
  54.       this.sound_array = [];
  55.       if(n > 0)
  56.       {
  57.          this.createAllSound(n);
  58.       }
  59.    };
  60.    sp = SoundMaster.prototype;
  61.    sp.createAllSound = function(n)
  62.    {
  63.       var i = 0;
  64.       while(i <= n - 1)
  65.       {
  66.          this.sound_array[i] = new Sound(createEmptyMovieClip("_soundmaster" + (this.base + i),this.base + i));
  67.          i++;
  68.       }
  69.    };
  70.    sp.attachAllSound = function()
  71.    {
  72.       var n = arguments.length - 1;
  73.       var i = 0;
  74.       while(i <= n)
  75.       {
  76.          this.sound_array[i].attachSound(arguments[i]);
  77.          i++;
  78.       }
  79.    };
  80.    sp.setAllVolume = function()
  81.    {
  82.       var n = arguments.length - 1;
  83.       var i = 0;
  84.       while(i <= n)
  85.       {
  86.          this.sound_array[i].setVolume(arguments[i]);
  87.          i++;
  88.       }
  89.    };
  90.    sp.setAllPan = function()
  91.    {
  92.       var n = arguments.length - 1;
  93.       var i = 0;
  94.       while(i <= n)
  95.       {
  96.          this.sound_array[i].setPan(arguments[i]);
  97.          i++;
  98.       }
  99.    };
  100.    sp.setVolume = function(n, vol)
  101.    {
  102.       var snd = this.sound_array[n];
  103.       if(vol != undefined)
  104.       {
  105.          snd.setVolume(vol);
  106.       }
  107.    };
  108.    sp.setPan = function(n, pan)
  109.    {
  110.       var snd = this.sound_array[n];
  111.       if(pan != undefined)
  112.       {
  113.          snd.setPan(pan);
  114.       }
  115.    };
  116.    sp.start = function(n, offset, loop, vol, pan)
  117.    {
  118.       var snd = this.sound_array[n];
  119.       if(vol > 0)
  120.       {
  121.          snd.setVolume(vol);
  122.          if(pan != undefined)
  123.          {
  124.             snd.setPan(pan);
  125.          }
  126.       }
  127.       snd.start(offset,loop);
  128.    };
  129.    sp.stop = function(n)
  130.    {
  131.       this.sound_array[n].stop();
  132.    };
  133.    sp.stopAllSounds = function()
  134.    {
  135.       var i = 0;
  136.       while(i <= this.sound_array.length - 1)
  137.       {
  138.          this.sound_array[i].stop();
  139.          i++;
  140.       }
  141.    };
  142.    delete sp;
  143.    stonePos = [4,4,5,5,4,4,5,5,4,6,6,4,3,4,6,6,6,6,5,2,6,5,6,4,4,7,5,5,2,4,3,4,5,5,4,4,5,5,5,4,5,5,5,5,5,4,4,5,7,2,3,5,4,3,5,5,5,6,6,2,5,6,7,4,5,5,4,5,5,3,7,5,6,6,3,6,7,6,5,6,5,5,5,4,4,8,7,7,5,6,7,6,4,6,3,5,3,6,2,5,6,5,6,5,7,4,5,3,8,7,2,6,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,5,0,6,0,6,-5,6,0,5,0,5,0,6,0,5,0,5,0];
  145.    moveLim = [18,16,46,26,38,39,36,37,26,38,17,27,16,18,18,18,37,47,28,18,18,19,28,29,38,38,47,36,16,27,16,39,46,39,36,27,48,39,38,18,49,46,16,39,47,36,26,18,28,17,17,37,19,26,38,46,27,38,28,19,26,27,39,17,28,19,19,47,29,16,38,28,47,37,17,17,39,47,18,39,48,29,28,18,37,49,39,49,19,48,19,27,18,37,26,19,18,19,16,29,18,46,19,47,48,27,37,26,29,38,18,29,18,28,46,17,27,37,37,37,17,36,18,29,28,27,28,38,38,27,19,38,37,19,47,19,18,28,28,36,49,29,38,38,17,19,37,29,37,48,37,37,19,37,16,36,28,39,29,17,37,49,39,39,17,37,46,49,48,37,18,28,37,27,26,49,19,29,29,37,18,16,27,17,27,37,49,48,39,37,28,37,26,18,47,18,28,19,37,18,29,28,28,49,39,38,28,48,19,49,26,47,29,46,37,37,36,18,49,38,27,38,27,29,17,28,27,38,26,16,19,39,46,29,38,38,48,19,38,17,29,29,49,18,26,18,36,46,28,19,46,18,19,47,28,28,48,48,48,38,17,18,26,46,38,17,28,16,19,49,36,28,16,29,48,27,27,47,16,26,39,48,17,28,26,26,36,16,28,47,29,37,19,27,37,48,37,46,39,28];
  146.    _global.IV = {GAMEID:"MONKEYJUMP",CEIL:0,FLOOR:0,LEFT_SIDE:0,RIGHT_SIDE:0,STONE_POS_UNIT:0,STEP_HEIGHT:0,STEPS:3,JUMP_SPEED:33,ERROR_LIMIT:15,GRAVITY:3,MONKEYS_LIFE:5,SCORE_STEP:50,SCORE_LEVEL:150,SCORE_COMBO:150,COMBO_LIMIT:1200,LAND_TIME:600,COMBO_BONUS:6};
  147.    init = function()
  148.    {
  149.       ServerConnection.onGameStart();
  150.       with(IV)
  151.       {
  152.          CEIL = stone_guide._y;
  153.          FLOOR = stone_guide._y + stone_guide._height;
  154.          LEFT_SIDE = stone_guide._x;
  155.          RIGHT_SIDE = stone_guide._x + stone_guide._width;
  156.          STONE_POS_UNIT = stone_guide._width / 8;
  157.          STEP_HEIGHT = (FLOOR - CEIL) / STEPS;
  158.       }
  159.       _global.GAME = {score:0,level:0,step:0,combo:1,comboTimer:getTimer()};
  160.       GAME.sounds = new SoundMaster(1011,10);
  161.       GAME.sounds.attachAllSound("background","gameover","jump1","success","fail","jump2","jump3","jump4","lifeup","combo");
  162.       GAME.sounds.setVolume(0,50);
  163.       gameover_mc._visible = false;
  164.       gameover_mc.stop();
  165.       combo_mc._visible = false;
  166.       comboBonus_mc.bonus = 0;
  167.       comboBonus_mc.gotoAndStop(1);
  168.       makeLevel(0);
  169.       setLife(IV.MONKEYS_LIFE);
  170.       setScore(0);
  171.       setCombo(0);
  172.       setFloorNum(1);
  173.       GAME.sounds.start(0,0,1000);
  174.       stone_mc.startMove = function()
  175.       {
  176.          this.onEnterFrame = this._moveStones;
  177.       };
  178.       stone_mc.stopMove = function()
  179.       {
  180.          delete this.onEnterFrame;
  181.       };
  182.       stone_mc.getIndex = function(n)
  183.       {
  184.          return GAME.level * IV.STEPS + n;
  185.       };
  186.       stone_mc._moveLevel = function()
  187.       {
  188.          this._y += this.spd;
  189.          monkey_mc._y += this.spd;
  190.          tree_mc._y += this.spd * 0.5;
  191.          if(tree_mc._y >= 447)
  192.          {
  193.             tree_mc._y -= 447;
  194.          }
  195.          if(Math.abs(this._y) >= IV.STEPS * IV.STEP_HEIGHT)
  196.          {
  197.             this._y = 0;
  198.             var i = 0;
  199.             while(i <= IV.STEPS)
  200.             {
  201.                this["stone" + this.getIndex(i)]._y = IV.FLOOR - i * IV.STEP_HEIGHT;
  202.                i++;
  203.             }
  204.             var mc;
  205.             var idx;
  206.             var i = 0;
  207.             while(i <= IV.STEPS - 1)
  208.             {
  209.                idx = stone_mc.getIndex(i);
  210.                mc = stone_mc["stone" + (idx + IV.STEPS + 1)] = stone_mc["stone" + (idx - IV.STEPS)];
  211.                idx += IV.STEPS + 1;
  212.                mc._x = IV.LEFT_SIDE + (stonePos[idx] - 1) * IV.STONE_POS_UNIT;
  213.                mc._y = IV.FLOOR - (IV.STEPS + i + 1) * IV.STEP_HEIGHT;
  214.                mc.spd = stoneSpd[idx];
  215.                mc.leftLim = IV.LEFT_SIDE + (Number(String(moveLim[idx]).charAt(0)) - 1) * IV.STONE_POS_UNIT;
  216.                mc.rightLim = IV.LEFT_SIDE + (Number(String(moveLim[idx]).charAt(1)) - 1) * IV.STONE_POS_UNIT;
  217.                if(i > IV.STEPS)
  218.                {
  219.                   mc._visible = false;
  220.                }
  221.                i++;
  222.             }
  223.             this.onEnterFrame = this._moveStones;
  224.             _quality = "HIGH";
  225.             snow_compo.onEnterFrame = snow_compo.letSnow_onef;
  226.             monkey_mc.enabled = true;
  227.             monkey_mc.land = true;
  228.          }
  229.       };
  230.       stone_mc._moveStones = function()
  231.       {
  232.          var mc;
  233.          var i = 0;
  234.          while(i <= IV.STEPS)
  235.          {
  236.             mc = this["stone" + this.getIndex(i)];
  237.             mc._x += mc.spd;
  238.             if(mc._x <= mc.leftLim || mc._x >= mc.rightLim)
  239.             {
  240.                mc.spd *= -1;
  241.             }
  242.             i++;
  243.          }
  244.       };
  245.       stone_mc.startMove();
  246.       monkey_mc.xpos = 0;
  247.       monkey_mc.ypos = 0;
  248.       monkey_mc._y = IV.FLOOR;
  249.       monkey_mc.land = true;
  250.       monkey_mc.enabled = true;
  251.       monkey_mc.gotoAndPlay("stand");
  252.       monkey_mc.onPress = function()
  253.       {
  254.          if(this.enabled)
  255.          {
  256.             this.ypos = this._y;
  257.             this.spd = IV.JUMP_SPEED;
  258.             this.enabled = false;
  259.             this.land = false;
  260.             this.xspd = stone_mc["stone" + (GAME.level * IV.STEPS + GAME.step)].spd;
  261.             this.gotoAndPlay("jump");
  262.             this.cryhead_mc._visible = false;
  263.             if(getTimer() - GAME.comboTimer <= IV.COMBO_LIMIT - IV.LAND_TIME)
  264.             {
  265.                GAME.sounds.start(GAME.combo + 4,0,1);
  266.             }
  267.             else
  268.             {
  269.                GAME.sounds.start(2,0,1);
  270.             }
  271.             monkey_mc.onEnterFrame = function()
  272.             {
  273.                this._x += this.xspd;
  274.                this._y -= this.spd -= IV.GRAVITY;
  275.                if(this.spd <= 0 && this._y >= this.ypos - IV.STEP_HEIGHT)
  276.                {
  277.                   this.xspd = 0;
  278.                   delete this.onEnterFrame;
  279.                   this.onLand();
  280.                }
  281.             };
  282.          }
  283.       };
  284.       monkey_mc.onKeyDown = function()
  285.       {
  286.          if(Key.getCode() == 13 || Key.getCode() == 32)
  287.          {
  288.             this.onPress();
  289.          }
  290.       };
  291.       Key.addListener(monkey_mc);
  292.       monkey_mc.onLand = function()
  293.       {
  294.          GAME.step = GAME.step + 1;
  295.          var mc = stone_mc["stone" + (GAME.level * IV.STEPS + GAME.step)];
  296.          if(Math.abs(mc._x - this._x) <= IV.ERROR_LIMIT)
  297.          {
  298.             if(getTimer() - GAME.comboTimer <= IV.COMBO_LIMIT)
  299.             {
  300.                setCombo(1);
  301.                banana_mc._x = this._x + 15;
  302.                banana_mc._y = this._y;
  303.                banana_mc.onEnterFrame = banana_onEnterFrame;
  304.             }
  305.             else
  306.             {
  307.                GAME.combo = 1;
  308.             }
  309.             GAME.comboTimer = getTimer();
  310.             setFloorNum(GAME.level * IV.STEPS + GAME.step + 1);
  311.             GAME.sounds.start(3,0,1);
  312.             setScore(IV.SCORE_STEP);
  313.             this.gotoAndPlay("stand");
  314.             this._y = this.ypos - IV.STEP_HEIGHT;
  315.             this.xpos = this._x - mc._x;
  316.             this.enabled = true;
  317.             this.land = true;
  318.             mc.play();
  319.          }
  320.          else
  321.          {
  322.             GAME.sounds.stop(0);
  323.             GAME.sounds.start(4,0,1);
  324.             setLife(-1);
  325.             GAME.step--;
  326.             this.ypos = IV.FLOOR - GAME.step * IV.STEP_HEIGHT;
  327.             this.startDrop = function()
  328.             {
  329.                this.cryhead_mc._visible = true;
  330.                this.onEnterFrame = function()
  331.                {
  332.                   this._y -= this.spd -= IV.GRAVITY;
  333.                   if(this._y >= 550)
  334.                   {
  335.                      delete this.onEnterFrame;
  336.                      if(GAME.life < 0)
  337.                      {
  338.                         onGameOver();
  339.                      }
  340.                      else
  341.                      {
  342.                         GAME.sounds.start(0,0,1000);
  343.                         this._y = this.ypos;
  344.                         this.enabled = true;
  345.                         this.land = true;
  346.                         this.gotoAndPlay("standup");
  347.                      }
  348.                   }
  349.                };
  350.             };
  351.             if(GAME.life < 0)
  352.             {
  353.                this.cryhead_mc._visible = false;
  354.                setDelay(this,"startDrop",800);
  355.                this.gotoAndPlay("fail");
  356.             }
  357.             else
  358.             {
  359.                this.startDrop();
  360.             }
  361.          }
  362.       };
  363.       onEnterFrame = function()
  364.       {
  365.          if(GAME.life >= 0 && monkey_mc.land)
  366.          {
  367.             monkey_mc._x = monkey_mc.xpos + stone_mc["stone" + (GAME.level * IV.STEPS + GAME.step)]._x;
  368.          }
  369.          if(Math.abs(monkey_mc.xpos) > 0)
  370.          {
  371.             monkey_mc.xpos *= 0.5;
  372.          }
  373.          if(GAME.step >= IV.STEPS && this._y < IV.STEP_HEIGHT * 4)
  374.          {
  375.             GAME.step = 0;
  376.             GAME.level = GAME.level + 1;
  377.             nextLevel();
  378.          }
  379.       };
  380.    };
  381.    makeLevel = function(n)
  382.    {
  383.       var mc;
  384.       var idx;
  385.       var i = 0;
  386.       while(i <= IV.STEPS * 2)
  387.       {
  388.          idx = n * IV.STEPS + i;
  389.          mc = stone_mc.attachMovie("stone_symbol","stone" + idx,idx);
  390.          mc._x = IV.LEFT_SIDE + (stonePos[idx] - 1) * IV.STONE_POS_UNIT;
  391.          mc._y = IV.FLOOR - i * IV.STEP_HEIGHT;
  392.          mc.spd = stoneSpd[idx];
  393.          mc.leftLim = IV.LEFT_SIDE + (Number(String(moveLim[idx]).charAt(0)) - 1) * IV.STONE_POS_UNIT;
  394.          mc.rightLim = IV.LEFT_SIDE + (Number(String(moveLim[idx]).charAt(1)) - 1) * IV.STONE_POS_UNIT;
  395.          if(i > IV.STEPS)
  396.          {
  397.             mc._visible = false;
  398.          }
  399.          i++;
  400.       }
  401.    };
  402.    nextLevel = function()
  403.    {
  404.       setScore(IV.SCORE_LEVEL);
  405.       var mc;
  406.       for(var i in stone_mc)
  407.       {
  408.          mc = stone_mc[i];
  409.          mc._visible = true;
  410.       }
  411.       monkey_mc.enabled = false;
  412.       monkey_mc.land = true;
  413.       stone_mc.spd = 20;
  414.       stone_mc.onEnterFrame = stone_mc._moveLevel;
  415.       _quality = "MEDIUM";
  416.       delete snow_compo.onEnterFrame;
  417.    };
  418.    setLife = function(n)
  419.    {
  420.       GAME.life += n;
  421.       raccoon_mc.gotoAndPlay("life");
  422.    };
  423.    setScore = function(n)
  424.    {
  425.       GAME.score += n;
  426.       score_mc.score_txt.text = GAME.score;
  427.    };
  428.    setCombo = function(n)
  429.    {
  430.       GAME.combo += n;
  431.       if(GAME.combo > 1)
  432.       {
  433.          setScore(IV.SCORE_COMBO);
  434.          comboBonus_mc.bonus += n;
  435.          if(comboBonus_mc.bonus >= IV.COMBO_BONUS)
  436.          {
  437.             comboBonus_mc.bonus -= IV.COMBO_BONUS;
  438.             setLife(1);
  439.             GAME.sounds.start(8,0,1);
  440.          }
  441.          else
  442.          {
  443.             GAME.sounds.start(9,0,1);
  444.          }
  445.          combo_mc._visible = true;
  446.          combo_mc.gotoAndPlay(1);
  447.          combo_mc.combo = GAME.combo;
  448.       }
  449.       else
  450.       {
  451.          comboBonus_mc.gotoAndStop(1);
  452.       }
  453.    };
  454.    setFloorNum = function(n)
  455.    {
  456.       var f3 = floor3_mc._currentframe - 1;
  457.       var f2 = floor2_mc._currentframe - 1;
  458.       var f1 = floor1_mc._currentframe - 1;
  459.       var n3 = Math.floor(n / 100);
  460.       var n2 = Math.floor((n - n3 * 100) / 10);
  461.       var n1 = n % 10;
  462.       if(f3 != n3)
  463.       {
  464.          floorBird3_mc.play();
  465.       }
  466.       if(f2 != n2)
  467.       {
  468.          floorBird2_mc.play();
  469.       }
  470.       if(f1 != n1)
  471.       {
  472.          floorBird1_mc.play();
  473.       }
  474.       floor3_mc.gotoAndStop(n3 + 1);
  475.       floor2_mc.gotoAndStop(n2 + 1);
  476.       floor1_mc.gotoAndStop(n1 + 1);
  477.    };
  478.    onGameOver = function()
  479.    {
  480.       GAME.sounds.start(1,0,1);
  481.       gameover_mc._visible = true;
  482.       gameover_mc.gotoAndPlay(1);
  483.    };
  484.    banana_onEnterFrame = function()
  485.    {
  486.       var xp = comboBonus_mc._x + (comboBonus_mc.bonus - 1) * 20;
  487.       this._x += (xp - this._x) * 0.3;
  488.       this._y += (comboBonus_mc._y - this._y) * 0.3;
  489.       if(Math.abs(xp - this._x) <= 1)
  490.       {
  491.          this._x = -100;
  492.          if(comboBonus_mc.bonus == 0)
  493.          {
  494.             comboBonus_mc.gotoAndPlay("life");
  495.          }
  496.          else
  497.          {
  498.             comboBonus_mc.gotoAndStop(comboBonus_mc.bonus + 1);
  499.          }
  500.          delete this.onEnterFrame;
  501.       }
  502.    };
  503.    help_mc._visible = false;
  504.    start_btn.onRelease = function()
  505.    {
  506.       gotoAndPlay(1);
  507.    };
  508.    help_btn.onRelease = function()
  509.    {
  510.       start_btn.enabled = false;
  511.       help_btn.enabled = false;
  512.       rank_btn.enabled = false;
  513.       help_mc._visible = true;
  514.       help_mc.start_btn.onRelease = start_btn.onRelease;
  515.    };
  516.    if(ServerConnection.getRankEnabled())
  517.    {
  518.       rank_btn.onRelease = function()
  519.       {
  520.          ServerConnection.onGameRankRequest();
  521.       };
  522.    }
  523.    else
  524.    {
  525.       rank_btn._visible = false;
  526.    }
  527.    stop();
  528. }
  529.