home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Esportes
/
CrossingCup.swf
/
scripts
/
__Packages
/
CKeeper.as
< prev
next >
Wrap
Text File
|
2007-12-11
|
10KB
|
386 lines
class CKeeper
{
var def_bx = 54.8;
var def_by = 0;
var def_bz = 0.1;
var afterAct = 0;
var AI_KEEPERJUMPRANDOM = 1;
function CKeeper(bg, _mcParent)
{
this.mybg = bg;
this.mcParent = _mcParent;
this.createMarker();
this.AutoCatch = false;
EventCenter.access().addEventListener("keeperevent",this);
}
function createMarker()
{
this.bx = this.def_bx;
this.by = this.def_by;
this.bz = this.def_bz;
var _loc3_ = new sandy.core.Sprite2D(0.26);
this.mcKeeper = this.mcParent.attachMovie("keeper","keeper",this.mcParent.getNextHighestDepth());
this.mcKeeper._visible = false;
this.mcKeeper.gotoAndStop(1);
var _loc4_ = new sandy.skin.MovieSkin(this.mcKeeper);
_loc3_.setSkin(_loc4_);
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(_loc3_);
this.mybg.addChild(_loc2_);
}
function startcatch()
{
this.AutoCatch = true;
}
function cekinput(mball)
{
if(Key.isDown(38) && Key.isDown(37))
{
this.todo = "upleft";
return undefined;
}
if(Key.isDown(38) && Key.isDown(39))
{
this.todo = "upright";
return undefined;
}
if(Key.isDown(40) && Key.isDown(37))
{
this.todo = "downleft";
return undefined;
}
if(Key.isDown(40) && Key.isDown(39))
{
this.todo = "downright";
return undefined;
}
if(Key.isDown(37))
{
this.todo = "downleft";
return undefined;
}
if(Key.isDown(39))
{
this.todo = "downright";
return undefined;
}
if(Key.isDown(38))
{
this.todo = "jump";
return undefined;
}
if(Key.isDown(40))
{
this.todo = "block";
return undefined;
}
}
function cekinputA(mball)
{
if(this.doing != "")
{
return undefined;
}
if(Key.isDown(37))
{
this.todo = "left";
}
if(Key.isDown(39))
{
this.todo = "right";
}
this.doAction();
}
function spacehit(mball)
{
this.cekinput(mball);
this.doAction();
}
function setLevel(level)
{
this.AI_KEEPERJUMPRANDOM = level;
}
function catchball(mball)
{
if(this.AI_KEEPERJUMPRANDOM == 0)
{
this.catchball1(mball);
}
else
{
this.catchball2(mball);
}
}
function catchball1(mball)
{
var _loc3_ = this.randRange(1,6);
var _loc2_ = this.bx - mball.bx;
if(_loc2_ > 9)
{
this.catchball2(mball);
return undefined;
}
switch(_loc3_)
{
case 1:
this.todo = "jump";
break;
case 2:
this.todo = "block";
break;
case 3:
this.todo = "downleft";
break;
case 4:
this.todo = "upleft";
break;
case 5:
this.todo = "downright";
break;
case 6:
this.todo = "upright";
}
}
function catchball2(mball)
{
var _loc4_ = Math.atan2(mball.xVel,mball.zVel);
var _loc6_ = this.bx - mball.bx;
var _loc5_ = _loc6_ / Math.tan(_loc4_);
var _loc2_ = mball.bz + _loc5_;
if(Math.abs(_loc2_ - this.bz) < 1)
{
if(Math.random() < 0.5)
{
this.todo = "jump";
return undefined;
}
this.todo = "block";
return undefined;
}
if(_loc2_ > this.bz)
{
if(Math.random() <= 0.5)
{
this.todo = "downleft";
return undefined;
}
this.todo = "upleft";
return undefined;
}
if(Math.random() <= 0.5)
{
this.todo = "downright";
return undefined;
}
this.todo = "upright";
return undefined;
}
function cekGoal(mball)
{
switch(this.doing)
{
case "":
case "left":
case "right":
if(mball.bz <= this.bz + 0.5 && mball.bz > this.bz - 0.5 && mball.by <= 2)
{
return false;
}
break;
case "jump":
if(mball.bz <= this.bz + 1 && mball.bz > this.bz - 1 && mball.by > 0.7 && mball.by < 3)
{
return false;
}
break;
case "block":
if(mball.bz <= this.bz + 1 && mball.bz > this.bz - 1 && mball.by <= 2)
{
return false;
}
break;
case "downleft":
if(mball.bz > this.bz && mball.bz < this.bz + 3 && mball.by <= 1.5)
{
return false;
}
break;
case "upleft":
if(mball.bz > this.bz && mball.bz < this.bz + 3 && mball.by > 1.5 && mball.by <= 3)
{
return false;
}
break;
case "upright":
if(mball.bz < this.bz && mball.bz > this.bz - 3 && mball.by > 1.5 && mball.by <= 3)
{
return false;
}
break;
case "downright":
if(mball.bz < this.bz && mball.bz > this.bz - 3 && mball.by <= 1.5)
{
return false;
}
break;
}
return true;
}
function doAction()
{
switch(this.todo)
{
case "downleft":
this.mcKeeper.gotoAndPlay("downleft");
this.doing = this.todo;
break;
case "downright":
this.mcKeeper.gotoAndPlay("downright");
this.doing = this.todo;
break;
case "upleft":
this.mcKeeper.gotoAndPlay("upleft");
this.doing = this.todo;
break;
case "upright":
this.mcKeeper.gotoAndPlay("upright");
this.doing = this.todo;
break;
case "win":
this.mcKeeper.gotoAndPlay("win");
this.doing = this.todo;
break;
case "win2":
this.mcKeeper.gotoAndPlay("win2");
this.doing = this.todo;
break;
case "loose":
this.mcKeeper.gotoAndPlay("loose");
this.doing = this.todo;
break;
case "loose2":
this.mcKeeper.gotoAndPlay("loose2");
this.doing = this.todo;
break;
case "jump":
this.mcKeeper.gotoAndPlay("jump");
this.doing = this.todo;
break;
case "block":
this.mcKeeper.gotoAndPlay("block");
this.doing = this.todo;
break;
case "left":
this.mcKeeper.gotoAndPlay("left");
this.doing = this.todo;
break;
case "right":
this.mcKeeper.gotoAndPlay("right");
this.doing = this.todo;
}
this.todo = "";
}
function win()
{
this.afterAct = 1;
}
function loose()
{
this.afterAct = -1;
}
function hide()
{
this.bTrans.translate(this.def_bx - 50,this.def_by,this.def_bz);
}
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.mcKeeper.gotoAndPlay("idle");
this.todo = "";
this.doing = "";
}
function restart()
{
this.mcKeeper.gotoAndStop(1);
}
function keeperevent(ob)
{
switch(ob.param)
{
case "idle":
this.mcKeeper.gotoAndPlay("idle");
this.doing = "";
break;
case "downleft":
case "downright":
case "upleft":
case "upright":
case "jump":
case "block":
if(this.afterAct != 0)
{
if(this.afterAct == -1)
{
this.afterAct = 0;
Math.random() >= 0.5 ? (this.todo = _loc0_ = "loose2", _loc0_) : (this.todo = _loc0_ = "loose", _loc0_);
this.doAction();
}
else
{
this.afterAct = 0;
Math.random() >= 0.5 ? (this.todo = _loc0_ = "win2", _loc0_) : (this.todo = _loc0_ = "win", _loc0_);
this.doAction();
}
}
else
{
this.mcKeeper.stop();
}
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);
break;
case "ballclosing":
if(this.AutoCatch)
{
this.doAction();
}
}
}
function randRange(min, max)
{
var _loc1_ = Math.floor(Math.random() * (max - min + 1)) + min;
return _loc1_;
}
function setHuman(human)
{
if(human)
{
this.mcKeeper.indicator._visible = true;
}
else
{
this.mcKeeper.indicator._visible = false;
}
}
}