home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / VenusMission.swf / scripts / __Packages / Venus_game.as < prev   
Encoding:
Text File  |  2008-09-23  |  17.9 KB  |  507 lines

  1. class Venus_game extends games.Game
  2. {
  3.    var gameMC;
  4.    var timer;
  5.    var manager;
  6.    var fader;
  7.    var _scoreValue;
  8.    var score;
  9.    var jumperMC;
  10.    var fuelMC;
  11.    var bonus;
  12.    var noColorTransform;
  13.    var itemsArray;
  14.    var itemsByClassArray;
  15.    var objectsscene;
  16.    var _playerOutBounds;
  17.    var _playerInBounds;
  18.    var foregroundscene;
  19.    var backgroundscene;
  20.    var _endLevel = false;
  21.    var _isPaused = false;
  22.    var _bonusValue = 0;
  23.    var _bonusInUse = false;
  24.    var bonusMax = 8;
  25.    var bonus_Values = [1,2,4];
  26.    var bonus_addString = "";
  27.    var bonus_stepdisplay = 10;
  28.    var _superBonusValue = 0;
  29.    var _speedValue = 0;
  30.    var _speedRate = 0;
  31.    var _distance = 0;
  32.    var _lastdistance = 0;
  33.    var _lastitemplace = 0;
  34.    var startSpeed = 50;
  35.    var speedMin = 3;
  36.    var speedMax = 50;
  37.    var rotatMin = 5;
  38.    var prevspeed = 0;
  39.    var resistance = 0.99;
  40.    var minItemDistance = 250;
  41.    var moveByY = 0;
  42.    var multipleY = 8;
  43.    var moveByX = 0;
  44.    var multipleX = 5;
  45.    var moveByHitValue = 0;
  46.    var moveByHitStepValue = 0;
  47.    var moveByHitStep = 1;
  48.    var moveByHitMax = 10;
  49.    var rotateByHitValue = 0;
  50.    var rotateHitStepValue = 0;
  51.    var rotateByHitStep = 2;
  52.    var rotateByHitMax = 52.5;
  53.    var time_endLevelPause = 1500;
  54.    var jumper_jetFrames = 10;
  55.    var jumper_jetEndFrame = 1;
  56.    var jumper_enabledEvents = true;
  57.    var setJumper = null;
  58.    var onBonusUse = null;
  59.    var onKeysMove = null;
  60.    function Venus_game(MC, w, h, managerinstance)
  61.    {
  62.       super();
  63.       this.gameMC = MC;
  64.       this.timer = system.Timer.getInstance(this.gameMC);
  65.       this.manager = managerinstance;
  66.       this.fader = new effects.Fader(this.gameMC);
  67.       this.manager.addListener(this);
  68.       this.gameArea = {_width:w,_height:h};
  69.       this._speedValue = 0;
  70.       this._scoreValue = 0;
  71.       this.score = new games.Score(this,this.gameMC.scoreMC,1010);
  72.       this.score.resetTo(0);
  73.       this.jumperMC = this.gameMC.jumperMC;
  74.       this.jumperMC.swapDepths(111);
  75.       this.jumperMC.gotoAndStop("fly");
  76.       this.jumperMC._x = 212;
  77.       this.jumperMC._y = 221;
  78.       this.jumperMC.man._rotation = 180;
  79.       this.jumperMC.man.jet.gotoAndStop("minimum");
  80.       this.jumperMC.man.jet.flame._visible = false;
  81.       this.jumperMC.man.jet.flame_shadow._visible = false;
  82.       this.jumper_jetEndFrame = this.jumperMC.man.jet._currentframe;
  83.       this.fuelMC = this.gameMC.fuelMC;
  84.       this.fuelMC.swapDepths(1001);
  85.       this.fuelMC.item.gotoAndStop("fuel");
  86.       this.fuelMC.energyline.bar._y = - this.fuelMC.energyline.bar._height;
  87.       this.gameMC.bonusMC.swapDepths(1002);
  88.       this.gameMC.bonusMC.item.gotoAndStop("bonus");
  89.       this.gameMC.bonusMC.energyline.bar._visible = false;
  90.       this.bonus = new games.Bonus(this,this.gameMC.bonusMC.item);
  91.       this.bonus.resetTo("0");
  92.       this.setItems();
  93.       this.noColorTransform = new flash.geom.ColorTransform();
  94.       this.makeScene(this.gameMC);
  95.    }
  96.    function setItems()
  97.    {
  98.       this.itemsArray = new Array();
  99.       this.itemsByClassArray = new Array();
  100.       this.itemsArray[0] = {classname:"item",sndname:"snd_item_item",nextpoint:500,dist:1000,pp:100,superbonus:1,rotation:0,space:200,fuel:0,bonus:0,upper:false};
  101.       this.itemsArray[1] = {classname:"smallfuel",sndname:"snd_item_smallfuel",nextpoint:500,dist:2250,pp:50,superbonus:0,rotation:0,space:200,fuel:0.25,bonus:0,upper:false};
  102.       this.itemsArray[2] = {classname:"bigfuel",sndname:"snd_item_bigfuel",nextpoint:4500,dist:4500,pp:100,superbonus:1,rotation:0,space:200,fuel:1,bonus:0,upper:false};
  103.       this.itemsArray[3] = {classname:"atom",sndname:"snd_item_atom",nextpoint:6000,dist:11000,pp:50,superbonus:0,rotation:0,space:200,fuel:0,bonus:2,upper:false};
  104.       this.itemsArray[4] = {classname:"atom2",sndname:"snd_item_atom",nextpoint:11000,dist:11000,pp:50,superbonus:0,rotation:0,space:0,fuel:0,bonus:2,upper:true};
  105.       this.itemsArray[5] = {classname:"laser",sndname:"snd_enemy_laser",nextpoint:4000,dist:4000,pp:0,superbonus:-10,rotation:0,space:0,fuel:0,bonus:-0.5,upper:true,animation:"stroke"};
  106.       this.itemsArray[6] = {classname:"redstar",sndname:"snd_enemy_enemy",nextpoint:6000,dist:6000,pp:0,superbonus:-10,rotation:-1,space:200,fuel:-0.25,bonus:0,upper:false};
  107.       this.itemsArray[7] = {classname:"enemy",sndname:"snd_enemy_enemy",nextpoint:9000,dist:9000,pp:0,superbonus:-10,rotation:1,space:200,fuel:-0.25,bonus:0,upper:false};
  108.       for(var pos in this.itemsArray)
  109.       {
  110.          this.itemsByClassArray[this.itemsArray[pos].classname] = this.itemsArray[pos];
  111.       }
  112.    }
  113.    function addBonusValue(val)
  114.    {
  115.       this._bonusValue += !(val > 0 && this._bonusValue == 0) ? this._bonusValue * val : 1;
  116.       if(this._bonusValue > this.bonusMax)
  117.       {
  118.          this._bonusValue = this.bonusMax;
  119.       }
  120.       else if(this._bonusValue < 0)
  121.       {
  122.          this._bonusValue = 0;
  123.       }
  124.       this.bonus.setValue(this._bonusValue);
  125.    }
  126.    function addFuelValue(fuel)
  127.    {
  128.       this._speedValue += fuel * this.speedMax;
  129.       if(this._speedValue > this.speedMax)
  130.       {
  131.          this._speedValue = this.speedMax;
  132.       }
  133.       else if(this._speedValue < 0)
  134.       {
  135.          this._speedValue = 0;
  136.       }
  137.    }
  138.    function checkObjectsCollision()
  139.    {
  140.       if(this._bonusInUse == true)
  141.       {
  142.          return undefined;
  143.       }
  144.       var objects = this.objectsscene.getTable();
  145.       var t_length = objects.length;
  146.       var pos;
  147.       var typeobject;
  148.       var hitMC;
  149.       var i = 0;
  150.       while(i < t_length)
  151.       {
  152.          pos = objects[i];
  153.          if(pos.collected != true)
  154.          {
  155.             hitMC = pos.MC.p_hit != undefined ? pos.MC.p_hit : pos.MC;
  156.             if(this.jumperMC.hitTest(hitMC))
  157.             {
  158.                pos.MC.gotoAndPlay("collect");
  159.                pos.collected = true;
  160.                typeobject = this.itemsByClassArray[pos.type];
  161.                break;
  162.             }
  163.          }
  164.          i++;
  165.       }
  166.       if(typeobject == undefined)
  167.       {
  168.          return undefined;
  169.       }
  170.       this.manager.playFX(typeobject.sndname);
  171.       this._scoreValue += typeobject.pp;
  172.       this.score.setValue(this._scoreValue);
  173.       if(typeobject.bonus != 0)
  174.       {
  175.          this.addBonusValue(typeobject.bonus);
  176.       }
  177.       if(typeobject.fuel != 0)
  178.       {
  179.          this.addFuelValue(typeobject.fuel);
  180.       }
  181.       if(typeobject.rotation != 0)
  182.       {
  183.          this.setJumperRotation(typeobject.rotation);
  184.       }
  185.       if(typeobject.animation != undefined)
  186.       {
  187.          this.setJumper = null;
  188.          this.jumperMC.gotoAndPlay(typeobject.animation);
  189.          this.jumper_enabledEvents = false;
  190.          this.jumperMC.onJumperStroke = system.Delegate.create(this,this.backJumperToAction);
  191.       }
  192.    }
  193.    function backJumperToAction()
  194.    {
  195.       this.jumperMC.gotoAndStop("fly");
  196.       this.jumperMC.man.jet.flame._visible = true;
  197.       this.jumperMC.man.jet.flame_shadow._visible = true;
  198.       this.setJumper = this.setJumperOnMove;
  199.       this.jumper_enabledEvents = true;
  200.    }
  201.    function checkForegroundCollision()
  202.    {
  203.       var foregroundBitmap;
  204.       var playerHitPoint = new flash.geom.Point();
  205.       var foregroundPoint = new flash.geom.Point();
  206.       var hitted1;
  207.       var hitted0;
  208.       var hittest;
  209.       var gb = this._playerOutBounds;
  210.       var gb2 = this._playerInBounds;
  211.       var rectangle = new flash.geom.Rectangle(0,0,this.jumperMC._width,this.jumperMC._height);
  212.       var tMC = this.foregroundscene.getMCOf(0);
  213.       var playerBitmap = new flash.display.BitmapData(gb.xMax - gb.xMin,gb.yMax - gb.yMin,true,255);
  214.       var matrix = new flash.geom.Matrix(-1,0,0,1,- gb2.xMin,- gb2.yMin);
  215.       playerBitmap.draw(this.jumperMC,matrix,this.noColorTransform,"normal");
  216.       playerHitPoint.x = gb.xMin;
  217.       playerHitPoint.y = gb.yMin;
  218.       foregroundBitmap = this.foregroundscene.getBitmapOf(0);
  219.       foregroundPoint.x = tMC._x;
  220.       foregroundPoint.y = tMC._y;
  221.       hitted0 = playerBitmap.hitTest(playerHitPoint,255,foregroundBitmap,foregroundPoint,255);
  222.       if(hitted0 == true)
  223.       {
  224.          do
  225.          {
  226.             this.jumperMC._y++;
  227.             playerHitPoint.y++;
  228.             hittest = playerBitmap.hitTest(playerHitPoint,255,foregroundBitmap,foregroundPoint,255);
  229.          }
  230.          while(hittest == true);
  231.          
  232.       }
  233.       playerBitmap.dispose();
  234.       tMC = this.foregroundscene.getMCOf(1);
  235.       playerBitmap = new flash.display.BitmapData(gb.xMax - gb.xMin,gb.yMax - gb.yMin,true,255);
  236.       matrix = new flash.geom.Matrix(-1,0,0,-1,gb2.xMax,gb2.yMax);
  237.       playerBitmap.draw(this.jumperMC,matrix,this.noColorTransform,"normal");
  238.       playerHitPoint.y = this.gameArea._height - gb.yMax;
  239.       foregroundBitmap = this.foregroundscene.getBitmapOf(1);
  240.       foregroundPoint.x = tMC._x;
  241.       foregroundPoint.y = 0;
  242.       hitted1 = playerBitmap.hitTest(playerHitPoint,255,foregroundBitmap,foregroundPoint,255);
  243.       if(hitted1 == true)
  244.       {
  245.          do
  246.          {
  247.             this.jumperMC._y--;
  248.             playerHitPoint.y++;
  249.             hittest = playerBitmap.hitTest(playerHitPoint,255,foregroundBitmap,foregroundPoint,255);
  250.          }
  251.          while(hittest == true);
  252.          
  253.       }
  254.       playerBitmap.dispose();
  255.       if(hitted0 == true || hitted1 == true)
  256.       {
  257.          this.manager.playFX("snd_ground");
  258.          this.setJumperRotation(!hitted0 ? -1 : 1);
  259.       }
  260.    }
  261.    function setJumperRotation(dir)
  262.    {
  263.       if(this.jumper_enabledEvents == false)
  264.       {
  265.          return undefined;
  266.       }
  267.       this.jumper_enabledEvents = false;
  268.       this.rotateByHitValue = dir * this.rotateByHitMax;
  269.       this.moveByHitValue = dir * int(2 * this.moveByHitMax * this._speedRate);
  270.       this.moveByHitStepValue = dir * this.moveByHitStep;
  271.       this.rotateHitStepValue = dir * this.rotateByHitStep;
  272.       this.jumperMC.man.jet.flame._visible = false;
  273.       this.jumperMC.man.jet.flame_shadow._visible = false;
  274.       this.setJumper = dir != 1 ? this.setJumperAfterHitDown : this.setJumperAfterHitUp;
  275.    }
  276.    function setJumperAfterHitUp()
  277.    {
  278.       var rot = this.jumperMC.man._rotation;
  279.       this.jumperMC._y += this.moveByHitValue;
  280.       if(this.moveByHitValue < this.moveByHitStep)
  281.       {
  282.          this.moveByHitValue = 0;
  283.       }
  284.       else
  285.       {
  286.          this.moveByHitValue -= this.moveByHitStepValue;
  287.       }
  288.       if(Math.abs(this.rotateByHitValue) <= this.rotatMin)
  289.       {
  290.          rot = this.jumperMC.man._rotation += this.rotatMin;
  291.          if((rot > 180 - this.rotatMin || rot < this.rotatMin - 180) && this.moveByHitValue == 0)
  292.          {
  293.             this.backJumperToAction();
  294.          }
  295.       }
  296.       else
  297.       {
  298.          this.jumperMC.man._rotation += this.rotateByHitValue;
  299.          this.rotateByHitValue -= this.rotateHitStepValue;
  300.       }
  301.       this.getPlayerBounds();
  302.    }
  303.    function setJumperAfterHitDown()
  304.    {
  305.       var rot = this.jumperMC.man._rotation;
  306.       this.jumperMC._y += this.moveByHitValue;
  307.       if(this.moveByHitValue < this.moveByHitStep)
  308.       {
  309.          this.moveByHitValue = 0;
  310.       }
  311.       else
  312.       {
  313.          this.moveByHitValue -= this.moveByHitStepValue;
  314.       }
  315.       if(Math.abs(this.rotateByHitValue) <= this.rotatMin)
  316.       {
  317.          rot = this.jumperMC.man._rotation -= this.rotatMin;
  318.          if((rot > 180 - this.rotatMin || rot < this.rotatMin - 180) && this.moveByHitValue == 0)
  319.          {
  320.             this.backJumperToAction();
  321.          }
  322.       }
  323.       else
  324.       {
  325.          this.jumperMC.man._rotation += this.rotateByHitValue;
  326.          this.rotateByHitValue -= this.rotateHitStepValue;
  327.       }
  328.       this.getPlayerBounds();
  329.    }
  330.    function setJumperOnMove()
  331.    {
  332.       var d_rot = (- this.rotatMin) * this.moveByY * this._speedRate;
  333.       this.jumperMC._y += this.moveByY * this._speedRate;
  334.       this.jumperMC._x += this.moveByX;
  335.       this.jumperMC.man._rotation = 180 + d_rot;
  336.       this.jumperMC.man.leg1._rotation = this._speedValue + d_rot;
  337.       this.jumperMC.man.leg2._rotation = this._speedValue + d_rot;
  338.       this.jumperMC.man.korpus._rotation = (- this._speedValue) / 2;
  339.       this.jumperMC.man.korpus.reka1._rotation = this._speedValue;
  340.       this.jumperMC.man.korpus.glowa._rotation = (- this._speedValue) / 4;
  341.       this.jumperMC.man.jet.gotoAndStop(this.jumper_jetEndFrame - int(this.jumper_jetFrames * this._speedRate));
  342.       this.jumperMC.man.jet._rotation = 90 - d_rot;
  343.       this.getPlayerBounds();
  344.    }
  345.    function getPlayerBounds()
  346.    {
  347.       this._playerOutBounds = this.jumperMC.getBounds(this.jumperMC._parent);
  348.       this._playerInBounds = this.jumperMC.getBounds();
  349.    }
  350.    function useBonus()
  351.    {
  352.       if(this._bonusInUse == true || this._bonusValue == 0 || this.jumper_enabledEvents == false || this._isPaused == true)
  353.       {
  354.          return undefined;
  355.       }
  356.       this.manager.playFX("snd_bonus_atom");
  357.       this._bonusInUse = true;
  358.       this._bonusValue = int(this._bonusValue / 2);
  359.       this.bonus.setValue(this._bonusValue);
  360.       this.addFuelValue(1);
  361.       var a = new flash.geom.ColorTransform(1,1,1,1,255,255,255,0);
  362.       var b = new flash.geom.ColorTransform(1,1,1,1,0,0,0,0);
  363.       var c = new flash.geom.ColorTransform(1,1,1,0,0,0,0,0);
  364.       this.fader.fadeIt(this.gameMC,a,0,null);
  365.       this.fader.fadeIt(this.gameMC,b,50,null);
  366.       this.fader.fadeIt(this.objectsscene.getSceneMC(),c,30,system.Delegate.create(this,this.onBonusUseEnd));
  367.    }
  368.    function onBonusUseEnd()
  369.    {
  370.       this.objectsscene.removeObjects();
  371.       var b = new flash.geom.ColorTransform(1,1,1,1,0,0,0,0);
  372.       this.fader.fadeIt(this.objectsscene.getSceneMC(),b,0,null);
  373.       this._bonusInUse = false;
  374.    }
  375.    function useKeys(val)
  376.    {
  377.       if(this._isPaused == true)
  378.       {
  379.          return undefined;
  380.       }
  381.       if(val._y != undefined)
  382.       {
  383.          this.moveByY = val._y * this.multipleY;
  384.       }
  385.    }
  386.    function pauseGame(val)
  387.    {
  388.       this._isPaused = val;
  389.       if(val == true)
  390.       {
  391.          this.prevspeed = this._speedValue;
  392.          this._speedValue = 0;
  393.       }
  394.       else
  395.       {
  396.          this._speedValue = this.prevspeed;
  397.       }
  398.    }
  399.    function onNewSceneElement(upper, px, py)
  400.    {
  401.       this.itemsArray.sortOn("nextpoint",Array.NUMERIC);
  402.       if(this.itemsArray[0].nextpoint > this._distance || this._distance - this._lastitemplace < this.minItemDistance)
  403.       {
  404.          return undefined;
  405.       }
  406.       var itemobj = this.itemsArray[0];
  407.       var r = itemobj.classname;
  408.       var s = itemobj.space * Math.random();
  409.       this._lastitemplace = this._distance;
  410.       itemobj.nextpoint += itemobj.dist;
  411.       if(upper == true)
  412.       {
  413.          py += s;
  414.       }
  415.       else
  416.       {
  417.          py -= s;
  418.       }
  419.       this.objectsscene.addObject(r,r,itemobj.upper && upper,px,py,1,0);
  420.    }
  421.    function accelate()
  422.    {
  423.       if(this._isPaused == true)
  424.       {
  425.          return undefined;
  426.       }
  427.       this._speedValue *= this.resistance;
  428.       this._speedRate = this._speedValue / this.speedMax;
  429.       this._lastdistance = this._distance;
  430.       this._distance = Math.round(this._distance + this._speedValue);
  431.       if(this._speedValue < this.speedMin)
  432.       {
  433.          this.endGame();
  434.       }
  435.    }
  436.    function setFuel()
  437.    {
  438.       var tMC = this.fuelMC.energyline.bar;
  439.       tMC._y = (- tMC._height) * this._speedRate;
  440.    }
  441.    function setScore()
  442.    {
  443.       this._scoreValue = int(this._scoreValue + this._speedValue / 10);
  444.       this.score.setValue(this._scoreValue);
  445.    }
  446.    function moveScene()
  447.    {
  448.       this.foregroundscene.moveScene(this._speedValue);
  449.       this.backgroundscene.moveScene(this._speedValue);
  450.    }
  451.    function moveObjects()
  452.    {
  453.       this.objectsscene.moveObjects(this._speedValue,getTimer());
  454.    }
  455.    function do_oEF()
  456.    {
  457.       this.setJumper();
  458.       this.moveScene();
  459.       this.moveObjects();
  460.       this.checkForegroundCollision();
  461.       this.checkObjectsCollision();
  462.       this.setFuel();
  463.       this.setScore();
  464.       this.accelate();
  465.    }
  466.    function makeScene(_MC)
  467.    {
  468.       this.backgroundscene = new games.MovingScene(_MC,0,550,400);
  469.       this.foregroundscene = new games.MovingScene(_MC,1000,550,400);
  470.       this.objectsscene = new games.MovingObjects(_MC,110,550,400);
  471.       this.foregroundscene.addBackground(0,1,0,true,50,230,20,150,"wall0","wall0_slope");
  472.       this.foregroundscene.addBackground(1,1,400,false,50,220,20,150,"wall0","wall0_slope");
  473.       this.backgroundscene.addBackground(2,0.75,0,true,50,150,120,200,"wall1","wall1_slope","wall2","wall2_slope");
  474.       this.backgroundscene.addBackground(3,0.75,400,false,50,150,120,200,"wall1","wall1_slope","wall2","wall2_slope");
  475.       this.foregroundscene.broadcastBackground(0);
  476.       this.foregroundscene.broadcastBackground(1);
  477.       this.foregroundscene.addListener(this);
  478.       var tMC = this.objectsscene.addObject("startscene",undefined,false,this.gameArea._width,this.gameArea._height / 2,1,0);
  479.       tMC.startAction = system.Delegate.create(this,this.startGame);
  480.    }
  481.    function startGame()
  482.    {
  483.       this.manager.playMusic("loop_ambient");
  484.       this.setJumper = this.setJumperOnMove;
  485.       this.onBonusUse = this.useBonus;
  486.       this.onKeysMove = this.useKeys;
  487.       this._speedValue = this.startSpeed;
  488.       this._bonusValue = 1;
  489.       this.bonus.resetTo("1");
  490.       this.jumperMC.man.jet.flame._visible = true;
  491.       this.jumperMC.man.jet.flame_shadow._visible = true;
  492.       this.timer.addListener(this.gameMC,0,system.Delegate.create(this,this.do_oEF),0);
  493.    }
  494.    function endGame(txt)
  495.    {
  496.       this.manager.stopMusic("loop_ambient");
  497.       this.manager.playFX("snd_gameover");
  498.       this._bonusValue = 0;
  499.       var gameoverinfo = txt != undefined ? txt : "game over!";
  500.       var gameoverscore = this.score.getValue();
  501.       var fn1 = this.manager.call_gameOver;
  502.       var fn0 = system.Delegate.create(this.manager,fn1,gameoverscore,gameoverinfo);
  503.       this.jumperMC.gotoAndPlay("helpless");
  504.       this.timer.addListener(this.gameMC,this.time_endLevelPause,fn0,1);
  505.    }
  506. }
  507.