home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / starisland.swf / scripts / __Packages / illusoft / GameTile.as < prev    next >
Encoding:
Text File  |  2007-12-10  |  15.3 KB  |  521 lines

  1. class illusoft.GameTile
  2. {
  3.    var id;
  4.    var dynamicsEngine;
  5.    var character;
  6.    var gameMC;
  7.    var game;
  8.    var nextLevel;
  9.    var surfaces;
  10.    var surfaceStatus;
  11.    var dmc;
  12.    var Enemy;
  13.    var edges;
  14.    var childs;
  15.    var gate1;
  16.    var portal;
  17.    var jetstream;
  18.    var normalGravities;
  19.    var button1;
  20.    var portal_graph;
  21.    var helps;
  22.    var rrs;
  23.    var onEnterFrame;
  24.    var _parent;
  25.    var levelComplete;
  26.    var startTime = 0;
  27.    var missionTime = 180000;
  28.    var pauseTime = 0;
  29.    var groundx = 0;
  30.    var groundy = 0;
  31.    var isActive = false;
  32.    var minX = 0;
  33.    var maxX = 0;
  34.    function GameTile(id, dEngine, character, game, gamemc, nextLevel)
  35.    {
  36.       this.id = id;
  37.       this.dynamicsEngine = dEngine;
  38.       this.character = character;
  39.       this.gameMC = gamemc;
  40.       this.game = game;
  41.       var _loc2_ = this;
  42.       this.nextLevel = nextLevel;
  43.       this.surfaces = new Array();
  44.       this.surfaceStatus = new Array();
  45.    }
  46.    function GetCharMC()
  47.    {
  48.       return this.dmc.char;
  49.    }
  50.    function Setup(gx, gy, surfaceData, childs, gate1Ar, portalAr, jetAr, normalGravities, switch1Ar, portalGrAr, helps, rrs)
  51.    {
  52.       this.groundx = gx;
  53.       this.groundy = gy;
  54.       this.dmc._x = - this.groundx;
  55.       this.dmc._y = - this.groundy;
  56.       this.GenerateSurfaces(surfaceData,- gx,- gy);
  57.       this.GenerateChilds(childs,- gx,- gy);
  58.       this.GenerateGate(gate1Ar,- gx,- gy,switch1Ar);
  59.       this.GeneratePortal(portalAr,- gx,- gy);
  60.       this.GenerateJetStream(jetAr,- gx,- gy);
  61.       this.GenerateNormalGravities(normalGravities,- gx,- gy);
  62.       this.GenerateRoundedRects(rrs,- gx,- gy);
  63.       this.GenerateExPortal(portalGrAr,- gx,- gy);
  64.       this.GenerateHelps(helps,- gx,- gy);
  65.    }
  66.    function GetBounds()
  67.    {
  68.       return {left:this.dmc._x,right:this.dmc._x + this.dmc._width};
  69.    }
  70.    function GenerateGate(gateAr, dx, dy, switchAr)
  71.    {
  72.       if(gateAr != null)
  73.       {
  74.          var _loc4_ = this.AddGate(gateAr[0] + dx,gateAr[1] + dy,gateAr[2],gateAr[3],gateAr[4]);
  75.          if(switchAr != null)
  76.          {
  77.             this.AddSwitch(switchAr[0] + dx,switchAr[1] + dy,switchAr[2],switchAr[3],switchAr[4],_loc4_);
  78.          }
  79.       }
  80.    }
  81.    function GeneratePortal(portalAr, dx, dy)
  82.    {
  83.       this.AddPortal(portalAr[0] + dx,portalAr[1] + dy,portalAr[2],portalAr[3],portalAr[4]);
  84.    }
  85.    function GenerateExPortal(portalAr, dx, dy)
  86.    {
  87.       if(portalAr != null)
  88.       {
  89.          this.AddExPortal(portalAr[0] + dx,portalAr[1] + dy,portalAr[2],portalAr[3],portalAr[4]);
  90.       }
  91.    }
  92.    function GenerateJetStream(jetAr, dx, dy)
  93.    {
  94.       if(jetAr != null)
  95.       {
  96.          this.AddJetStream(jetAr[0] + dx,jetAr[1] + dy,jetAr[2],jetAr[3],jetAr[4]);
  97.       }
  98.    }
  99.    function GenerateChilds(childs, dx, dy)
  100.    {
  101.       var _loc3_ = 0;
  102.       while(_loc3_ < childs.length)
  103.       {
  104.          var _loc2_ = childs[_loc3_];
  105.          if(_loc2_ != null)
  106.          {
  107.             this.AddChildChar(_loc2_[0] + dx,_loc2_[1] + dy,_loc2_[2],_loc2_[3],_loc2_[4]);
  108.          }
  109.          _loc3_ = _loc3_ + 1;
  110.       }
  111.    }
  112.    function GenerateNormalGravities(normalGravities, dx, dy)
  113.    {
  114.       var _loc3_ = 0;
  115.       while(_loc3_ < normalGravities.length)
  116.       {
  117.          var _loc2_ = normalGravities[_loc3_];
  118.          if(_loc2_ != null)
  119.          {
  120.             this.AddNormalGravity(_loc2_[0] + dx,_loc2_[1] + dy,_loc2_[2],_loc2_[3],_loc2_[4]);
  121.          }
  122.          _loc3_ = _loc3_ + 1;
  123.       }
  124.    }
  125.    function GenerateRoundedRects(rrs, dx, dy)
  126.    {
  127.       var _loc3_ = 0;
  128.       while(_loc3_ < rrs.length)
  129.       {
  130.          var _loc2_ = rrs[_loc3_];
  131.          if(_loc2_ != null)
  132.          {
  133.             this.AddRoundedRect(_loc2_[0] + dx,_loc2_[1] + dy,_loc2_[2],_loc2_[3],_loc2_[4]);
  134.          }
  135.          _loc3_ = _loc3_ + 1;
  136.       }
  137.    }
  138.    function GenerateHelps(helps, dx, dy)
  139.    {
  140.       var _loc3_ = 0;
  141.       while(_loc3_ < helps.length)
  142.       {
  143.          var _loc2_ = helps[_loc3_];
  144.          if(_loc2_ != null)
  145.          {
  146.             this.AddHelp(_loc2_[0] + dx,_loc2_[1] + dy,_loc2_[2],_loc2_[3],_loc2_[4]);
  147.          }
  148.          _loc3_ = _loc3_ + 1;
  149.       }
  150.    }
  151.    function Update(x)
  152.    {
  153.       var _loc5_ = Math.round(x / 150);
  154.       var _loc2_ = this.minX;
  155.       while(_loc2_ < this.maxX)
  156.       {
  157.          var _loc4_ = _loc2_ == _loc5_ || _loc2_ + 1 == _loc5_ || _loc2_ - 1 == _loc5_;
  158.          if(this.surfaceStatus[_loc2_] != _loc4_)
  159.          {
  160.             var _loc3_ = 0;
  161.             while(_loc3_ < this.surfaces.length)
  162.             {
  163.                this.surfaces[_loc2_][_loc3_].setActiveState(_loc4_);
  164.                _loc3_ = _loc3_ + 1;
  165.             }
  166.             this.surfaceStatus[_loc2_] = _loc4_;
  167.          }
  168.          _loc2_ = _loc2_ + 1;
  169.       }
  170.    }
  171.    function GenerateSurfaces(surfaceData, dx, dy)
  172.    {
  173.       var cref = this;
  174.       var _loc7_ = 0;
  175.       while(_loc7_ < surfaceData.length)
  176.       {
  177.          var _loc4_ = surfaceData[_loc7_];
  178.          var _loc3_ = _loc4_[0] + dx;
  179.          var _loc10_ = _loc4_[1] + dy;
  180.          var _loc2_ = _loc4_[2] + dx;
  181.          var _loc9_ = _loc4_[3] + dy;
  182.          if(this.minX == null || _loc3_ < this.minX)
  183.          {
  184.             this.minX = _loc3_;
  185.          }
  186.          else if(this.maxX == null || _loc3_ > this.maxX)
  187.          {
  188.             this.maxX = _loc3_;
  189.          }
  190.          if(_loc2_ < this.minX)
  191.          {
  192.             this.minX = _loc2_;
  193.          }
  194.          else if(_loc2_ > this.maxX)
  195.          {
  196.             this.maxX = _loc2_;
  197.          }
  198.          var _loc5_ = Math.round((_loc3_ + _loc2_) / 300);
  199.          if(this.surfaces[_loc5_] == null)
  200.          {
  201.             this.surfaces[_loc5_] = new Array();
  202.             this.surfaceStatus[_loc5_] = true;
  203.          }
  204.          var _loc11_ = _loc4_[4];
  205.          var _loc6_ = new org.cove.flade.surfaces.LineSurface(_loc3_,_loc10_,_loc2_,_loc9_,this.gameMC);
  206.          this.surfaces[_loc5_].push(_loc6_);
  207.          this.dynamicsEngine.addSurface(_loc6_);
  208.          var _loc8_ = _loc2_ - _loc3_;
  209.          var _loc12_ = _loc9_ - _loc10_;
  210.          if(_loc8_ != 0 && Math.abs(_loc12_ / _loc8_) < 1.3 && _loc11_ && _loc8_ > 0)
  211.          {
  212.             _loc6_.onContact = function()
  213.             {
  214.                cref.character.AllowJump(true,this);
  215.             };
  216.          }
  217.          _loc7_ = _loc7_ + 1;
  218.       }
  219.    }
  220.    function AddLineSurface(line, allowJump)
  221.    {
  222.       this.surfaces.push(line);
  223.       var cref = this;
  224.       line.onContact = function()
  225.       {
  226.          cref.character.AllowJump(allowJump);
  227.       };
  228.       this.dynamicsEngine.addSurface(line);
  229.    }
  230.    function AddCircleSurface(circle, allowJump)
  231.    {
  232.       this.surfaces.push(circle);
  233.       var cref = this;
  234.       circle.onContact = function()
  235.       {
  236.          cref.character.AllowJump(allowJump);
  237.       };
  238.       this.dynamicsEngine.addSurface(circle);
  239.    }
  240.    function SetActive(active)
  241.    {
  242.       if(this.isActive != active)
  243.       {
  244.          for(var _loc4_ in this.surfaces)
  245.          {
  246.             var _loc2_ = this.surfaces[_loc4_];
  247.             _loc2_.setActiveState(active);
  248.          }
  249.          this.isActive = active;
  250.       }
  251.    }
  252.    function Start()
  253.    {
  254.       if(_root.pad1 != undefined)
  255.       {
  256.          removeMovieClip(_root.pad1);
  257.       }
  258.       illusoft.Game.Instance.running = true;
  259.       this.character.ShowInfo(_root);
  260.       this.game.arrEnemy = this.Enemy.split("/");
  261.       this.game.protecttime = 60;
  262.       trace("Start:" + this.id);
  263.       if(SharedObject.getLocal("Agame.starisland").data[this.id] == null)
  264.       {
  265.          SharedObject.getLocal("Agame.starisland").data[this.id] = 0;
  266.          SharedObject.getLocal("Agame.starisland").data[this.id].flush();
  267.       }
  268.       var _loc4_ = SharedObject.getLocal("Agame.starisland").data[this.id];
  269.       var _loc3_ = _loc4_ % 60;
  270.       this.character.info_mc.RegTime.text = int(_loc4_ / 60) + "  " + (_loc3_ >= 10 ? _loc3_ : "0" + _loc3_);
  271.    }
  272.    function Init()
  273.    {
  274.       var classRef = this;
  275.       this.game.chafe = 1;
  276.       this.game.Thisscore = 0;
  277.       this.game.GetStars = 0;
  278.       this.game.KilledEnemies = 0;
  279.       this.dmc = this.gameMC.attachMovie(this.id,this.id + new Date().getTime(),this.gameMC.getNextHighestDepth());
  280.       this.dmc.onEnterFrame = function()
  281.       {
  282.          classRef.Setup(this.groundx,this.groundy,this.edges,this.childs,this.gate1,this.portal,this.jetstream,this.normalGravities,this.button1,this.portal_graph,this.helps,this.rrs);
  283.          delete this.onEnterFrame;
  284.       };
  285.    }
  286.    function AddRectangleSurface(surface, allowJump)
  287.    {
  288.       this.surfaces.push(surface);
  289.       var cref = this;
  290.       surface.onContact = function()
  291.       {
  292.          cref.character.AllowJump(allowJump);
  293.       };
  294.       this.dynamicsEngine.addSurface(surface);
  295.    }
  296.    function AddRectangleSurface2(surface, allowJump)
  297.    {
  298.       this.surfaces.push(surface);
  299.       var _loc2_ = this;
  300.       surface.onContact = function()
  301.       {
  302.          surface.setActiveState(false);
  303.       };
  304.       this.dynamicsEngine.addSurface(surface);
  305.    }
  306.    function AddRoundedRectangle(rr)
  307.    {
  308.       this.surfaces.push(rr);
  309.       this.dynamicsEngine.addSurface(rr);
  310.    }
  311.    function AddChildChar(xPos, yPos, width, height, mc)
  312.    {
  313.       var rc = new illusoft.utils.RectangleCheck(xPos,yPos,width,height,this.gameMC);
  314.       this.surfaces.push(rc);
  315.       var cref = this;
  316.       mc._visible = true;
  317.       rc.onContact = function()
  318.       {
  319.          rc.setActiveState(false);
  320.          rc.setVisible(false);
  321.          _global.sounds.PlaySound("bling");
  322.          mc._visible = false;
  323.          cref.character.FoundChild(mc._name);
  324.       };
  325.       this.dynamicsEngine.addSurface(rc);
  326.    }
  327.    function AddJetStream(xPos, yPos, width, height, mc)
  328.    {
  329.       var _loc2_ = new illusoft.utils.RectangleCheck(xPos,yPos,width,height,this.gameMC);
  330.       this.surfaces.push(_loc2_);
  331.       var cref = this;
  332.       mc._visible = false;
  333.       _loc2_.onContact = function()
  334.       {
  335.          cref.game.Stream();
  336.          cref.character.AllowJump(false);
  337.       };
  338.       this.dynamicsEngine.addSurface(_loc2_);
  339.    }
  340.    function AddNormalGravity(xPos, yPos, width, height, mc)
  341.    {
  342.       var _loc2_ = new illusoft.utils.RectangleCheck(xPos,yPos,width,height,this.gameMC);
  343.       this.surfaces.push(_loc2_);
  344.       var cref = this;
  345.       mc._visible = false;
  346.       _loc2_.onContact = function()
  347.       {
  348.          cref.game.NormalGravity();
  349.          cref.character.AllowJump(false);
  350.       };
  351.       this.dynamicsEngine.addSurface(_loc2_);
  352.    }
  353.    function AddRoundedRect(xPos, yPos, width, height, mc)
  354.    {
  355.       var _loc2_ = new illusoft.utils.RoundedRectangle(xPos,yPos,width,height,25,this.dynamicsEngine,this.character,this.gameMC);
  356.       this.surfaces.push(_loc2_);
  357.       var _loc3_ = this;
  358.       mc._visible = false;
  359.       _loc2_.onContact = function()
  360.       {
  361.       };
  362.       this.dynamicsEngine.addSurface(_loc2_);
  363.    }
  364.    function AddGate(xPos, yPos, width, height, mc, switchAr)
  365.    {
  366.       var _loc2_ = new org.cove.flade.surfaces.RectangleTile(xPos,yPos,width,height,this.gameMC);
  367.       this.gate1 = new illusoft.Gate(mc,_loc2_);
  368.       this.surfaces.push(_loc2_);
  369.       var cref = this;
  370.       mc._visible = true;
  371.       _loc2_.onContact = function()
  372.       {
  373.          cref.CheckGate();
  374.       };
  375.       this.dynamicsEngine.addSurface(_loc2_);
  376.       return this.gate1;
  377.    }
  378.    function AddHelp(xPos, yPos, width, height, mc, switchAr)
  379.    {
  380.       var _loc2_ = new illusoft.utils.RectangleCheck(xPos,yPos,width,height,this.gameMC);
  381.       var help = new illusoft.Help(mc,_loc2_,this.game);
  382.       this.surfaces.push(_loc2_);
  383.       var _loc4_ = this;
  384.       mc._visible = true;
  385.       _loc2_.onContact = function()
  386.       {
  387.          help.Show();
  388.       };
  389.       this.dynamicsEngine.addSurface(_loc2_);
  390.    }
  391.    function AddSwitch(xPos, yPos, width, height, mc, gate)
  392.    {
  393.       var _loc2_ = new org.cove.flade.surfaces.CircleTile(xPos,yPos,width / 2,this.gameMC);
  394.       this.surfaces.push(_loc2_);
  395.       _loc2_.onContact = function()
  396.       {
  397.          gate.Open();
  398.       };
  399.       this.dynamicsEngine.addSurface(_loc2_);
  400.       var _loc3_ = new illusoft.Switch(mc,_loc2_);
  401.       gate.SetSwitch(_loc3_);
  402.    }
  403.    function AddPortal(xPos, yPos, width, height, mc)
  404.    {
  405.       var _loc4_ = new org.cove.flade.surfaces.RectangleTile(xPos,yPos,width,height,this.gameMC);
  406.       this.portal = new illusoft.Portal(mc,_loc4_);
  407.       this.surfaces.push(_loc4_);
  408.       var cref = this;
  409.       mc._visible = true;
  410.       mc.AniDone = function()
  411.       {
  412.          cref.GoToNextLevel();
  413.       };
  414.       mc.RotateDone = function()
  415.       {
  416.          illusoft.Game.Instance.running = false;
  417.          var _loc3_ = this._parent.levelComplete;
  418.          _loc3_._x = - cref.gameMC._x + 250;
  419.          _loc3_._y = - cref.gameMC._y + 120;
  420.          _loc3_.gotoAndPlay(1);
  421.          _loc3_._visible = true;
  422.          cref.game.listenForKeys = false;
  423.          cref.GetCharMC()._visible = false;
  424.          _global.sounds.PlaySound("surprise");
  425.       };
  426.       _loc4_.onContact = function()
  427.       {
  428.          cref.CheckPortal();
  429.       };
  430.       this.dynamicsEngine.addSurface(_loc4_);
  431.    }
  432.    function AddExPortal(xPos, yPos, width, height, mc)
  433.    {
  434.       var _loc2_ = new org.cove.flade.surfaces.RectangleTile(xPos,yPos,width,height,this.gameMC);
  435.       this.surfaces.push(_loc2_);
  436.       var _loc4_ = this;
  437.       mc._visible = true;
  438.       mc.stars._visible = false;
  439.       this.dynamicsEngine.addSurface(_loc2_);
  440.    }
  441.    function CheckPortal()
  442.    {
  443.       if(this.character.HasAllChilds())
  444.       {
  445.          this.LevelComplete();
  446.          this.game.LevelComplete();
  447.          this.portal.Open();
  448.       }
  449.    }
  450.    function LevelComplete()
  451.    {
  452.    }
  453.    function GetPortalPos()
  454.    {
  455.       var _loc2_ = this.dmc.portal;
  456.       return new illusoft.utils.Point(_loc2_._x + _loc2_._width / 2,_loc2_._y + _loc2_._height / 2);
  457.    }
  458.    function CheckGate()
  459.    {
  460.    }
  461.    function OpenGate()
  462.    {
  463.       if(this.gate1 != null)
  464.       {
  465.          this.gate1.Open();
  466.       }
  467.    }
  468.    function HasAllChilds()
  469.    {
  470.    }
  471.    function GoToNextLevel()
  472.    {
  473.       this.game.GoToNextLevel();
  474.    }
  475.    function Close()
  476.    {
  477.       this.dmc._visible = false;
  478.       this.character.HideInfo();
  479.       this.Enemy = "";
  480.       this.game.SetUnderWater(false);
  481.       this.game.NormalGravity();
  482.       this.dynamicsEngine.ClearSurfaces();
  483.       removeMovieClip(this.dmc);
  484.       delete this.dmc;
  485.    }
  486.    function StartToTime()
  487.    {
  488.       this.startTime = getTimer();
  489.       trace(this.startTime);
  490.       this.levelComplete = false;
  491.       this.character.info_mc.txtChild.text = "0/5";
  492.       this.character.info_mc.txtScore.text = this.game.Totalscore;
  493.       this.character.UpdateBlood(true);
  494.    }
  495.    function GetPlayedTime()
  496.    {
  497.       if(this.game.listenForKeys)
  498.       {
  499.          return this.pauseTime - this.startTime;
  500.       }
  501.       return this.pauseTime - this.startTime;
  502.    }
  503.    function GetTimeLeft()
  504.    {
  505.       if(this.game.listenForKeys)
  506.       {
  507.          if(this.pauseTime != 0)
  508.          {
  509.             this.startTime += getTimer() - this.pauseTime;
  510.             this.pauseTime = 0;
  511.          }
  512.          return this.missionTime + this.startTime - getTimer();
  513.       }
  514.       if(this.pauseTime == 0)
  515.       {
  516.          this.pauseTime = getTimer();
  517.       }
  518.       return this.missionTime + this.startTime - this.pauseTime;
  519.    }
  520. }
  521.