home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Acao / fwg_knight.swf / scripts / __Packages / Game.as < prev    next >
Encoding:
Text File  |  2008-08-28  |  11.5 KB  |  375 lines

  1. class Game extends MovieClip
  2. {
  3.    var __nScore;
  4.    var mScore;
  5.    var __bPause;
  6.    var btMoreGame;
  7.    var btAddGame;
  8.    var btDownload;
  9.    var btHighScore;
  10.    var btPlay;
  11.    var btHelp;
  12.    var pKnight;
  13.    var mMid;
  14.    var mClip;
  15.    var nTime_id;
  16.    var nKill;
  17.    var nDays;
  18.    var aEnemy;
  19.    var onEnterFrame;
  20.    var mGround;
  21.    var mDay;
  22.    var nTime = 0;
  23.    var nTime_th = 0;
  24.    static var nInterval = 1000;
  25.    static var nG = 2;
  26.    function Game()
  27.    {
  28.       super();
  29.       stopAllSounds();
  30.       Common.clearAllClip(_root);
  31.       Common.clearAllClip(this);
  32.       Global.MUSIC = new Sound(_root.createEmptyMovieClip("mMusic",_root.getNextHighestDepth()));
  33.       Global.SOUND = new Sound(this);
  34.       Global.GAME = this;
  35.    }
  36.    function get nScore()
  37.    {
  38.       return this.__nScore;
  39.    }
  40.    function set nScore(_nScore)
  41.    {
  42.       this.__nScore = int(_nScore);
  43.       this.__nScore < 0 && (this.__nScore = 0);
  44.       this.mScore.sTxt = "SCORE: " + this.__nScore;
  45.    }
  46.    function get bPause()
  47.    {
  48.       return this.__bPause;
  49.    }
  50.    function set bPause(_bPause)
  51.    {
  52.       if(this.__bPause != _bPause)
  53.       {
  54.          this.__bPause = _bPause;
  55.          !this.__bPause ? this.run() : this.pause();
  56.       }
  57.    }
  58.    function init()
  59.    {
  60.       Global.playMusic("sdMusic",0,999);
  61.       _root.stop();
  62.       this._x = this._y = 0;
  63.       Common.mask();
  64.       this.gotoAndStop("menu");
  65.    }
  66.    function inMenu()
  67.    {
  68.       this.bPause = false;
  69.       Common.clearAllClip(this);
  70.       var _loc3_ = new Array("btPlay","btHelp","btHighScore","btDownload","btMoreGame","btAddGame");
  71.       var _loc6_ = new Array("PLAY GAME","INSTRUCTIONS","VIEW HIGHSCORES","DOWNLOAD GAMES","MORE ONLINE GAMES","ADD THIS GAME TO YOUR SITE");
  72.       var _loc7_ = "left";
  73.       var _loc8_ = 30;
  74.       var _loc10_ = 50;
  75.       var _loc9_ = 250;
  76.       var _loc2_ = 0;
  77.       while(_loc2_ < _loc3_.length)
  78.       {
  79.          this.attachMovie("Btn",_loc3_[_loc2_],this.getNextHighestDepth(),{sTxt:_loc6_[_loc2_],autoSize:_loc7_,_x:_loc10_,_y:_loc9_ + _loc2_ * _loc8_});
  80.          _loc2_ = _loc2_ + 1;
  81.       }
  82.       this.btMoreGame.press = function()
  83.       {
  84.          Global.FWGURL();
  85.       };
  86.       this.btAddGame.press = function()
  87.       {
  88.          Global.ADDGAME();
  89.       };
  90.       this.btDownload.press = function()
  91.       {
  92.          Global.DOWNLOAD();
  93.       };
  94.       this.btHighScore.press = function()
  95.       {
  96.          Global.VIEWSCORE();
  97.       };
  98.       this.btPlay.release = function()
  99.       {
  100.          if(Global.LOAD() != undefined)
  101.          {
  102.             fwg.Human.aKey = Global.LOAD();
  103.             Common.mask();
  104.             Global.GAME.gotoAndStop("loading");
  105.          }
  106.          else
  107.          {
  108.             Global.SAVE(fwg.Human.aKey);
  109.             Common.mask();
  110.             Global.GAME.gotoAndStop("help");
  111.          }
  112.       };
  113.       this.btHelp.release = function()
  114.       {
  115.          if(Global.LOAD() != undefined)
  116.          {
  117.             fwg.Human.aKey = Global.LOAD().concat();
  118.          }
  119.          Common.mask();
  120.          Global.GAME.gotoAndStop("help");
  121.       };
  122.       if(this.pKnight._x == undefined)
  123.       {
  124.          this.mMid._x = 0;
  125.          this.pKnight = Common.addClip("fwg.Knight","mKnight",this.mClip,{_x:320,_y:350},-1);
  126.       }
  127.       this.pKnight.walk(1);
  128.       clearInterval(this.nTime_id);
  129.       this.nTime_id = setInterval(this,"step_time",Game.nInterval);
  130.    }
  131.    function inCredits()
  132.    {
  133.       Common.clearAllClip(this);
  134.       Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"MUSIC CREDITS",_obFormat:{align:"center",size:60}});
  135.       Common.addClip("Btn",null,this,{_x:Global.WIDTH - 60,_y:Global.HEIGHT - 30,sTxt:"MENU",autoSize:"right",press:function()
  136.       {
  137.          Common.mask();
  138.          Global.GAME.gotoAndStop("menu");
  139.       }});
  140.       this.pKnight.walk(1);
  141.    }
  142.    function inHelp()
  143.    {
  144.       Common.clearAllClip(this);
  145.       Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"INSTRUCTIONS",_obFormat:{align:"center",size:60}});
  146.       this.pKnight.stand();
  147.    }
  148.    function inSetting()
  149.    {
  150.       Common.clearAllClip(this);
  151.       Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"KEY SETTINGS",_obFormat:{align:"center",size:60}});
  152.       Common.addClip("Btn",null,this,{_x:50,_y:Global.HEIGHT - 30,sTxt:"BACK",press:function()
  153.       {
  154.          Global.SAVE(fwg.Human.aKey);
  155.          Common.mask();
  156.          Global.GAME.gotoAndStop("help");
  157.       }});
  158.       Common.addClip("Btn",null,this,{_x:Global.WIDTH - 50,_y:Global.HEIGHT - 30,sTxt:"MENU",autoSize:"right",press:function()
  159.       {
  160.          Global.SAVE(fwg.Human.aKey);
  161.          Common.mask();
  162.          Global.GAME.gotoAndStop("menu");
  163.       }});
  164.       this.pKnight.walk(1);
  165.    }
  166.    function inLoading()
  167.    {
  168.       this.bPause = true;
  169.       var _loc2_ = Global.LOAD();
  170.       for(var _loc3_ in _loc2_)
  171.       {
  172.          if(_loc2_[_loc3_] != fwg.Human.aKey[_loc3_])
  173.          {
  174.             Global.SAVE(fwg.Human.aKey);
  175.             break;
  176.          }
  177.       }
  178.       Common.clearAllClip(this);
  179.       this.gotoAndStop("playing");
  180.    }
  181.    function inPlaying()
  182.    {
  183.       Common.clearAllClip(this);
  184.       this.mClip._x = 0;
  185.       this.mClip._y = 0;
  186.       this.nTime = 0;
  187.       this.nScore = 0;
  188.       this.nKill = 0;
  189.       this.nDays = 1;
  190.       this.mMid._x = 0;
  191.       this.aEnemy = new Array();
  192.       this.pKnight = Common.addClip("fwg.Knight","mKnight",this.mClip,{_x:300,_y:200});
  193.       this.pKnight.pCtrl = new fwg.Human();
  194.       this.bPause = false;
  195.    }
  196.    function inNextLevel()
  197.    {
  198.       this.bPause = true;
  199.       Common.clearAllClip(this);
  200.       Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"LEVEL COMPLETE",_obFormat:{align:"center",size:60}});
  201.       Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:150,sTxt:"SCORE: " + this.nScore,_obFormat:{align:"center",size:50}});
  202.       Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:200,sTxt:"SUBMIT SCORE",autoSize:"center",press:function()
  203.       {
  204.          Common.addClip("PopUp",null,_root,{sFrame:"submit",aSt:["",Global.GAME.nScore]});
  205.          this._visible = false;
  206.       }});
  207.       Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:250,sTxt:"NEXT LEVEL",autoSize:"center",press:function()
  208.       {
  209.          Common.mask();
  210.          Global.GAME.gotoAndStop("loading");
  211.       }});
  212.       Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:350,sTxt:"MENU",autoSize:"center",press:function()
  213.       {
  214.          Common.mask();
  215.          Global.GAME.gotoAndStop("menu");
  216.       }});
  217.    }
  218.    function inGameOver()
  219.    {
  220.       Common.clearAllClip(this);
  221.       Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"GAME OVER",_obFormat:{align:"center",size:60}});
  222.       Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:150,sTxt:"SCORE: " + this.nScore,_obFormat:{align:"center",size:30}});
  223.       Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:185,sTxt:"DAYS: " + this.nDays,_obFormat:{align:"center"}});
  224.       Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:220,sTxt:"KILLS: " + this.nKill,_obFormat:{align:"center"}});
  225.       Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:255,sTxt:"SUBMIT SCORE",autoSize:"center",press:function()
  226.       {
  227.          Common.addClip("PopUp",null,_root,{sFrame:"submit",aSt:["",Global.GAME.nScore]});
  228.          this._visible = false;
  229.       }});
  230.       Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:290,sTxt:"TRY AGAIN",autoSize:"center",press:function()
  231.       {
  232.          Global.GAME.nScore = 0;
  233.          Common.mask();
  234.          Global.GAME.gotoAndStop("loading");
  235.       }});
  236.       Common.addClip("Btn",null,this,{_x:50,_y:350,sTxt:"MENU",autoSize:"left",press:function()
  237.       {
  238.          Common.mask();
  239.          Global.GAME.gotoAndStop("menu");
  240.       }});
  241.       Common.addClip("Btn",null,this,{_x:50,_y:380,sTxt:"DOWNLOAD GAMES",autoSize:"left",press:function()
  242.       {
  243.          Global.DOWNLOAD();
  244.       }});
  245.       Common.addClip("Btn",null,this,{_x:50,_y:410,sTxt:"MORE ONLINE GAMES",autoSize:"left",press:function()
  246.       {
  247.          Global.FWGURL();
  248.       }});
  249.       Common.addClip("Btn",null,this,{_x:50,_y:440,sTxt:"ADD THIS GAME TO YOUR SITE",autoSize:"left",press:function()
  250.       {
  251.          Global.ADDGAME();
  252.       }});
  253.       if(this.pKnight._x == undefined)
  254.       {
  255.          this.mMid._x = 0;
  256.          this.pKnight = Common.addClip("fwg.Knight","mKnight",this.mClip,{_x:320,_y:350},-1);
  257.          this.pKnight.walk(1);
  258.       }
  259.       clearInterval(this.nTime_id);
  260.       this.nTime_id = setInterval(this,"step_time",Game.nInterval);
  261.    }
  262.    function inGameWin()
  263.    {
  264.       this.bPause = true;
  265.       Common.clearAllClip(this);
  266.    }
  267.    function run()
  268.    {
  269.       clearInterval(this.nTime_id);
  270.       this.nTime_id = setInterval(this,"step_time",Game.nInterval);
  271.       this.onEnterFrame = function()
  272.       {
  273.          Global.GAME.step();
  274.       };
  275.    }
  276.    function pause()
  277.    {
  278.       clearInterval(this.nTime_id);
  279.       delete this.onEnterFrame;
  280.    }
  281.    function step_time()
  282.    {
  283.       this.nTime = this.nTime + 1;
  284.       if(this.nTime % 30 == 0)
  285.       {
  286.          this.mGround.cacheAsBitmap = false;
  287.          this.mGround.play();
  288.          this.mMid.cacheAsBitmap = false;
  289.          for(var _loc2_ in this.mMid)
  290.          {
  291.             this.mMid[_loc2_].play();
  292.          }
  293.          this.nDays += 0.25;
  294.          this.nDays = int(this.nDays * 10) / 10;
  295.          this.mDay.sTxt = "DAYS: " + int(this.nDays);
  296.       }
  297.    }
  298.    function step()
  299.    {
  300.       if(this._currentframe == 46)
  301.       {
  302.          this.nTime_th <= 100000 ? this.nTime_th++ : (this.nTime_th = 1);
  303.          if(this.nTime_th % 30 == 0)
  304.          {
  305.             if(this.aEnemy.length < 5 + int(this.nTime / 30))
  306.             {
  307.                Common.addClip("fwg.Enemy_0","Enemy_0",this.mClip,{_x:- this.mClip._x - 50,_y:300});
  308.                Common.addClip("fwg.Enemy_0","Enemy_0",this.mClip,{_x:- this.mClip._x + Global.WIDTH + 50,_y:300});
  309.                if(random(100) > 90)
  310.                {
  311.                   Common.addClip("fwg.Enemy_1","Enemy_1",this.mClip,{_x:(random(2) <= 0 ? - this.mClip._x - 300 : - this.mClip._x + Global.WIDTH + 300),_y:200});
  312.                }
  313.             }
  314.          }
  315.       }
  316.    }
  317.    static function hitGround(x, y, _m1, _m2)
  318.    {
  319.       var _loc1_ = {x:x,y:y};
  320.       _m1.localToGlobal(_loc1_);
  321.       return _m2.hitTest(_loc1_.x,_loc1_.y,true);
  322.    }
  323.    static function getYhit(x, y, _m1, _m2)
  324.    {
  325.       var _loc1_ = {x:x,y:y};
  326.       _m1.localToGlobal(_loc1_);
  327.       y = _loc1_.y;
  328.       var _loc3_ = false;
  329.       var _loc2_ = 0;
  330.       while(_loc2_ < 300)
  331.       {
  332.          if(_loc3_)
  333.          {
  334.             if(!_m2.hitTest(_loc1_.x,_loc1_.y,true))
  335.             {
  336.                break;
  337.             }
  338.             _loc1_.y -= 0.5;
  339.          }
  340.          else if(_m2.hitTest(_loc1_.x,_loc1_.y,true))
  341.          {
  342.             _loc3_ = true;
  343.          }
  344.          else
  345.          {
  346.             _loc1_.y += 0.5;
  347.          }
  348.          _loc2_ = _loc2_ + 1;
  349.       }
  350.       return _loc1_.y - y;
  351.    }
  352.    static function getBetween(x, y, _m1, _m2)
  353.    {
  354.       var _loc1_ = {x:x,y:y};
  355.       _m1.localToGlobal(_loc1_);
  356.       y = _loc1_.y;
  357.       var _loc3_ = undefined;
  358.       var _loc2_ = 20;
  359.       while(_loc2_ > 1)
  360.       {
  361.          if(_m2.hitTest(_loc1_.x,_loc1_.y,true))
  362.          {
  363.             _loc3_ = -1;
  364.          }
  365.          else
  366.          {
  367.             _loc3_ = 1;
  368.          }
  369.          _loc1_.y += _loc2_ * _loc3_;
  370.          _loc2_ /= 2;
  371.       }
  372.       return _loc1_.y;
  373.    }
  374. }
  375.