//==================================================
//
// Other scripts can be found here,
// so that, every other script
// aren't being bombard by long stuffs
//
//==================================================

//======VARIABLES======

let csd = GetCurrentScriptDirectory;

let Alert = csd~"se\alert.wav";
let Appear = csd~"se\appear.wav";
let CardGet = csd~"se\cardget.wav";
let Cat = csd~"se\cat.wav";
let Charge1 = csd~"se\charge1.wav";
let Charge2 = csd~"se\charge2.wav";
let Charge3 = csd~"se\charge3.wav";
let Defeat = csd~"se\defeat.wav";
let Explode = csd~"se\explode.wav";
let Laser1 = csd~"se\laser1.wav";
let Laser2 = csd~"se\laser2.wav";
let Option = csd~"se\option.wav";
let Shot1 = csd~"se\shot1.wav";
let Shot2 = csd~"se\shot2.wav";
let Shot2_l = csd~"se\shot2_l.wav";
let Shot3 = csd~"se\shot3.wav";
let Shot4 = csd~"se\shot4.wav";
let Spark = csd~"se\spark.wav";
let SpellCard = csd~"se\spellcard.wav";
let TimeOut01 = csd~"se\timeout01.wav";
let TimeOut02 = csd~"se\timeout02.wav";

//======VARIABLE END======

//======SOUND STUFF======

sub LoadAllSE
{
LoadSE(Alert);
LoadSE(Appear);
LoadSE(CardGet);
LoadSE(Cat);
LoadSE(Charge1);
LoadSE(Charge2);
LoadSE(Charge3);
LoadSE(Defeat);
LoadSE(Explode);
LoadSE(Laser1);
LoadSE(Laser2);
LoadSE(Option);
LoadSE(Shot1);
LoadSE(Shot2);
LoadSE(Shot2_l);
LoadSE(Shot3);
LoadSE(Shot4);
LoadSE(Spark);
LoadSE(SpellCard);
LoadSE(TimeOut01);
LoadSE(TimeOut02);
}

//======SOUND END======

//======OTHER======

function Wait(time){loop(time){yield;}}

task Sound(l, stop, stop2, s)
{
Wait(stop);
loop(l)
	{
	PlaySE(s);
	Wait(stop2);
	}
}

task Timer
{
loop
	{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(TimeOut01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(TimeOut02);}
	Wait(60);
	}
}

//======ANIMATION FOR KOISHI======

let BR = [0,0,64,64];
let bossflip = 0;

let ani = 0;

task MoveKoishi
{
ani++;
let currentani = ani;

if (GetSpeedX > 0)
	{
	bossflip = 0;
	loop(8){if(currentani==ani){BR = [0,64,64,128]; yield;}}
	loop(8){if(currentani==ani){BR = [64,64,128,128]; yield;}}
	loop(8){if(currentani==ani){BR = [128,64,192,128]; yield;}}
	while(GetSpeed>0 && currentani==ani){BR = [192,64,256,128]; yield;}
	loop(8){if(currentani==ani){BR = [128,64,192,128]; yield;}}
	loop(8){if(currentani==ani){BR = [64,64,128,128]; yield;}}
	}
else
{
if (GetSpeedX < 0)
	{
	bossflip = 1;
	loop(8){if(currentani==ani){BR = [0,64,64,128]; yield;}}
	loop(8){if(currentani==ani){BR = [64,64,128,128]; yield;}}
	loop(8){if(currentani==ani){BR = [128,64,192,128]; yield;}}
	while(GetSpeed>0 && currentani==ani){BR = [192,64,256,128]; yield;}
	loop(8){if(currentani==ani){BR = [128,64,192,128]; yield;}}
	loop(8){if(currentani==ani){BR = [64,64,128,128]; yield;}}
	}
}
if(currentani==ani){IdleKoishi;}
}

task IdleKoishi
{
ani++;
let currentani = ani;
while(currentani==ani)
	{
	loop(10){if(currentani==ani){BR = [0,0,64,64]; yield;}}
	loop(10){if(currentani==ani){BR = [64,0,128,64]; yield;}}
	loop(10){if(currentani==ani){BR = [128,0,192,64]; yield;}}
	loop(10){if(currentani==ani){BR = [192,0,256,64]; yield;}}
	loop(10){if(currentani==ani){BR = [128,0,192,64]; yield;}}
	loop(10){if(currentani==ani){BR = [64,0,128,64]; yield;}}
	}
}

task FireKoishi
{
ani++;
let currentani = ani;
while(currentani==ani)
	{
	bossflip = 0;
	loop(6){if(currentani==ani){BR = [0,192,64,128]; yield;}}
	loop(6){if(currentani==ani){BR = [64,192,128,128]; yield;}}
	loop(6){if(currentani==ani){BR = [128,192,192,128]; yield;}}
	loop(999){if(currentani==ani){BR = [192,192,256,128]; yield;}}
	}
}

task IdleFire
{
ani++;
let currentani = ani;
while(currentani==ani)
	{
	bossflip = 0;
	loop(1){if(currentani==ani){BR = [192,192,256,128]; yield;}}
	}
}

//======KOISHI END======

//======ANIMATION FOR SATORI======

let BR = [0,0,48,64];
let bossflip = 0;

let ani = 0;

task MoveSatori
{
ani++;
let currentani = ani;

if (GetSpeedX > 0)
	{
	bossflip = 0;
	loop(8){if(currentani==ani){BR = [0,192,48,128]; yield;}}
	loop(8){if(currentani==ani){BR = [48,192,96,128]; yield;}}
	loop(8){if(currentani==ani){BR = [96,192,144,128]; yield;}}
	while(GetSpeed>0 && currentani==ani){BR = [144,192,192,128]; yield;}
	loop(8){if(currentani==ani){BR = [96,192,144,128]; yield;}}
	loop(8){if(currentani==ani){BR = [48,192,96,128]; yield;}}
	}
else
{
if (GetSpeedX < 0)
	{
	bossflip = 1;
	loop(8){if(currentani==ani){BR = [0,192,48,128]; yield;}}
	loop(8){if(currentani==ani){BR = [48,192,96,128]; yield;}}
	loop(8){if(currentani==ani){BR = [96,192,144,128]; yield;}}
	while(GetSpeed>0 && currentani==ani){BR = [144,192,192,128]; yield;}
	loop(8){if(currentani==ani){BR = [96,192,144,128]; yield;}}
	loop(8){if(currentani==ani){BR = [48,192,96,128]; yield;}}
	}
}
if(currentani==ani){IdleSatori;}
}

task IdleSatori
{
ani++;
let currentani = ani;
while(currentani==ani)
	{
	loop(10){if(currentani==ani){BR = [0,0,48,64]; yield;}}
	loop(10){if(currentani==ani){BR = [48,0,96,64]; yield;}}
	loop(10){if(currentani==ani){BR = [96,0,144,64]; yield;}}
	loop(10){if(currentani==ani){BR = [144,0,192,64]; yield;}}
	loop(10){if(currentani==ani){BR = [0,64,48,128]; yield;}}
	loop(10){if(currentani==ani){BR = [48,64,96,128]; yield;}}
	loop(10){if(currentani==ani){BR = [96,64,144,128]; yield;}}
	loop(10){if(currentani==ani){BR = [144,64,192,128]; yield;}}
	}
}

//======SATORI END======

//==========================================
//CutIn imitation script
// 
//	Types: 1 - MOF   Middle appear -> float to top -> leave top
//	       2 - SA    
//             3 - UFO	 Diagonal right top entrance -> slowmode -> follow path to leave
//	       4 - UFO2  Horizontal left entrance -> slowmode -> follow path to leave (Byakuren style)
//
// ==========================================================================================================

    let CSD = GetCurrentScriptDirectory;
    let cutinType = 0;


    // cutin function
    task ExCutin(type,cutinImg,left,top,right,bottom){

	SetCommonData("boundL",left);
	SetCommonData("boundT",top);
	SetCommonData("boundR",right);
	SetCommonData("boundB",bottom);

	// type checker
	if(type=="KANAKO"){
		SetCommonData("cutinType",1); 
		CreateEnemyFromFile(CSD~"cutinFam.dnh",GetClipMaxX+256,GetCenterY-100,0,0,cutinImg);
	}

	if(type=="YAMAME"){
		SetCommonData("cutinType",3); 
		CreateEnemyFromFile(CSD~"cutinFam.dnh",GetClipMaxX+256,GetCenterY-100,0,0,cutinImg);
	}

	if(type=="BYAKUREN"){
		SetCommonData("cutinType",4); 
		CreateEnemyFromFile(CSD~"cutinFam.dnh",GetClipMinX-256,GetCenterY,0,0,cutinImg);
	}
    }
    