home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Esportes
/
CrossingCup.swf
/
scripts
/
__Packages
/
CBall.as
< prev
next >
Wrap
Text File
|
2007-12-11
|
12KB
|
379 lines
class CBall
{
var count = 0;
var def_bx = 54.8;
var def_by = 0.1;
var def_bz = -38.5;
var gravity = 0.9;
var friction = 0.95;
function CBall(bg, _mcParent)
{
this.mcParent = _mcParent;
this.mybg = bg;
this.camswitched = false;
this.createBall();
this.createShadow();
this.createMarker();
this.ctrNT = -1;
this.halted = false;
}
function createBall()
{
this.bx = this.def_bx;
this.by = this.def_by;
this.bz = this.def_bz;
this.ball = new sandy.core.Sprite2D(0.03);
this.mcBall = this.mcParent.attachMovie("ball","ball",this.mcParent.getNextHighestDepth());
this.mcBall._visible = false;
var _loc3_ = new sandy.skin.MovieSkin(this.mcBall);
this.ball.setSkin(_loc3_);
var _loc2_ = new sandy.core.group.TransformGroup();
this.bTrans = new sandy.core.transform.Transform3D();
this.bTrans.translate(this.bx,this.by,this.bz);
_loc2_.setTransform(this.bTrans);
_loc2_.addChild(this.ball);
this.mybg.addChild(_loc2_);
}
function getPosition()
{
var _loc2_ = this.ball.getPosition();
return _loc2_;
}
function createShadow()
{
this.bx = this.def_bx;
this.by = this.def_by;
this.bz = this.def_bz;
var _loc3_ = new sandy.primitive.Plane3D(0.5,0.5,1,"tri");
this.mcBallShadow = this.mcParent.attachMovie("ballshadow","ballshadow",this.mcParent.getNextHighestDepth());
this.mcBallShadow._visible = false;
var _loc4_ = new sandy.skin.MovieSkin(this.mcBallShadow);
_loc3_.setSkin(_loc4_);
var _loc2_ = new sandy.core.group.TransformGroup();
this.bsTrans = new sandy.core.transform.Transform3D();
this.bsTrans.translate(this.bx,-0.1,this.bz);
_loc2_.setTransform(this.bsTrans);
_loc2_.addChild(_loc3_);
this.mybg.addChild(_loc2_);
}
function createMarker()
{
this.markball = new sandy.primitive.Plane3D(1,1,1,"tri");
var _loc3_ = this.mcParent.attachMovie("bayball","bayball",this.mcParent.getNextHighestDepth());
_loc3_._visible = false;
var _loc4_ = new sandy.skin.MovieSkin(_loc3_);
this.markball.setSkin(_loc4_);
var _loc2_ = new sandy.core.group.TransformGroup();
this.bmTrans = new sandy.core.transform.Transform3D();
this.bmTrans.translate(this.def_bx + 2,0,this.def_bz - 2);
_loc2_.setTransform(this.bmTrans);
_loc2_.addChild(this.markball);
this.mybg.addChild(_loc2_);
}
function createTanda()
{
var _loc3_ = new sandy.primitive.Box(0.1,0.1,0.1,"tri");
var _loc4_ = new sandy.skin.SimpleColorSkin(65535,100);
_loc3_.setSkin(_loc4_);
var _loc2_ = new sandy.core.group.TransformGroup();
this.xTanda = new sandy.core.transform.Transform3D();
this.xTanda.translate(54,0,4.2);
_loc2_.setTransform(this.xTanda);
_loc2_.addChild(_loc3_);
this.mybg.addChild(_loc2_);
}
function createTrajectoryLine(vs1, vs2)
{
var _loc2_ = new sandy.primitive.Line3D(vs1,vs2);
_loc2_.setSkin(new sandy.skin.SimpleLineSkin(1,0,30));
this.tgTrajectoryLine = new sandy.core.group.TransformGroup();
this.tgTrajectoryLine.addChild(_loc2_);
this.mybg.addChild(this.tgTrajectoryLine);
}
function deleteTrajectoryLine()
{
this.tgTrajectoryLine.destroy();
}
function shoot(_power, anglex, angley)
{
this.power = _power;
this.Aangle = anglex * -1 * 3.141592653589793 / 180;
this.Bangle = angley * -1 * 3.141592653589793 / 180;
this.terus = true;
this.yVel = Math.sin(this.Aangle) * this.power;
var _loc2_ = Math.cos(this.Aangle) * this.power;
this.xVel = Math.sin(this.Bangle) * _loc2_;
this.zVel = Math.cos(this.Bangle) * _loc2_;
}
function makeshoot(power, anglex, angley)
{
this.Aangle = anglex * -1 * 3.141592653589793 / 180;
this.Bangle = angley * -1 * 3.141592653589793 / 180;
this.terus = true;
this.yVel = Math.sin(this.Aangle) * power;
var _loc3_ = Math.cos(this.Aangle) * power;
this.xVel = Math.sin(this.Bangle) * _loc3_;
this.zVel = Math.cos(this.Bangle) * _loc3_;
_global.__DISPATCH({type:"gameevent",param:"shoot"});
this.halted = false;
}
function haltedit()
{
this.xVel = 0;
this.zVel = 0;
this.halted = true;
}
function deflect()
{
this.yVel /= 3;
this.xVel = - this.xVel / 3;
this.zVel = - this.zVel / 3;
}
function makeBallTrajectories()
{
this.arBallTrajectories = new Array();
var _loc3_ = new Object();
_loc3_.bx = this.bx;
_loc3_.by = this.by;
_loc3_.bz = this.bz;
_loc3_.xVel = this.xVel;
_loc3_.yVel = this.yVel;
_loc3_.zVel = this.zVel;
_loc3_.power = this.power;
_loc3_.Aangle = this.Aangle;
var _loc7_ = new sandy.core.data.Vector(this.bx,0,this.bz);
var _loc5_ = false;
var _loc4_ = 20;
while(!_loc5_)
{
var _loc2_ = new CBallPoint(this.mybg,this.mcParent,_loc3_,_loc4_);
_loc4_ += 3;
if(_loc2_.obax2.by <= 0)
{
_loc5_ = true;
this.bmTrans.translate(_loc2_.obax2.bx,0,_loc2_.obax2.bz);
}
this.arBallTrajectories.push(_loc2_);
_loc3_ = _loc2_.obax2;
}
var _loc6_ = new sandy.core.data.Vector(_loc3_.bx,0,_loc3_.bz);
this.createTrajectoryLine(_loc7_,_loc6_);
}
function clearBallTrajectories()
{
var _loc2_ = 0;
while(_loc2_ < this.arBallTrajectories.length)
{
this.arBallTrajectories[_loc2_].destroy();
delete this.arBallTrajectories[_loc2_];
_loc2_ = _loc2_ + 1;
}
this.deleteTrajectoryLine();
}
function getNearestBallTrajectories(kp)
{
var _loc5_ = new sandy.core.data.Vector(0,0,0);
var _loc6_ = 100;
this.idNT = 0;
var _loc2_ = 0;
while(_loc2_ < this.arBallTrajectories.length)
{
var _loc3_ = CBallPoint(this.arBallTrajectories[_loc2_]).getPosition();
var _loc4_ = Math.abs(kp.z - _loc3_.z);
if(_loc4_ < _loc6_)
{
this.idNT = _loc2_;
_loc6_ = _loc4_;
_loc5_.x = _loc3_.x;
_loc5_.y = _loc3_.y;
_loc5_.z = _loc3_.z;
}
_loc2_ = _loc2_ + 1;
}
return _loc5_;
}
function randRange(min, max)
{
var _loc1_ = Math.floor(Math.random() * (max - min + 1)) + min;
return _loc1_;
}
function getRandomPos()
{
if(this.arBallTrajectories.length > 10)
{
var _loc4_ = -1;
var _loc2_ = 10;
while(_loc4_ == -1 && _loc2_ < this.arBallTrajectories.length)
{
var _loc3_ = CBallPoint(this.arBallTrajectories[_loc2_]).getPosition();
if(_loc3_.y < 3)
{
_loc4_ = _loc2_;
}
_loc2_ = _loc2_ + 1;
}
var _loc6_ = this.randRange(_loc4_,this.arBallTrajectories.length - 1);
}
else
{
_loc6_ = this.arBallTrajectories.length - 1;
}
var _loc5_ = this.arBallTrajectories[_loc6_].getPosition();
if(_loc5_.y > 2)
{
_loc5_.x += this.randRange(-0.5,0.5);
}
else
{
_loc5_.x += this.randRange(0,0);
}
_loc5_.y = 0;
return _loc5_;
}
function startTrajectoryCounter(nwait)
{
this.ctrNT = 0;
this.idNT -= nwait;
}
function reset()
{
this.bx = this.def_bx;
this.by = this.def_by;
this.bz = this.def_bz;
this.bTrans.translate(this.def_bx,this.def_by,this.def_bz);
this.bsTrans.translate(this.def_bx,-0.1,this.def_bz);
this.bmTrans.translate(this.def_bx + 2,0,this.def_bz - 2);
this.clearBallTrajectories();
this.camswitched = false;
this.halted = false;
this.ingoalsequence = 0;
this.ctrNT = -1;
}
function render(rat)
{
if(!this.terus)
{
return undefined;
}
if(rat == undefined)
{
rat = 0.01;
}
this.yVel -= this.gravity;
this.bx += this.xVel * rat;
this.by += this.yVel * rat;
this.bz += this.zVel * rat;
if(this.ctrNT != -1)
{
this.ctrNT = this.ctrNT + 1;
if(this.ctrNT == this.idNT)
{
_global.__DISPATCH({type:"kickerevent",param:"shoot"});
}
}
if(this.bz > -10 && !this.camswitched)
{
this.camswitched = true;
this.makeBallTrajectories();
_global.__DISPATCH({type:"gameevent",param:"transition"});
}
if(this.by < this.def_by)
{
this.by = this.def_by;
this.power *= 0.6;
this.yVel = Math.sin(this.Aangle) * this.power;
this.xVel *= this.friction;
this.zVel *= this.friction;
if(this.power < 0.1)
{
this.power = 0;
if(Math.abs(this.xVel) < 1)
{
this.xVel = 0;
}
if(Math.abs(this.yVel) < 1)
{
this.yVel = 0;
}
if(Math.abs(this.zVel) < 1)
{
this.zVel = 0;
}
if(this.xVel == 0 && this.yVel == 0 && this.zVel == 0)
{
this.terus = false;
_global.__DISPATCH({type:"gameevent",param:"ballout"});
}
}
}
if(this.bz > 14 || this.bx > 70 || this.bx < 30)
{
this.terus = false;
_global.__DISPATCH({type:"gameevent",param:"ballout"});
}
this.bTrans.translate(this.bx,this.by,this.bz);
this.bsTrans.translate(this.bx,-0.1,this.bz);
}
function cekinggoal()
{
if(this.ingoalsequence == 4)
{
if(this.bx > 58 || this.bz > 4.2 || this.bz < -3.2 || this.by > 3)
{
if(this.bx > 58)
{
this.bx = 58;
}
if(this.bz > 3.2)
{
this.bz = 3.2;
}
if(this.bz < -3.2)
{
this.bz = -3.2;
}
this.xVel = 0;
this.zVel = 0;
this.ingoalsequence = 5;
}
}
if(this.ingoalsequence == 3)
{
_global.__DISPATCH({type:"gameevent",param:"enteringhurdle"});
}
if(this.ingoalsequence == 2)
{
if(this.bx > 54.5)
{
if(this.bx < 58 && this.bz <= 4.2 && this.bz > -3.2 and this.by < 3)
{
this.ingoalsequence = 3;
}
else
{
_global.__DISPATCH({type:"gameevent",param:"loose"});
this.ingoalsequence = 0;
}
}
}
if(this.ingoalsequence == 1)
{
if(this.bx > 50)
{
this.ingoalsequence = 2;
_global.__DISPATCH({type:"keeperevent",param:"ballclosing"});
}
}
}
function hide()
{
this.mcBallShadow.gotoAndStop(2);
this.mcBall.gotoAndStop(2);
}
function show()
{
this.mcBallShadow.gotoAndStop(1);
this.mcBall.gotoAndStop(1);
}
}