home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Aventura
/
pendekar.swf
/
scripts
/
DefineSprite_442_oJagoanAI
/
frame_1
/
DoAction.as
Wrap
Text File
|
2006-05-08
|
2KB
|
88 lines
function init()
{
if(runOnce)
{
return undefined;
}
this.runOnce = true;
this.pBuffer = _parent._parent.pBuffer;
this.c = _parent;
}
function action()
{
if(!c.hitable)
{
return undefined;
}
if(!c.action)
{
return undefined;
}
t = getClosestTarget();
if(t.dir * c.dir < 0)
{
tempT = t._x + t.dirValue(50);
tempC = c._x + c.dirValue(50);
}
else
{
tempT = t._x;
tempC = c._x + c.dirValue(50);
}
d = tempT - tempC;
r = random(100) + 1;
if(r <= c.mobility)
{
if(Math.abs(d) > 20)
{
if(d < 0)
{
c.moveLeft();
}
else if(d >= 0)
{
c.moveRight();
}
}
else if(r <= c.skill)
{
c.attCombo(1);
}
else
{
c.idle();
}
}
else
{
c.idle();
}
}
function getClosestTarget()
{
i = 0;
while(i < pBuffer.length)
{
tempDist = Math.abs(pBuffer[i]._x - c._x);
if(i == 0)
{
lastDist = tempDist;
tempTarget = pBuffer[i];
}
else if(tempDist <= lastDist)
{
lastDist = tempDist;
tempTarget = pBuffer[i];
}
i++;
}
if(tempTarget == undefined)
{
trace("err: AI Target not found");
}
return tempTarget;
}
this.onLoad = init();
this.onEnterFrame = action();
play();