home *** CD-ROM | disk | FTP | other *** search
- class CKicker
- {
- var mball;
- var mybg;
- var mcParent;
- var AutoKick;
- var mcKicker;
- var bx;
- var by;
- var bz;
- var mark;
- var bTrans;
- var todo;
- var AutoRun;
- var xrunto;
- var zrunto;
- var angley;
- var anglex;
- var power;
- var def_bx = 39;
- var def_by = 0;
- var def_bz = 1;
- var tbmc = 1;
- var zInner = 0.4;
- var zOuter = 1.1;
- var xInner = 1;
- var xOuter = 2;
- var KS_IDLE = 1;
- var KS_RUNRIGHT = 2;
- var KS_RUNLEFT = 3;
- var KS_RUNUP = 4;
- var KS_RUNDOWN = 5;
- var KS_HEADING = 6;
- var KS_VOLLEY = 7;
- var KS_DIVE = 8;
- var KS_BACKFLIP = 9;
- var KS_CHESTVOLLEY = 10;
- var kickerstate = 0;
- var AI_KICKERSHOOTLR = 0;
- function CKicker(bg, _mcParent, _mball)
- {
- this.mball = _mball;
- this.mybg = bg;
- this.mcParent = _mcParent;
- this.createMarker();
- this.tbmc = 0.3;
- this.AutoKick = false;
- EventCenter.access().addEventListener("kickerevent",this);
- }
- function createAnim()
- {
- this.mcKicker = this.mcParent.attachMovie("kicker","kicker",this.mcParent.getNextHighestDepth());
- this.mcKicker._x = 260;
- this.mcKicker._y = 387;
- this.mcKicker._visible = false;
- }
- function createMarker()
- {
- this.bx = this.def_bx;
- this.by = this.def_by;
- this.bz = this.def_bz;
- this.mark = new sandy.core.Sprite2D(0.09);
- this.mcKicker = this.mcParent.attachMovie("kicker","kicker",this.mcParent.getNextHighestDepth());
- this.mcKicker.gotoAndStop(1);
- this.mcKicker._visible = false;
- var _loc3_ = new sandy.skin.MovieSkin(this.mcKicker);
- this.mark.setSkin(_loc3_);
- var _loc2_ = new sandy.core.group.TransformGroup();
- this.bTrans = new sandy.core.transform.Transform3D();
- this.bTrans.translate(this.def_bx,0,this.def_bz);
- _loc2_.setTransform(this.bTrans);
- _loc2_.addChild(this.mark);
- this.mybg.addChild(_loc2_);
- }
- function restart()
- {
- this.mcKicker.gotoAndStop(1);
- }
- function hide()
- {
- this.bTrans.translate(this.def_bx,this.def_by,this.def_bz);
- this.AutoKick = false;
- this.mcKicker.gotoAndStop(1);
- this.mcKicker._visible = false;
- }
- function show()
- {
- this.bx = this.def_bx;
- this.by = this.def_by;
- this.bz = this.def_bz;
- this.bTrans.translate(this.bx,this.by,this.bz);
- this.mcKicker.gotoAndPlay(2);
- this.kickerstate = this.KS_IDLE;
- }
- function getPosition()
- {
- var _loc2_ = this.mark.getPosition();
- return _loc2_;
- }
- function win()
- {
- switch(this.randRange(1,6))
- {
- case 1:
- this.mcKicker.gotoAndPlay("win");
- break;
- case 2:
- case 3:
- this.mcKicker.gotoAndPlay("win2");
- break;
- case 4:
- case 5:
- case 6:
- this.mcKicker.gotoAndPlay("win3");
- }
- }
- function loose()
- {
- switch(this.randRange(1,4))
- {
- case 1:
- this.mcKicker.gotoAndPlay("loose");
- break;
- case 2:
- case 3:
- case 4:
- this.mcKicker.gotoAndPlay("loose2");
- }
- }
- function toidle()
- {
- this.kickerstate = this.KS_IDLE;
- this.mcKicker.gotoAndStop("idle");
- }
- function doaction()
- {
- switch(this.todo)
- {
- case "backflip":
- _global.__DISPATCH({type:"gameevent",param:"shooting"});
- this.kickerstate = this.KS_BACKFLIP;
- this.mcKicker.gotoAndPlay("backflip");
- break;
- case "heading":
- _global.__DISPATCH({type:"gameevent",param:"shooting"});
- this.kickerstate = this.KS_HEADING;
- this.mcKicker.gotoAndPlay("heading");
- break;
- case "chestvolley":
- _global.__DISPATCH({type:"gameevent",param:"shooting"});
- this.kickerstate = this.KS_CHESTVOLLEY;
- this.mcKicker.gotoAndPlay("chestvolley");
- break;
- case "dive":
- _global.__DISPATCH({type:"gameevent",param:"shooting"});
- this.kickerstate = this.KS_DIVE;
- this.mcKicker.gotoAndPlay("dive");
- break;
- case "volley":
- _global.__DISPATCH({type:"gameevent",param:"shooting"});
- this.kickerstate = this.KS_VOLLEY;
- this.mcKicker.gotoAndPlay("volley");
- }
- }
- function action()
- {
- var _loc7_ = this.mball.getPosition();
- var _loc8_ = this.mball.markball.getPosition();
- var _loc3_ = this.mark.getPosition();
- var _loc0_ = null;
- var _loc5_ = near = this.mball.getNearestBallTrajectories(_loc3_);
- var _loc2_ = _loc5_.x - _loc3_.x;
- var _loc4_ = _loc5_.y - _loc3_.y;
- var _loc6_ = _loc5_.z - _loc3_.z;
- this.todo = "nothing";
- if(_loc6_ > -0.5 && _loc4_ < 3.3 && _loc2_ > -1 && _loc2_ < 6)
- {
- if(_loc4_ >= 2)
- {
- if(_loc2_ < 0)
- {
- this.todo = "backflip";
- }
- else
- {
- this.todo = "heading";
- }
- }
- else if(_loc2_ > 3)
- {
- this.todo = "dive";
- }
- else if(_loc2_ < 0)
- {
- this.todo = "backflip";
- }
- else if(_loc4_ > 1)
- {
- this.todo = "chestvolley";
- }
- else if(_loc4_ < 1)
- {
- this.todo = "volley";
- }
- else
- {
- this.todo = "chestvolley";
- }
- }
- if(!this.AutoKick)
- {
- this.doaction();
- }
- }
- function startrun()
- {
- this.AutoRun = true;
- this.AutoKick = true;
- var _loc2_ = this.mball.getRandomPos();
- this.xrunto = _loc2_.x;
- this.zrunto = _loc2_.z;
- }
- function autoRunAction()
- {
- if(this.bx > this.xrunto)
- {
- this.bx -= this.tbmc;
- }
- if(this.bx < this.xrunto)
- {
- this.bx += this.tbmc;
- }
- if(this.bz > this.zrunto)
- {
- this.bz -= this.tbmc;
- }
- if(this.bz < this.zrunto)
- {
- this.bz += this.tbmc;
- }
- if(this.kickerstate == this.KS_IDLE)
- {
- this.kickerstate = this.KS_RUNUP;
- this.mcKicker.gotoAndPlay("runuploop");
- }
- this.bTrans.translate(this.bx,this.by,this.bz);
- if(Math.abs(this.bx - this.xrunto) < 0.5 && Math.abs(this.bz - this.zrunto) < 0.5)
- {
- this.action();
- this.kickerstate = this.KS_IDLE;
- this.mcKicker.gotoAndStop("idle");
- this.AutoRun = false;
- }
- }
- function randRange(min, max)
- {
- var _loc1_ = Math.floor(Math.random() * (max - min + 1)) + min;
- return _loc1_;
- }
- function autokicklevel1()
- {
- if(this.bz > 1)
- {
- this.angley = -90 - this.randRange(0,45);
- }
- else
- {
- this.angley = -90 + this.randRange(0,45);
- }
- Math.random() >= 0.5 ? (this.anglex -= 10) : (this.anglex += 10);
- }
- function autokicklevel2()
- {
- if(this.bz > 1)
- {
- if(this.bz > 5)
- {
- this.angley = -110 - this.randRange(0,30);
- }
- else
- {
- this.angley = -90 - this.randRange(0,30);
- }
- }
- else if(this.bz > -1)
- {
- this.angley = -90 + this.randRange(0,30);
- }
- else
- {
- this.angley = -70 + this.randRange(0,30);
- }
- Math.random() >= 0.5 ? (this.anglex -= 5) : (this.anglex += 5);
- }
- function setLevel(level)
- {
- this.AI_KICKERSHOOTLR = level;
- }
- function makeshoot()
- {
- this.power = 80;
- this.anglex = 0;
- this.angley = -90;
- if(this.AutoKick)
- {
- if(this.AI_KICKERSHOOTLR == 0)
- {
- this.autokicklevel1();
- }
- else
- {
- this.autokicklevel2();
- }
- }
- else
- {
- if(Key.isDown(37))
- {
- this.angley += 15;
- }
- if(Key.isDown(39))
- {
- this.angley -= 16;
- }
- if(Key.isDown(38))
- {
- this.anglex -= 15;
- }
- if(Key.isDown(40))
- {
- this.anglex += 10;
- }
- }
- this.mball.makeshoot(this.power,this.anglex,this.angley);
- }
- function cekrun()
- {
- if(this.AutoRun)
- {
- this.autoRunAction();
- return undefined;
- }
- }
- function cekinput(canspace)
- {
- if(canspace == undefined)
- {
- canspace = true;
- }
- if(this.kickerstate == this.KS_IDLE)
- {
- if(Key.isDown(38))
- {
- this.kickerstate = this.KS_RUNUP;
- this.mcKicker.gotoAndPlay("runuploop");
- }
- if(Key.isDown(40))
- {
- this.kickerstate = this.KS_RUNDOWN;
- this.mcKicker.gotoAndPlay("rundownloop");
- }
- if(Key.isDown(37))
- {
- this.kickerstate = this.KS_RUNLEFT;
- this.mcKicker.gotoAndPlay("runleftloop");
- }
- if(Key.isDown(39))
- {
- this.kickerstate = this.KS_RUNRIGHT;
- this.mcKicker.gotoAndPlay("runrightloop");
- }
- if(Key.isDown(32) && canspace)
- {
- this.action();
- }
- return undefined;
- }
- if(this.kickerstate == this.KS_RUNRIGHT)
- {
- if(Key.isDown(38))
- {
- this.bx += this.tbmc;
- }
- if(Key.isDown(40))
- {
- this.bx -= this.tbmc;
- }
- if(Key.isDown(32))
- {
- this.action();
- }
- if(Key.isDown(39))
- {
- this.bz -= this.tbmc;
- this.bTrans.translate(this.bx,this.by,this.bz);
- }
- else
- {
- this.kickerstate = this.KS_IDLE;
- this.mcKicker.gotoAndStop("idle");
- }
- return undefined;
- }
- if(this.kickerstate == this.KS_RUNLEFT)
- {
- if(Key.isDown(38))
- {
- this.bx += this.tbmc;
- }
- if(Key.isDown(40))
- {
- this.bx -= this.tbmc;
- }
- if(Key.isDown(32))
- {
- this.action();
- }
- if(Key.isDown(37))
- {
- this.bz += this.tbmc;
- this.bTrans.translate(this.bx,this.by,this.bz);
- }
- else
- {
- this.kickerstate = this.KS_IDLE;
- this.mcKicker.gotoAndStop("idle");
- }
- return undefined;
- }
- if(this.kickerstate == this.KS_RUNUP)
- {
- if(Key.isDown(37))
- {
- this.bz += this.tbmc;
- }
- if(Key.isDown(39))
- {
- this.bz -= this.tbmc;
- }
- if(Key.isDown(32))
- {
- this.action();
- }
- if(Key.isDown(38))
- {
- this.bx += this.tbmc;
- this.bTrans.translate(this.bx,this.by,this.bz);
- }
- else
- {
- this.kickerstate = this.KS_IDLE;
- this.mcKicker.gotoAndStop("idle");
- }
- return undefined;
- }
- if(this.kickerstate == this.KS_RUNDOWN)
- {
- if(Key.isDown(37))
- {
- this.bz += this.tbmc;
- }
- if(Key.isDown(39))
- {
- this.bz -= this.tbmc;
- }
- if(Key.isDown(32))
- {
- this.action();
- }
- if(Key.isDown(40))
- {
- this.bx -= this.tbmc;
- this.bTrans.translate(this.bx,this.by,this.bz);
- }
- else
- {
- this.kickerstate = this.KS_IDLE;
- this.mcKicker.gotoAndStop("idle");
- }
- return undefined;
- }
- }
- function kickerevent(ob)
- {
- switch(ob.param)
- {
- case "shoot":
- this.doaction(this.todo);
- break;
- case "runright":
- this.mcKicker.gotoAndPlay("runrightloop");
- break;
- case "runleft":
- this.mcKicker.gotoAndPlay("runleftloop");
- break;
- case "rundown":
- this.mcKicker.gotoAndPlay("rundownloop");
- break;
- case "runup":
- this.mcKicker.gotoAndPlay("runuploop");
- break;
- case "addup":
- this.bx += ob.tbmc;
- this.bTrans.translate(this.bx,this.by,this.bz);
- break;
- case "adddown":
- this.bx -= ob.tbmc;
- this.bTrans.translate(this.bx,this.by,this.bz);
- break;
- case "addleft":
- this.bz += ob.tbmc;
- this.bTrans.translate(this.bx,this.by,this.bz);
- break;
- case "addright":
- this.bz -= ob.tbmc;
- this.bTrans.translate(this.bx,this.by,this.bz);
- }
- }
- function setHuman(human)
- {
- if(human)
- {
- this.mcKicker.indicator._visible = true;
- }
- else
- {
- this.mcKicker.indicator._visible = false;
- }
- }
- }
-