home *** CD-ROM | disk | FTP | other *** search
- class Game extends MovieClip
- {
- var __nScore;
- var mScore;
- var __bPause;
- var btMoreGame;
- var btAddGame;
- var btDownload;
- var btHighScore;
- var btPlay;
- var btHelp;
- var pKnight;
- var mMid;
- var mClip;
- var nTime_id;
- var nKill;
- var nDays;
- var aEnemy;
- var onEnterFrame;
- var mGround;
- var mDay;
- var nTime = 0;
- var nTime_th = 0;
- static var nInterval = 1000;
- static var nG = 2;
- function Game()
- {
- super();
- stopAllSounds();
- Common.clearAllClip(_root);
- Common.clearAllClip(this);
- Global.MUSIC = new Sound(_root.createEmptyMovieClip("mMusic",_root.getNextHighestDepth()));
- Global.SOUND = new Sound(this);
- Global.GAME = this;
- }
- function get nScore()
- {
- return this.__nScore;
- }
- function set nScore(_nScore)
- {
- this.__nScore = int(_nScore);
- this.__nScore < 0 && (this.__nScore = 0);
- this.mScore.sTxt = "SCORE: " + this.__nScore;
- }
- function get bPause()
- {
- return this.__bPause;
- }
- function set bPause(_bPause)
- {
- if(this.__bPause != _bPause)
- {
- this.__bPause = _bPause;
- !this.__bPause ? this.run() : this.pause();
- }
- }
- function init()
- {
- Global.playMusic("sdMusic",0,999);
- _root.stop();
- this._x = this._y = 0;
- Common.mask();
- this.gotoAndStop("menu");
- }
- function inMenu()
- {
- this.bPause = false;
- Common.clearAllClip(this);
- var _loc3_ = new Array("btPlay","btHelp","btHighScore","btDownload","btMoreGame","btAddGame");
- var _loc6_ = new Array("PLAY GAME","INSTRUCTIONS","VIEW HIGHSCORES","DOWNLOAD GAMES","MORE ONLINE GAMES","ADD THIS GAME TO YOUR SITE");
- var _loc7_ = "left";
- var _loc8_ = 30;
- var _loc10_ = 50;
- var _loc9_ = 250;
- var _loc2_ = 0;
- while(_loc2_ < _loc3_.length)
- {
- this.attachMovie("Btn",_loc3_[_loc2_],this.getNextHighestDepth(),{sTxt:_loc6_[_loc2_],autoSize:_loc7_,_x:_loc10_,_y:_loc9_ + _loc2_ * _loc8_});
- _loc2_ = _loc2_ + 1;
- }
- this.btMoreGame.press = function()
- {
- Global.FWGURL();
- };
- this.btAddGame.press = function()
- {
- Global.ADDGAME();
- };
- this.btDownload.press = function()
- {
- Global.DOWNLOAD();
- };
- this.btHighScore.press = function()
- {
- Global.VIEWSCORE();
- };
- this.btPlay.release = function()
- {
- if(Global.LOAD() != undefined)
- {
- fwg.Human.aKey = Global.LOAD();
- Common.mask();
- Global.GAME.gotoAndStop("loading");
- }
- else
- {
- Global.SAVE(fwg.Human.aKey);
- Common.mask();
- Global.GAME.gotoAndStop("help");
- }
- };
- this.btHelp.release = function()
- {
- if(Global.LOAD() != undefined)
- {
- fwg.Human.aKey = Global.LOAD().concat();
- }
- Common.mask();
- Global.GAME.gotoAndStop("help");
- };
- if(this.pKnight._x == undefined)
- {
- this.mMid._x = 0;
- this.pKnight = Common.addClip("fwg.Knight","mKnight",this.mClip,{_x:320,_y:350},-1);
- }
- this.pKnight.walk(1);
- clearInterval(this.nTime_id);
- this.nTime_id = setInterval(this,"step_time",Game.nInterval);
- }
- function inCredits()
- {
- Common.clearAllClip(this);
- Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"MUSIC CREDITS",_obFormat:{align:"center",size:60}});
- Common.addClip("Btn",null,this,{_x:Global.WIDTH - 60,_y:Global.HEIGHT - 30,sTxt:"MENU",autoSize:"right",press:function()
- {
- Common.mask();
- Global.GAME.gotoAndStop("menu");
- }});
- this.pKnight.walk(1);
- }
- function inHelp()
- {
- Common.clearAllClip(this);
- Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"INSTRUCTIONS",_obFormat:{align:"center",size:60}});
- this.pKnight.stand();
- }
- function inSetting()
- {
- Common.clearAllClip(this);
- Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"KEY SETTINGS",_obFormat:{align:"center",size:60}});
- Common.addClip("Btn",null,this,{_x:50,_y:Global.HEIGHT - 30,sTxt:"BACK",press:function()
- {
- Global.SAVE(fwg.Human.aKey);
- Common.mask();
- Global.GAME.gotoAndStop("help");
- }});
- Common.addClip("Btn",null,this,{_x:Global.WIDTH - 50,_y:Global.HEIGHT - 30,sTxt:"MENU",autoSize:"right",press:function()
- {
- Global.SAVE(fwg.Human.aKey);
- Common.mask();
- Global.GAME.gotoAndStop("menu");
- }});
- this.pKnight.walk(1);
- }
- function inLoading()
- {
- this.bPause = true;
- var _loc2_ = Global.LOAD();
- for(var _loc3_ in _loc2_)
- {
- if(_loc2_[_loc3_] != fwg.Human.aKey[_loc3_])
- {
- Global.SAVE(fwg.Human.aKey);
- break;
- }
- }
- Common.clearAllClip(this);
- this.gotoAndStop("playing");
- }
- function inPlaying()
- {
- Common.clearAllClip(this);
- this.mClip._x = 0;
- this.mClip._y = 0;
- this.nTime = 0;
- this.nScore = 0;
- this.nKill = 0;
- this.nDays = 1;
- this.mMid._x = 0;
- this.aEnemy = new Array();
- this.pKnight = Common.addClip("fwg.Knight","mKnight",this.mClip,{_x:300,_y:200});
- this.pKnight.pCtrl = new fwg.Human();
- this.bPause = false;
- }
- function inNextLevel()
- {
- this.bPause = true;
- Common.clearAllClip(this);
- Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"LEVEL COMPLETE",_obFormat:{align:"center",size:60}});
- Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:150,sTxt:"SCORE: " + this.nScore,_obFormat:{align:"center",size:50}});
- Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:200,sTxt:"SUBMIT SCORE",autoSize:"center",press:function()
- {
- Common.addClip("PopUp",null,_root,{sFrame:"submit",aSt:["",Global.GAME.nScore]});
- this._visible = false;
- }});
- Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:250,sTxt:"NEXT LEVEL",autoSize:"center",press:function()
- {
- Common.mask();
- Global.GAME.gotoAndStop("loading");
- }});
- Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:350,sTxt:"MENU",autoSize:"center",press:function()
- {
- Common.mask();
- Global.GAME.gotoAndStop("menu");
- }});
- }
- function inGameOver()
- {
- Common.clearAllClip(this);
- Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:80,sTxt:"GAME OVER",_obFormat:{align:"center",size:60}});
- Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:150,sTxt:"SCORE: " + this.nScore,_obFormat:{align:"center",size:30}});
- Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:185,sTxt:"DAYS: " + this.nDays,_obFormat:{align:"center"}});
- Common.addClip("Txt",null,this,{_x:Global.WIDTH / 2,_y:220,sTxt:"KILLS: " + this.nKill,_obFormat:{align:"center"}});
- Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:255,sTxt:"SUBMIT SCORE",autoSize:"center",press:function()
- {
- Common.addClip("PopUp",null,_root,{sFrame:"submit",aSt:["",Global.GAME.nScore]});
- this._visible = false;
- }});
- Common.addClip("Btn",null,this,{_x:Global.WIDTH / 2,_y:290,sTxt:"TRY AGAIN",autoSize:"center",press:function()
- {
- Global.GAME.nScore = 0;
- Common.mask();
- Global.GAME.gotoAndStop("loading");
- }});
- Common.addClip("Btn",null,this,{_x:50,_y:350,sTxt:"MENU",autoSize:"left",press:function()
- {
- Common.mask();
- Global.GAME.gotoAndStop("menu");
- }});
- Common.addClip("Btn",null,this,{_x:50,_y:380,sTxt:"DOWNLOAD GAMES",autoSize:"left",press:function()
- {
- Global.DOWNLOAD();
- }});
- Common.addClip("Btn",null,this,{_x:50,_y:410,sTxt:"MORE ONLINE GAMES",autoSize:"left",press:function()
- {
- Global.FWGURL();
- }});
- Common.addClip("Btn",null,this,{_x:50,_y:440,sTxt:"ADD THIS GAME TO YOUR SITE",autoSize:"left",press:function()
- {
- Global.ADDGAME();
- }});
- if(this.pKnight._x == undefined)
- {
- this.mMid._x = 0;
- this.pKnight = Common.addClip("fwg.Knight","mKnight",this.mClip,{_x:320,_y:350},-1);
- this.pKnight.walk(1);
- }
- clearInterval(this.nTime_id);
- this.nTime_id = setInterval(this,"step_time",Game.nInterval);
- }
- function inGameWin()
- {
- this.bPause = true;
- Common.clearAllClip(this);
- }
- function run()
- {
- clearInterval(this.nTime_id);
- this.nTime_id = setInterval(this,"step_time",Game.nInterval);
- this.onEnterFrame = function()
- {
- Global.GAME.step();
- };
- }
- function pause()
- {
- clearInterval(this.nTime_id);
- delete this.onEnterFrame;
- }
- function step_time()
- {
- this.nTime = this.nTime + 1;
- if(this.nTime % 30 == 0)
- {
- this.mGround.cacheAsBitmap = false;
- this.mGround.play();
- this.mMid.cacheAsBitmap = false;
- for(var _loc2_ in this.mMid)
- {
- this.mMid[_loc2_].play();
- }
- this.nDays += 0.25;
- this.nDays = int(this.nDays * 10) / 10;
- this.mDay.sTxt = "DAYS: " + int(this.nDays);
- }
- }
- function step()
- {
- if(this._currentframe == 46)
- {
- this.nTime_th <= 100000 ? this.nTime_th++ : (this.nTime_th = 1);
- if(this.nTime_th % 30 == 0)
- {
- if(this.aEnemy.length < 5 + int(this.nTime / 30))
- {
- Common.addClip("fwg.Enemy_0","Enemy_0",this.mClip,{_x:- this.mClip._x - 50,_y:300});
- Common.addClip("fwg.Enemy_0","Enemy_0",this.mClip,{_x:- this.mClip._x + Global.WIDTH + 50,_y:300});
- if(random(100) > 90)
- {
- 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});
- }
- }
- }
- }
- }
- static function hitGround(x, y, _m1, _m2)
- {
- var _loc1_ = {x:x,y:y};
- _m1.localToGlobal(_loc1_);
- return _m2.hitTest(_loc1_.x,_loc1_.y,true);
- }
- static function getYhit(x, y, _m1, _m2)
- {
- var _loc1_ = {x:x,y:y};
- _m1.localToGlobal(_loc1_);
- y = _loc1_.y;
- var _loc3_ = false;
- var _loc2_ = 0;
- while(_loc2_ < 300)
- {
- if(_loc3_)
- {
- if(!_m2.hitTest(_loc1_.x,_loc1_.y,true))
- {
- break;
- }
- _loc1_.y -= 0.5;
- }
- else if(_m2.hitTest(_loc1_.x,_loc1_.y,true))
- {
- _loc3_ = true;
- }
- else
- {
- _loc1_.y += 0.5;
- }
- _loc2_ = _loc2_ + 1;
- }
- return _loc1_.y - y;
- }
- static function getBetween(x, y, _m1, _m2)
- {
- var _loc1_ = {x:x,y:y};
- _m1.localToGlobal(_loc1_);
- y = _loc1_.y;
- var _loc3_ = undefined;
- var _loc2_ = 20;
- while(_loc2_ > 1)
- {
- if(_m2.hitTest(_loc1_.x,_loc1_.y,true))
- {
- _loc3_ = -1;
- }
- else
- {
- _loc3_ = 1;
- }
- _loc1_.y += _loc2_ * _loc3_;
- _loc2_ /= 2;
- }
- return _loc1_.y;
- }
- }
-