home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / Clusterz / Clusterz.swf / scripts / Clusterz.as next >
Encoding:
Text File  |  2008-09-12  |  10.5 KB  |  309 lines

  1. package
  2. {
  3.    import ENGINE.CORE.OCache;
  4.    import ENGINE.CORE.OGlobal;
  5.    import ENGINE.CORE.OSound;
  6.    import ENGINE.CORE.OSystem;
  7.    import ENGINE.INTERFACE.OAlert;
  8.    import ENGINE.INTERFACE.OApplication;
  9.    import ENGINE.INTERFACE.OWindow;
  10.    import ENGINE.SMARTFOX.OMultiplayer;
  11.    import RES.OBJECTS.OBang;
  12.    import RES.OBJECTS.OBubble;
  13.    import RES.WINDOWS.OWChoosePlayer;
  14.    import RES.WINDOWS.OWEnterName;
  15.    import RES.WINDOWS.OWGame;
  16.    import RES.WINDOWS.OWHighScores;
  17.    import RES.WINDOWS.OWInstructions;
  18.    import RES.WINDOWS.OWIntro;
  19.    import RES.WINDOWS.OWMenu;
  20.    import RES.WINDOWS.OWOptions;
  21.    import flash.display.BitmapData;
  22.    import flash.display.DisplayObject;
  23.    import flash.display.GradientType;
  24.    import flash.display.Sprite;
  25.    import flash.events.Event;
  26.    import flash.geom.Matrix;
  27.    import flash.system.Security;
  28.    
  29.    public class Clusterz extends OApplication
  30.    {
  31.       
  32.       public static const stNormal:int = 0;
  33.       
  34.       public static const stInstruction:int = 1;
  35.        
  36.       
  37.       private var iShowDemo:Boolean = true;
  38.       
  39.       private var iSystem:OSystem;
  40.       
  41.       private var iBang:OBang;
  42.       
  43.       private var iWindow:OWindow;
  44.       
  45.       public function Clusterz()
  46.       {
  47.          iShowDemo = true;
  48.          super("Clusterz");
  49.          ClusterzL.iGAME;
  50.          Security.allowDomain("*");
  51.          OSound.PlayListAdd("music.mp3");
  52.          OSound.PlayMusic();
  53.       }
  54.       
  55.       override public function Init() : void
  56.       {
  57.          if(!this.stage || this.stage.stageHeight == 0 || this.stage.stageWidth == 0)
  58.          {
  59.             return;
  60.          }
  61.          this.InitBackground([this.MakeBackgroundImage()],0);
  62.          if(ClusterzL.sDebug)
  63.          {
  64.             this.iSystem = new OSystem();
  65.             this.addChild(this.iSystem);
  66.          }
  67.          this.InitImageCache();
  68.          super.Init();
  69.          this.iBang = new OBang();
  70.          this.addChild(this.iBang);
  71.          if(ClusterzL.iGAME.prPlayerName == "")
  72.          {
  73.             this.prMenuItem = ClusterzL.miIntro;
  74.          }
  75.          else
  76.          {
  77.             this.prMenuItem = ClusterzL.miIntro;
  78.          }
  79.          OnMenuItem();
  80.       }
  81.       
  82.       override protected function OnMenuItem() : void
  83.       {
  84.          var _loc1_:int = 0;
  85.          var _loc2_:DisplayObject = null;
  86.          var _loc3_:OWHighScores = null;
  87.          _loc1_ = this.prMenuItem;
  88.          if(_loc1_ != ClusterzL.miInstructions)
  89.          {
  90.             State = stNormal;
  91.          }
  92.          switch(_loc1_)
  93.          {
  94.             case ClusterzL.miNullWindow:
  95.                return;
  96.             case ClusterzL.miLastWindow:
  97.                _loc2_ = this.getChildAt(this.numChildren - 1);
  98.                this.iWindow = _loc2_ is OWindow ? _loc2_ as OWindow : null;
  99.                if(this.iWindow)
  100.                {
  101.                   this.iWindow.prActive = true;
  102.                   return;
  103.                }
  104.                this.iWindow = new OWMenu();
  105.                this.prMenuItem = ClusterzL.miNullWindow;
  106.                break;
  107.             case ClusterzL.miIntro:
  108.                this.iWindow = new OWIntro();
  109.                if(ClusterzL.iGAME.prPlayerName == "")
  110.                {
  111.                   this.prMenuItem = ClusterzL.miEnterNameFirst;
  112.                }
  113.                else
  114.                {
  115.                   this.prMenuItem = ClusterzL.miMenu;
  116.                }
  117.                break;
  118.             case ClusterzL.miEnterNameFirst:
  119.                this.iWindow = new OWEnterName(false);
  120.                this.prMenuItem = ClusterzL.miMenu;
  121.                break;
  122.             case ClusterzL.miEnterNewName:
  123.                this.iWindow = new OWEnterName(true);
  124.                (this.iWindow as OWEnterName).prName = "";
  125.                this.prMenuItem = ClusterzL.miLastWindow;
  126.                break;
  127.             case ClusterzL.miMenu:
  128.                iShowDemo = true;
  129.                switch(ClusterzL.iMP.State)
  130.                {
  131.                   case OMultiplayer.stNone:
  132.                      ClusterzL.iMP.Init(ClusterzL.sDomain,ClusterzL.sServer,ClusterzL.sZone,ClusterzL.sXTName,ClusterzL.iGAME.prPlayerName);
  133.                      break;
  134.                   case OMultiplayer.stConnectionError:
  135.                      if(ClusterzL.iMP.prErrorsCount < 5)
  136.                      {
  137.                         ClusterzL.iMP.State = OMultiplayer.stNone;
  138.                         ClusterzL.iMP.Init(ClusterzL.sDomain,ClusterzL.sServer,ClusterzL.sZone,ClusterzL.sXTName,ClusterzL.iGAME.prPlayerName);
  139.                      }
  140.                }
  141.                this.iWindow = new OWMenu();
  142.                this.prMenuItem = ClusterzL.miNullWindow;
  143.                break;
  144.             case ClusterzL.miCommingSoon:
  145.                this.iWindow = new OAlert(ClusterzL.OWCommingSoon,null);
  146.                this.prMenuItem = ClusterzL.miLastWindow;
  147.                break;
  148.             case ClusterzL.miChoosePlayer:
  149.                this.iWindow = new OWChoosePlayer();
  150.                this.prMenuItem = ClusterzL.miMenu;
  151.                break;
  152.             case ClusterzL.miDeletePlayerConfirm:
  153.                this.iWindow = new OAlert(ClusterzL.OWDeletePlayerConfirm,[ClusterzL.miDeletePlayer,ClusterzL.miLastWindow]);
  154.                this.prMenuItem = ClusterzL.miLastWindow;
  155.                break;
  156.             case ClusterzL.miDeletePlayer:
  157.                ClusterzL.iGAME.DeletePlayer(ClusterzL.iGAME.prPlayerName);
  158.                if(ClusterzL.iGAME.prPlayerName != "")
  159.                {
  160.                   this.OnMenuItem();
  161.                   return;
  162.                }
  163.                this.iWindow = new OWEnterName(false);
  164.                this.prMenuItem = ClusterzL.miLastWindow;
  165.                break;
  166.             case ClusterzL.miOptions:
  167.                this.iWindow = new OWOptions();
  168.                this.prMenuItem = ClusterzL.miLastWindow;
  169.                break;
  170.             case ClusterzL.miGlobalScores:
  171.                this.iWindow = new OWHighScores();
  172.                this.prMenuItem = ClusterzL.miLastWindow;
  173.                break;
  174.             case ClusterzL.miDeleteScoresConfirm:
  175.                this.iWindow = new OAlert(ClusterzL.OWDeleteScoresConfirm,[ClusterzL.miDeleteScores,ClusterzL.miLastWindow]);
  176.                this.prMenuItem = ClusterzL.miLastWindow;
  177.                break;
  178.             case ClusterzL.miDeleteScores:
  179.                _loc3_ = this.getChildAt(this.numChildren - 1) as OWHighScores;
  180.                this.OnMenuItem();
  181.                return;
  182.             case ClusterzL.miPlayGame:
  183.                if(ClusterzL.iGAME.prLevel > 0 || !iShowDemo)
  184.                {
  185.                   ClusterzL.iGAME.Start();
  186.                   this.iBang.Clear();
  187.                   this.iWindow = new OWGame(this.iBang,this.getChildIndex(this.iBang),false);
  188.                   this.prMenuItem = ClusterzL.miMenu;
  189.                }
  190.                else
  191.                {
  192.                   this.State = stInstruction;
  193.                   this.iWindow = new OWInstructions();
  194.                   this.iShowDemo = false;
  195.                   this.prMenuItem = ClusterzL.miPlayGame;
  196.                }
  197.                break;
  198.             case ClusterzL.miInstructions:
  199.                this.State = stInstruction;
  200.                this.iWindow = new OWInstructions();
  201.                this.prMenuItem = ClusterzL.miLastWindow;
  202.          }
  203.          this.addChild(this.iWindow);
  204.       }
  205.       
  206.       override public function OnPress(param1:Event, param2:*) : void
  207.       {
  208.          if(param1 == null)
  209.          {
  210.             this.prMenuItem = param2;
  211.          }
  212.       }
  213.       
  214.       private function InitImageCache() : void
  215.       {
  216.          var _loc1_:Number = NaN;
  217.          var _loc2_:int = 0;
  218.          var _loc3_:int = 0;
  219.          ClusterzL.iCache = new OCache();
  220.          _loc3_ = 0;
  221.          _loc1_ = 2;
  222.          while(_loc1_ <= 20)
  223.          {
  224.             _loc2_ = 0;
  225.             while(_loc2_ < OBubble.iColorsCount)
  226.             {
  227.                ClusterzL.iCache.SetArrItem("Bubble",_loc3_,OBubble.MakeBubble([null,_loc1_ * 0.97,_loc1_ / 91 * 3,_loc2_]));
  228.                _loc3_++;
  229.                _loc2_++;
  230.             }
  231.             _loc1_ += 0.5;
  232.          }
  233.          _loc3_ = 0;
  234.          _loc1_ = 2;
  235.          while(_loc1_ <= 20)
  236.          {
  237.             _loc2_ = 0;
  238.             while(_loc2_ < OBubble.iColorsCount)
  239.             {
  240.                ClusterzL.iCache.SetArrItem("Shadow",_loc3_,OBubble.MakeShadow([null,_loc1_,_loc1_ / 91 * 3,_loc2_]));
  241.                _loc3_++;
  242.                _loc2_++;
  243.             }
  244.             _loc1_ += 0.5;
  245.          }
  246.       }
  247.       
  248.       override protected function OnDeactivate(param1:Event) : void
  249.       {
  250.          ClusterzL.iGAME.SaveCache();
  251.       }
  252.       
  253.       override public function OnEnterFrame(param1:Event) : void
  254.       {
  255.          super.OnEnterFrame(param1);
  256.          if(!(this.iWindow is OWGame))
  257.          {
  258.             if(Math.random() < 0.02)
  259.             {
  260.                this.iBang.MakeFirework0();
  261.             }
  262.          }
  263.          ClusterzL.iMP.OnEnterFrame();
  264.          if(ClusterzL.sDebug)
  265.          {
  266.             OSystem.iUserText1 = " : " + ClusterzL.iMP.State.toString() + " : " + ClusterzL.iMP.prActiveRoomID.toString() + " " + ClusterzL.iMP.prPlayerID.toString() + " : " + ClusterzL.iMP.prError + " : " + OGlobal.Domain;
  267.          }
  268.          if(this.iWindow)
  269.          {
  270.             if(this.iWindow.prAnimation)
  271.             {
  272.                return;
  273.             }
  274.             if(!this.iWindow.prVisible)
  275.             {
  276.                this.removeChild(this.iWindow);
  277.                this.iWindow.Free();
  278.                this.iWindow = null;
  279.                this.OnMenuItem();
  280.             }
  281.             else if(!this.iWindow.prActive)
  282.             {
  283.                this.OnMenuItem();
  284.             }
  285.          }
  286.          if(State == stNormal && Boolean(iBang))
  287.          {
  288.             iBang.OnEnterFrame(null);
  289.          }
  290.       }
  291.       
  292.       private function MakeBackgroundImage() : BitmapData
  293.       {
  294.          var _loc1_:Sprite = null;
  295.          var _loc2_:Matrix = null;
  296.          var _loc3_:int = 0;
  297.          var _loc4_:BitmapData = null;
  298.          _loc1_ = new Sprite();
  299.          _loc2_ = new Matrix();
  300.          _loc3_ = OGlobal.StageRect.height;
  301.          _loc2_.createGradientBox(50,_loc3_,Math.PI / 2);
  302.          _loc1_.graphics.beginGradientFill(GradientType.LINEAR,[4954918,12709283],[1,1],[0,255],_loc2_);
  303.          _loc1_.graphics.drawRect(0,0,50,_loc3_);
  304.          (_loc4_ = new BitmapData(50,_loc3_,false,0)).draw(_loc1_);
  305.          return _loc4_;
  306.       }
  307.    }
  308. }
  309.