home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Aventura
/
pendekar.swf
/
scripts
/
DefineSprite_745
/
frame_1
/
DoAction.as
Wrap
Text File
|
2006-05-08
|
12KB
|
537 lines
function init()
{
if(runOnce)
{
return undefined;
}
this.runOnce = true;
this.stageWidth = Stage.width;
this.stageHeight = Stage.height;
this.stageName = "Untitled";
this.stageLength = 100;
this.envBuffer = new Array();
this.envDepth = 100;
this.envCount = 0;
this.flrBuffer = new Array();
this.flrDepth = 200;
this.flrCount = 0;
this.oTypeBuffer = new Array();
this.oDistBuffer = new Array();
this.oVisBuffer = new Array();
this.oDepth = 300;
this.oCount = 0;
this.pBuffer = new Array();
this.pDepth = 400;
this.pCount = 0;
this.sDepth = 500;
this.speed = 4;
this.dist = 0;
this.cp = 0;
this.bodyCount = 0;
this.isScroll = true;
switch(_root.currentLevel)
{
case 0:
this.attachMovie("level01","scenario",sDepth);
break;
case 1:
this.attachMovie("level02","scenario",sDepth);
break;
case 2:
this.attachMovie("level03","scenario",sDepth);
break;
case 3:
this.attachMovie("level04","scenario",sDepth);
break;
case 4:
this.attachMovie("practice","scenario",sDepth);
break;
case 5:
this.attachMovie("challenge01","scenario",sDepth);
break;
case 6:
this.attachMovie("challenge02","scenario",sDepth);
break;
default:
trace("err: Level scenario not loaded!");
}
sDepth++;
}
function setStage(stageName, stageLength, flr, env, bg)
{
this.stageName = stageName;
this.stageLength = stageLength;
setComboTimer();
i = 0;
while(i < 4)
{
addFlr(flr);
i++;
}
this.flr = flr;
addEnv(env);
this.env = env;
this.attachMovie(bg,"bg",1);
this.attachMovie("screen_flasher_in","flasher",sDepth);
sDepth++;
this.attachMovie("oDimmer","dimmer",sDepth);
sDepth++;
this.attachMovie("hud","hud",sDepth);
mCombo = hud.combo;
sDepth++;
addSFXChannels(3);
}
function addFlr(flr)
{
if(flr == undefined)
{
trace("err: Stage floor undefined!");
}
if(flrBuffer.length == 0)
{
newFlr = "flr_0";
}
else
{
newFlr = flrBuffer[flrBuffer.length - 1]._name.substr(0,4) + flrCount;
}
this.attachMovie(flr,newFlr,flrDepth);
this[newFlr]._y = stageHeight - this[newFlr]._height;
this[newFlr]._x = flrBuffer[flrBuffer.length - 1]._x + flrBuffer[flrBuffer.length - 1]._width;
flrBuffer.push(this[newFlr]);
flrCount++;
if(flrDepth < 299)
{
flrDepth++;
}
else
{
flrDepth = 200;
}
}
function addEnv(env)
{
if(env == undefined)
{
trace("err: Stage environment undefined!");
}
if(envBuffer.length == 0)
{
newEnv = "env_0";
}
else
{
newEnv = envBuffer[envBuffer.length - 1]._name.substr(0,4) + envCount;
}
this.attachMovie(env,newEnv,envDepth);
this[newEnv]._y = stageHeight - (this[newEnv]._height + 50);
this[newEnv]._x = envBuffer[envBuffer.length - 1]._x + envBuffer[envBuffer.length - 1]._width;
envBuffer.push(this[newEnv]);
envCount++;
if(envDepth < 199)
{
envDepth++;
}
else
{
envDepth = 100;
}
}
function scrollStage(speed)
{
if(dist >= stageLength)
{
scenario.checkPoint(cp);
return undefined;
}
if(speed == undefined)
{
trace("err: Stage scroll speed undefined!");
return undefined;
}
if(isObjectVisible())
{
addObject();
}
if(oVisBuffer.length > 0)
{
scrollObject(speed);
}
scrollFlr(speed);
scrollEnv(speed);
scrollBg(speed);
dist += speed;
}
function scrollObject(speed)
{
i = 0;
while(i < oVisBuffer.length)
{
oVisBuffer[i]._x -= speed;
i++;
}
if(oVisBuffer[0]._x <= -1 * oVisBuffer[0]._width)
{
removeMovieClip(oVisBuffer.shift());
}
}
function scrollFlr(speed)
{
if(flrBuffer[flrBuffer.length - 1]._x - speed + flrBuffer[flrBuffer.length - 1]._width <= stageWidth)
{
addFlr(this.flr);
}
i = 0;
while(i < flrBuffer.length)
{
flrBuffer[i]._x -= speed;
i++;
}
if(flrBuffer[0]._x <= -1 * flrBuffer[0]._width)
{
removeMovieClip(flrBuffer.shift());
}
}
function scrollEnv(speed)
{
speed /= 2;
if(envBuffer[envBuffer.length - 1]._x - speed + envBuffer[envBuffer.length - 1]._width <= stageWidth)
{
addEnv(this.env);
}
i = 0;
while(i < envBuffer.length)
{
envBuffer[i]._x -= speed;
i++;
}
if(envBuffer[0]._x <= -1 * envBuffer[0]._width)
{
removeMovieClip(envBuffer.shift());
}
}
function scrollBg(speed)
{
speed = Math.round(speed / 16);
if(bg._x > -1 * (bg._width - stageWidth))
{
bg._x -= speed;
}
}
function addSFXChannels(number)
{
if(number == undefined)
{
trace("err: SFX channels undefined");
return undefined;
}
SFXChannel = new Array(number);
SFXStatus = new Array(number);
i = 0;
while(i < number)
{
SFXChannel[i] = new Sound();
SFXStatus[i] = true;
SFXChannel[i].onSoundComplete = function()
{
SFXStatus[i] = true;
};
i++;
}
}
function playSFX(name)
{
i = 0;
if(i < SFXChannel.length)
{
if(SFXStatus[i])
{
SFXChannel[i].attachSound(name);
SFXChannel[i].start();
}
return undefined;
}
}
function setComboTimer()
{
comboCount = 0;
this.attachMovie("oComboTimer","oComboTimer",sDepth);
sDepth++;
}
function resetComboTimer()
{
oComboTimer.count = 0;
oComboTimer.play();
comboCount++;
}
function displayMaxCombo()
{
if(comboCount > 1)
{
mCombo.display(comboCount);
}
}
function addObject()
{
oCount++;
if(oDepth < 399)
{
oDepth++;
}
else
{
oDepth = 300;
}
oID = "object" + oCount;
newObjectType = oTypeBuffer.shift();
newObjectDist = oDistBuffer.shift();
attachMovie(newObjectType,oID,oDepth);
oVisBuffer.push(this[oID]);
this[oID]._x = stageWidth + newObjectDist - dist;
this[oID]._y = stageHeight - 30;
}
function registerObject(oType, oDist)
{
oTypeBuffer.push(oType);
oDistBuffer.push(oDist);
}
function spawnObject(oType, oPos)
{
oCount++;
if(oDepth < 399)
{
oDepth++;
}
else
{
oDepth = 300;
}
oID = "object" + oCount;
attachMovie(oType,oID,oDepth);
oVisBuffer.push(this[oID]);
this[oID]._x = oPos;
this[oID]._y = stageHeight - 30;
this[oID].intro = true;
return this[oID];
}
function isObjectVisible()
{
oDist = oDistBuffer[0];
return dist < oDist ? false : true;
}
function pickupObject(hit, player)
{
i = 0;
while(i < oVisBuffer.length)
{
if(hit.hitTest(oVisBuffer[i]) && oVisBuffer[i].id > 0)
{
weapon = player.weapon;
if(weapon > 0)
{
spawnObject("oWeapon" + getWeaponName(weapon),player._x + player.dirValue(40));
}
player.weapon = oVisBuffer[i].id;
removeMovieClip(oVisBuffer[i]);
}
i++;
}
}
function isPlayerConnect(hit, object)
{
i = 0;
while(i < pBuffer.length)
{
if(hit.hitTest(pBuffer[i]) && pBuffer[i].hitable)
{
temp = object._x + object.dirValue(hit._x);
if(Math.abs(temp - pBuffer[i]._x) <= 55)
{
return true;
}
}
i++;
}
return false;
}
function isObjectConnect(hit, player)
{
i = 0;
while(i < oVisBuffer.length)
{
if(hit.hitTest(oVisBuffer[i]) && oVisBuffer[i].hitable)
{
temp = player._x + player.dirValue(hit._x);
if(Math.abs(temp - oVisBuffer[i]._x) <= 60)
{
return true;
}
}
i++;
}
return false;
}
function hitPlayer(hit, power, object, hard)
{
i = 0;
while(i < pBuffer.length)
{
if(hit.hitTest(pBuffer[i]) && pBuffer[i].hitable)
{
pBuffer[i].getHit(power,hard,object);
attachMovie("oHitFlash01","oHitFlash",pDepth + 1);
oHitFlash._x = pBuffer[i]._x + pBuffer[i].dirValue(Math.floor(pBuffer[i]._width / 2));
if(object.dir == -1)
{
oHitFlash._xscale *= -1;
}
oHitFlash._y = hit._y + object._y;
}
i++;
}
}
function hitObject(hit, power, player, hard)
{
i = 0;
while(i < oVisBuffer.length)
{
if(hit.hitTest(oVisBuffer[i]) && oVisBuffer[i].hitable)
{
hud.tRightBar = oVisBuffer[i];
oVisBuffer[i].getHit(power,hard,player);
resetComboTimer();
if(comboCount > 1)
{
displayMaxCombo();
}
attachMovie("oHitFlash01","oHitFlash",pDepth + 1);
oHitFlash._x = oVisBuffer[i]._x + oVisBuffer[i].dirValue(Math.floor(oVisBuffer[i]._width / 2));
if(player.dir == -1)
{
oHitFlash._xscale *= -1;
}
oHitFlash._y = hit._y + player._y;
}
i++;
}
}
function hitAllObject(power, player, hard)
{
result = false;
i = 0;
while(i < oVisBuffer.length)
{
if(oVisBuffer[i].hitable)
{
result = true;
hud.tRightBar = oVisBuffer[i];
oVisBuffer[i].getHit(power,hard,player);
resetComboTimer();
if(comboCount > 1)
{
displayMaxCombo();
}
attachMovie("oHitFlash01","oHitFlash",pDepth + 1);
oHitFlash._x = oVisBuffer[i]._x + oVisBuffer[i].dirValue(Math.floor(oVisBuffer[i]._width / 2));
if(player.dir == -1)
{
oHitFlash._xscale *= -1;
}
oHitFlash._y = -20 + player._y;
}
i++;
}
return result;
}
function slicePlayer(hit, power, object, hard)
{
i = 0;
while(i < pBuffer.length)
{
if(hit.hitTest(pBuffer[i]) && pBuffer[i].hitable)
{
pBuffer[i].getHit(power,hard);
attachMovie("oHitFlash02","oHitFlash",pDepth + 1);
oHitFlash._x = pBuffer[i]._x + pBuffer[i].dirValue(Math.floor(pBuffer[i]._width / 2));
if(object.dir == -1)
{
oHitFlash._xscale *= -1;
}
oHitFlash._y = hit._y + object._y;
}
i++;
}
}
function sliceObject(hit, power, player, hard)
{
i = 0;
while(i < oVisBuffer.length)
{
if(hit.hitTest(oVisBuffer[i]) && oVisBuffer[i].hitable)
{
hud.tRightBar = oVisBuffer[i];
oVisBuffer[i].getHit(power,hard);
resetComboTimer();
if(comboCount > 1)
{
displayMaxCombo();
}
attachMovie("oHitFlash02","oHitFlash",pDepth + 1);
oHitFlash._x = oVisBuffer[i]._x + oVisBuffer[i].dirValue(Math.floor(oVisBuffer[i]._width / 2));
if(player.dir == -1)
{
oHitFlash._xscale *= -1;
}
oHitFlash._y = hit._y + player._y;
}
i++;
}
}
function getWeaponName(number)
{
switch(number)
{
case 1:
return "Bamboo";
case 2:
return "Golok";
case 3:
return "Kipas";
default:
trace("err: getWeaponName(number) not specified");
}
}
function getWeaponPower(number)
{
switch(number)
{
case 1:
return 21;
case 2:
return 22;
case 3:
return 20;
default:
trace("err: getWeaponPower(number) not specified");
}
}
function addPlayer(pType)
{
pCount++;
if(pDepth < 499)
{
pDepth++;
}
else
{
pDepth = 400;
}
pID = "player" + pCount;
attachMovie(pType,pID,pDepth);
pBuffer.push(this[pID]);
this[pID]._x = 10;
this[pID]._y = stageHeight - 30;
hud.tLeftBar = this[pID];
}
this.onLoad = init();