home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Esportes
/
CrossingCup.swf
/
scripts
/
__Packages
/
game.as
< prev
next >
Wrap
Text File
|
2007-12-11
|
26KB
|
854 lines
class game
{
static var G_START = 1;
static var G_WHISTLE = 2;
static var G_AIM = 3;
static var G_POWER = 4;
static var G_CORNERKICK = 5;
static var G_CORNERSHOOT = 6;
static var G_TRANSITION = 7;
static var G_TIMING = 8;
static var G_RECEIVING = 9;
static var G_SHOOTING = 10;
static var G_SHOOT = 11;
static var G_WINLOOSE = 12;
static var G_GAMEOVER = 13;
static var G_RESTART = 30;
static var GX_WHISTLE = 102;
static var GX_AIM = 103;
static var GX_RECEIVING = 109;
static var GX2_RECEIVING = 110;
static var GX_SHOOT = 111;
var kickerHint = false;
var keeperHint = false;
var AILevel = 0;
var purgegame = false;
function game(mc)
{
this.mcParent = mc;
this.setup3d();
this.playtime = 0;
this.gameon = true;
this.def_playtime = CSessionManager.ins().numPlayPerGame;
this.world.addEventListener(sandy.core.World3D.onRenderEVENT,this,this.renderWorld);
this.iRender = setInterval(this,"renderWorldnow",10);
EventCenter.access().addEventListener("gameevent",this);
this.kickerHint = false;
this.keeperHint = false;
var _loc2_ = new Object();
_loc2_.ob = this;
_loc2_.onKeyDown = function()
{
this.ob.cekkey();
};
Key.addListener(_loc2_);
}
function introgame(human)
{
this.gameon = true;
this.purgegame = false;
if(!this.cornercam)
{
this.switchcam();
}
this.keeper.setLevel(0);
this.kicker.setLevel(0);
this.AILevel = 0;
this.kickerHint = false;
this.keeperHint = false;
if(human)
{
this.AutoAim = false;
this.AutoKick = false;
this.AutoCatch = true;
if(CTournament.ins().tournamentPhase > 3)
{
this.keeper.setLevel(1);
this.AILevel = 1;
}
this.cornerkicker.setHuman(true);
if(CSessionManager.ins().firstTimeOffense)
{
CSessionManager.ins().firstTimeOffense = false;
_global.__DISPATCH({type:"inGameMenu",name:"showtuto"});
CSessionManager.ins().justEndTutorial = CSessionManager.ins().justEndTutorial + 1;
this.kickerHint = true;
}
else
{
_global.__DISPATCH({type:"inGameMenu",name:"hidetuto"});
}
}
else
{
this.AutoAim = true;
this.AutoKick = true;
this.AutoCatch = false;
if(CTournament.ins().tournamentPhase > 3)
{
this.kicker.setLevel(1);
this.AILevel = 1;
}
this.cornerkicker.setHuman(false);
if(CSessionManager.ins().firstTimeDefense)
{
CSessionManager.ins().firstTimeDefense = false;
_global.__DISPATCH({type:"inGameMenu",name:"showtuto"});
CSessionManager.ins().justEndTutorial = CSessionManager.ins().justEndTutorial + 1;
this.keeperHint = true;
}
else
{
_global.__DISPATCH({type:"inGameMenu",name:"hidetuto"});
}
}
this.mball.reset();
this.mball.show();
this.carrow.hide();
this.kicker.restart();
this.kicker.hide();
this.keeper.restart();
this.keeper.hide();
this.cornerkicker.restart();
this.cornerkicker.show();
}
function initgame()
{
this.pumpgame(game.G_START);
}
function startgame()
{
this.xrot = 0;
this.pumpgame(game.GX_WHISTLE);
}
function endgame()
{
this.gameon = false;
SoundManager.ins().fadeAmbience(false);
this.GamePhase = -1;
}
function gameevent(event)
{
if(this.purgegame)
{
return undefined;
}
switch(event.param)
{
case "cheat":
var _loc3_ = CTournament.ins().currentMatch;
if(CTeamManager.ins().currentTeam == _loc3_.team1)
{
if(event.win)
{
_loc3_.addScorea(1,0);
}
else
{
_loc3_.addScorea(0,1);
}
}
else if(event.win)
{
_loc3_.addScorea(0,1);
}
else
{
_loc3_.addScorea(1,0);
}
_loc3_.round = 2;
_loc3_.totalkick1 = 0;
_loc3_.totalkick2 = 0;
this.playtime = this.def_playtime * 2;
this.pumpgame(game.G_RESTART);
break;
case "dialogendgame":
this.KillTheGame();
_global.__DISPATCH({type:"inGameMenu",name:"stopdialog"});
break;
case "dialognoendgame":
_global.__DISPATCH({type:"inGameMenu",name:"stopdialog"});
break;
case "skiptutorial":
CSessionManager.ins().firstTimeOffense = false;
CSessionManager.ins().firstTimeDefense = false;
CSessionManager.ins().justEndTutorial = 0;
this.kickerHint = false;
this.keeperHint = false;
_global.__DISPATCH({type:"inGameMenu",name:"hidetuto"});
_global.__DISPATCH({type:"inGameHelp",param:"stop"});
this.pumpgame(game.G_WHISTLE);
break;
case "playtutorial":
this.pumpgame(game.G_WHISTLE);
break;
case "startgamealready":
if(this.AutoAim)
{
event.obyek.indicator._visible = true;
}
else
{
event.obyek.indicator._visible = false;
}
this.startgame();
break;
case "playambience":
break;
case "cornerkick":
this.pumpgame(game.G_CORNERSHOOT);
break;
case "transition":
this.pumpgame(game.G_TRANSITION);
break;
case "finishtransition":
this.pumpgame(game.G_TIMING);
break;
case "shooting":
this.pumpgame(game.G_SHOOTING);
break;
case "shoot":
this.pumpgame(game.GX_SHOOT);
break;
case "headingcontact":
var _loc5_ = this.kicker.getPosition();
var _loc4_ = this.mball.getPosition();
var _loc9_ = Math.abs(_loc5_.x - _loc4_.x);
var _loc8_ = Math.abs(_loc5_.y + _loc4_.y + 2.5);
var _loc7_ = Math.abs(_loc5_.z - _loc4_.z);
if(_loc9_ < 2 && _loc8_ < 0.8 && _loc7_ < 0.5)
{
this.kicker.makeshoot();
}
break;
case "volleycontact":
_loc5_ = this.kicker.getPosition();
_loc4_ = this.mball.getPosition();
_loc9_ = Math.abs(_loc5_.x - _loc4_.x);
_loc8_ = Math.abs(_loc5_.y - _loc4_.y);
_loc7_ = Math.abs(_loc5_.z - _loc4_.z);
if(_loc9_ < 1.5 && _loc8_ < 1.5 && _loc7_ < 1)
{
this.kicker.makeshoot();
}
break;
case "backflipcontact":
_loc5_ = this.kicker.getPosition();
_loc4_ = this.mball.getPosition();
_loc9_ = Math.abs(_loc5_.x - _loc4_.x);
_loc8_ = Math.abs(_loc5_.y + _loc4_.y + 2);
_loc7_ = Math.abs(_loc5_.z - _loc4_.z);
if(_loc9_ < 2 && _loc8_ < 1 && _loc7_ < 1.1)
{
this.kicker.makeshoot();
}
break;
case "divecontact":
_loc5_ = this.kicker.getPosition();
_loc4_ = this.mball.getPosition();
_loc9_ = Math.abs(_loc5_.x - _loc4_.x);
_loc8_ = Math.abs(_loc5_.y + _loc4_.y);
_loc7_ = Math.abs(_loc5_.z - _loc4_.z);
if(_loc9_ < 5 && _loc8_ < 1.5 && _loc7_ < 1)
{
this.kicker.makeshoot();
}
break;
case "chestvolleycontact":
_loc5_ = this.kicker.getPosition();
_loc4_ = this.mball.getPosition();
_loc9_ = Math.abs(_loc5_.x - _loc4_.x);
_loc8_ = Math.abs(_loc5_.y + _loc4_.y + 0.5);
_loc7_ = Math.abs(_loc5_.z - _loc4_.z);
if(_loc9_ < 1 && _loc8_ < 2 && _loc7_ < 1.2)
{
this.mball.haltedit();
SoundManager.ins().playKick();
}
break;
case "chestvolleykick":
if(this.mball.halted)
{
this.kicker.makeshoot();
}
break;
case "heading":
case "volley":
case "dive":
case "backflip":
case "chestvolley":
this.kicker.toidle();
break;
case "ballout":
if(this.GamePhase != game.G_WINLOOSE)
{
this.keeper.win();
this.kicker.loose();
this.pumpgame(game.G_WINLOOSE);
}
break;
case "goal":
this.keeper.loose();
this.kicker.win();
SoundManager.ins().playVictory();
if(!this.kickerHint && !this.keeperHint)
{
CTournament.ins().currentMatch.addScore();
_global.__DISPATCH({type:"changeScore"});
}
this.pumpgame(game.G_WINLOOSE);
break;
case "loose":
this.keeper.win();
this.kicker.loose();
this.pumpgame(game.G_WINLOOSE);
break;
case "enteringhurdle":
if(!this.keeper.cekGoal(this.mball))
{
this.mball.deflect();
this.mball.ingoalsequence = 5;
this.kicker.loose();
this.pumpgame(game.G_WINLOOSE);
}
else
{
SoundManager.ins().playGoal();
_global.__DISPATCH({type:"gameevent",param:"goal"});
this.mball.ingoalsequence = 4;
}
}
}
function setIncomingBallTimer()
{
var _loc2_ = 0;
this.AILevel != 0 ? (_loc2_ = 1700) : (_loc2_ = 2200);
if(this.kickerHint)
{
_loc2_ += 2500;
}
this.iIncomingBall = setInterval(this,"IncomingBall",_loc2_);
}
function IncomingBall()
{
clearInterval(this.iIncomingBall);
if(!this.kickerHint && !this.keeperHint)
{
this.pumpgame(game.G_RECEIVING);
}
}
function endwhistle()
{
this.pumpgame(game.GX_AIM);
}
function pumpgame(phase)
{
if(phase == undefined)
{
this.GamePhase = this.GamePhase + 1;
phase = this.GamePhase;
}
else
{
this.GamePhase = phase;
}
switch(phase)
{
case game.G_START:
this.playtime = 0;
break;
case game.GX_WHISTLE:
if(CSessionManager.ins().firstTimer)
{
_global.__DISPATCH({type:"inGameHelp",param:"firsttimer"});
CSessionManager.ins().firstTimer = false;
return undefined;
}
if(CSessionManager.ins().justEndTutorial == 3)
{
_global.__DISPATCH({type:"inGameHelp",param:"endtutorial"});
_global.__DISPATCH({type:"inGameMenu",name:"hidetuto"});
return undefined;
}
if(CSessionManager.ins().justEndTutorial == 2)
{
CSessionManager.ins().justEndTutorial = CSessionManager.ins().justEndTutorial + 1;
}
this.pumpgame(game.G_WHISTLE);
break;
case game.G_WHISTLE:
if(this.kickerHint)
{
_global.__DISPATCH({type:"inGameHelp",param:"aiming"});
}
if(this.keeperHint)
{
_global.__DISPATCH({type:"inGameHelp",param:"keeperwait"});
}
SoundManager.ins().playWhistle();
EventCenter.access().addEventListener("endwhistle",this);
if(!this.AutoKick)
{
this.carrow.show();
this.mball.hide();
}
else
{
this.mball.show();
this.carrow.hide();
}
this.cornerkicker.show();
break;
case game.GX_AIM:
if(!this.kickerHint && !this.keeperHint && CSessionManager.ins().justEndTutorial != 3)
{
this.pumpgame(game.G_AIM);
}
break;
case game.G_POWER:
if(this.kickerHint)
{
_global.__DISPATCH({type:"inGameHelp",param:"power"});
}
this.carrow.powering();
break;
case game.G_CORNERKICK:
this.carrow.unpowering();
this.mball.show();
this.carrow.hide();
this.cornerkicker.setHuman(false);
this.cornerkicker.kick();
break;
case game.G_CORNERSHOOT:
if(this.kickerHint)
{
_global.__DISPATCH({type:"inGameHelp",param:"cross"});
}
SoundManager.ins().playKick();
this.mball.shoot(this.carrow.power,this.carrow.rx,this.carrow.ry);
break;
case game.G_TRANSITION:
this.mball.hide();
this.mcParent._parent.latar.gotoAndPlay(2);
this.mcParent._parent.indicator._visible = false;
this.mcParent._visible = false;
this.switchcam();
if(this.AutoKick)
{
this.kicker.startrun();
}
break;
case game.G_TIMING:
if(this.kickerHint)
{
_global.__DISPATCH({type:"inGameHelp",param:"moving"});
this.pumpgame(game.GX_RECEIVING);
}
if(this.keeperHint)
{
_global.__DISPATCH({type:"inGameHelp",param:"keepermove"});
}
if(!this.kickerHint && !this.keeperHint)
{
this.setIncomingBallTimer();
}
this.mcParent._visible = true;
this.kicker.show();
this.keeper.show();
if(this.AutoKick)
{
this.kicker.action();
this.kicker.setHuman(false);
this.keeper.setHuman(true);
}
else
{
this.kicker.setHuman(true);
this.keeper.setHuman(false);
}
break;
case game.GX_RECEIVING:
break;
case game.GX2_RECEIVING:
this.mball.show();
break;
case game.G_RECEIVING:
if(this.kickerHint)
{
this.setIncomingBallTimer();
}
this.mball.show();
if(this.AutoKick)
{
this.mball.startTrajectoryCounter(3);
}
break;
case game.G_SHOOTING:
this.mball.ingoalsequence = 1;
break;
case game.GX_SHOOT:
if(this.keeperHint)
{
_global.__DISPATCH({type:"inGameHelp",param:"keepercatch"});
}
else
{
this.pumpgame(game.G_SHOOT);
}
break;
case game.G_SHOOT:
SoundManager.ins().playKick();
this.kicker.setHuman(false);
if(this.AutoCatch)
{
this.keeper.catchball(this.mball);
this.keeper.startcatch();
}
break;
case game.G_WINLOOSE:
this.iCelebrate = setInterval(this,"endCelebrate",3000);
break;
case game.G_RESTART:
if(SoundManager.ins().goalplayed)
{
SoundManager.ins().fadeGoal(false);
}
this.mball.reset();
this.cornerkicker.hide();
this.kicker.setHuman(false);
this.kicker.hide();
this.keeper.setHuman(false);
this.keeper.hide();
this.mball.hide();
this.carrow.hide();
this.mcParent._parent.latar.gotoAndStop(1);
if(!this.cornercam)
{
this.switchcam();
}
if(!this.keeperHint && !this.kickerHint)
{
this.playtime = this.playtime + 1;
_global.__DISPATCH({type:"updateBallCounter"});
}
var _loc5_ = this.keeperHint;
this.keeperHint = false;
var _loc4_ = this.kickerHint;
this.kickerHint = false;
_global.__DISPATCH({type:"endGame",h1:_loc5_,h2:_loc4_});
this.GamePhase = game.G_GAMEOVER;
}
}
function playtimeover()
{
if(this.playtime >= this.def_playtime * 2)
{
return true;
}
return false;
}
function endCelebrate()
{
clearInterval(this.iCelebrate);
this.pumpgame(game.G_RESTART);
}
function renderWorld()
{
if(this.GamePhase == game.G_CORNERSHOOT)
{
this.mball.render();
return undefined;
}
if(this.GamePhase == game.G_RECEIVING)
{
this.mball.render();
return undefined;
}
if(this.GamePhase == game.G_SHOOTING)
{
this.mball.render();
return undefined;
}
if(this.GamePhase == game.G_SHOOT)
{
this.mball.render();
return undefined;
}
if(this.GamePhase == game.G_WINLOOSE)
{
this.mball.render();
return undefined;
}
}
function renderWorldnow()
{
if(!this.gameon)
{
return undefined;
}
if(this.GamePhase == game.G_AIM)
{
if(this.AutoAim)
{
if(!this.kickerHint && !this.keeperHint)
{
this.carrow.autoAim(false);
}
else
{
this.carrow.autoAim(true);
}
this.pumpgame(game.G_CORNERKICK);
}
if(Key.isDown(38))
{
this.carrow.up();
}
if(Key.isDown(40))
{
this.carrow.down();
}
if(Key.isDown(37))
{
this.carrow.left();
}
if(Key.isDown(39))
{
this.carrow.right();
}
return undefined;
}
if(this.GamePhase == game.G_TIMING)
{
if(this.AutoKick)
{
this.kicker.cekrun();
}
else
{
this.kicker.cekinput();
}
if(!this.AutoCatch)
{
this.keeper.cekinputA(this.mball);
}
return undefined;
}
if(this.GamePhase == game.GX2_RECEIVING)
{
this.kicker.cekinput(false);
return undefined;
}
if(this.GamePhase == game.G_RECEIVING)
{
if(this.AutoKick)
{
this.kicker.cekrun();
}
else
{
this.kicker.cekinput();
}
if(!this.AutoCatch)
{
this.keeper.cekinputA(this.mball);
}
return undefined;
}
if(this.GamePhase == game.G_SHOOTING)
{
if(!this.AutoCatch)
{
this.keeper.cekinputA(this.mball);
}
return undefined;
}
if(this.GamePhase == game.GX_SHOOT)
{
return undefined;
}
if(this.GamePhase == game.G_SHOOT)
{
if(!this.AutoCatch)
{
this.keeper.cekinputA(this.mball);
}
this.mball.cekinggoal();
return undefined;
}
if(this.GamePhase == game.G_WINLOOSE)
{
this.mball.cekinggoal();
return undefined;
}
}
function cekkey()
{
var _loc3_ = Key.getCode();
if(this.kickerHint)
{
if(Key.isDown(37) || Key.isDown(39) || Key.isDown(38) || Key.isDown(40))
{
if(this.GamePhase == game.GX_AIM)
{
this.pumpgame(game.G_AIM);
_global.__DISPATCH({type:"inGameHelp",param:"doneaiming"});
return undefined;
}
}
if(_loc3_ == 192 || _loc3_ == 13)
{
if(this.GamePhase == game.GX_RECEIVING)
{
this.pumpgame(game.GX2_RECEIVING);
_global.__DISPATCH({type:"inGameHelp",param:"moving2"});
return undefined;
}
if(this.GamePhase == game.GX2_RECEIVING)
{
this.pumpgame(game.G_RECEIVING);
_global.__DISPATCH({type:"inGameHelp",param:"stop"});
return undefined;
}
return undefined;
}
}
if(this.keeperHint)
{
if(_loc3_ == 192 || _loc3_ == 13)
{
if(this.GamePhase == game.G_TIMING)
{
this.pumpgame(game.G_RECEIVING);
_global.__DISPATCH({type:"inGameHelp",param:"stop"});
return undefined;
}
if(this.GamePhase == game.GX_SHOOT)
{
this.pumpgame(game.G_SHOOT);
_global.__DISPATCH({type:"inGameHelp",param:"stop"});
return undefined;
}
if(this.GamePhase == game.GX_AIM)
{
this.pumpgame(game.G_AIM);
_global.__DISPATCH({type:"inGameHelp",param:"stop"});
return undefined;
}
}
}
if(Key.isDown(32))
{
switch(this.GamePhase)
{
case game.G_AIM:
this.pumpgame(game.G_POWER);
break;
case game.G_POWER:
this.pumpgame(game.G_CORNERKICK);
break;
case game.G_SHOOTING:
case game.G_SHOOT:
if(!this.AutoCatch)
{
this.keeper.spacehit(this.mball);
break;
}
}
}
if(_loc3_ == 192 || _loc3_ == 13)
{
if(this.GamePhase == game.GX_WHISTLE)
{
this.pumpgame(game.G_WHISTLE);
_global.__DISPATCH({type:"inGameHelp",param:"stop"});
CSessionManager.ins().justEndTutorial = 0;
return undefined;
}
}
}
function switchcam()
{
if(this.cornercam)
{
this.cam.setPosition(28.339,4.808,0);
this.cam.rotateX(2);
this.cam.rotateY(90);
}
else
{
this.cam.setPosition(50,5.5,-51);
this.cam.rotateY(-90);
this.cam.rotateX(-2);
}
this.cornercam = !this.cornercam;
}
function setup3d()
{
this.world = sandy.core.World3D.getInstance();
this.screen = new sandy.view.ClipScreen(this.mcParent.createEmptyMovieClip("screen",1),640,400);
this.cam = new sandy.view.Camera3D(620,this.screen);
this.cam.setPosition(50,5.5,-51);
this.cam.rotateX(-10);
this.cornercam = true;
this.world.addCamera(this.cam);
var _loc2_ = new sandy.core.group.Group();
this.world.setRootGroup(_loc2_);
this.mball = new CBall(_loc2_,this.mcParent);
this.carrow = new CArrow(_loc2_,this.mcParent);
this.cornerkicker = new CCornerKicker(_loc2_,this.mcParent);
this.keeper = new CKeeper(_loc2_,this.mcParent);
this.kicker = new CKicker(_loc2_,this.mcParent,this.mball);
this.world.render();
}
function createField(bg, x, y, z)
{
var _loc4_ = new sandy.primitive.Plane3D(90,120,5,"tri");
var _loc6_ = new sandy.skin.MixedSkin(65280,80,0,100,1);
_loc4_.setSkin(_loc6_);
var _loc1_ = new sandy.core.group.TransformGroup();
var _loc2_ = new sandy.core.group.TransformGroup();
var _loc5_ = new sandy.core.transform.Transform3D();
var _loc3_ = new sandy.core.transform.Transform3D();
_loc5_.rot(0,0,0);
_loc3_.translate(x,y,z);
_loc1_.setTransform(_loc5_);
_loc2_.setTransform(_loc3_);
_loc1_.addChild(_loc4_);
_loc2_.addChild(_loc1_);
bg.addChild(_loc2_);
}
function setupfps()
{
this.mcParent.createTextField("fps",10000,0,200,50,20);
this.mcParent.fps.size = 14;
this.mcParent.fps.color = 16777215;
this._t = getTimer();
this._fps = 0;
}
function KillTheGame()
{
_global.__DISPATCH({type:"inGameHelp",param:"stopdialog"});
CSessionManager.ins().firstTimeOffense = false;
CSessionManager.ins().firstTimeDefense = false;
this.kickerHint = false;
this.keeperHint = false;
var _loc3_ = CTournament.ins().currentMatch;
if(CTeamManager.ins().currentTeam == _loc3_.team1)
{
_loc3_.addScorea(1,0);
}
else
{
_loc3_.addScorea(0,1);
}
_loc3_.round = 2;
_loc3_.totalkick1 = 0;
_loc3_.totalkick2 = 0;
this.playtime = this.def_playtime * 2;
CTournament.ins().endTournament();
this.pumpgame(game.G_RESTART);
this.purgegame = true;
}
}