
#include"./Index.txt"

let bossObj;
let bossX = 0;
let bossY = 0;

let imgBoss = CSD ~ "/Texture/Lost Jack.png";
let CAUTIONSFX = CSD ~ "/SFX/CAUTION.wav";
let CHARGESFX = CSD ~ "/SFX/CHARGE.wav";
let WOODSFX = CSD ~ "/SFX/Wood.mp3";

@Initialize {

	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);

	ObjMove_SetPosition(bossObj,190,100);
	
	LoadSound(CAUTIONSFX);
	LoadSound(CHARGESFX);
	LoadSound(WOODSFX);
	mainTask;
 }

@Event {
	
	alternative(GetEventType())
	case(EV_REQUEST_LIFE) {
		SetScriptResult(0);
	}		
 }

@MainLoop {
	
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	
	yield;
 }

@Finalize {

 }

task mainTask{
	wait(3);
	let T =31;
	PlaySound(CAUTIONSFX);
	loop(30){
	PlaySound(CHARGESFX);
		TChargeDark(bossX,bossY);
		wait(T);
		T--;
	}
	loop(60){
	PlaySound(CHARGESFX);
		TChargeDark(bossX,bossY);
		wait(1);
	}
	PlaySound(WOODSFX);
	renderBoss;
	wait(100);
	TEnd;
 }
 
 task renderBoss{
	let Z=0;
	let X=0;
	let dir;
	
	ObjPrim_SetTexture(bossObj, imgBoss);
	ObjSprite2D_SetSourceRect(bossObj,0,0,600,589);
	ObjSprite2D_SetDestCenter(bossObj);
	ObjRender_SetScaleXYZ(bossObj,0.5,0.5,0);
	
	while(!Obj_IsDeleted(bossObj)) {
		dir = ObjMove_GetAngle(bossObj);
		
		if(cos(dir) > 0) {
			loop(90){
				ObjRender_SetScaleXYZ(bossObj,0.2+0.02*sin(Z),0.2-0.02*sin(Z),0);
				Z+=3;
				ObjRender_SetAngleXYZ(bossObj,0,X,0);
				if(X>0){X-=2;}
				wait(1);
			}
		}
		else if(cos(dir) < 0) {
			loop(90){
				ObjRender_SetScaleXYZ(bossObj,0.2+0.02*sin(Z),0.2-0.02*sin(Z),0);
				Z+=3;
				ObjRender_SetAngleXYZ(bossObj,0,X,0);
				if(X<180){X+=2;}
		wait(1);
			}}
		yield;
	}

 }
 
 task TEnd {
	DeleteShotAll(TYPE_ALL,TYPE_ITEM);
	Obj_Delete(bossObj);
	ResetShaderI(0, 100);
	DeleteShotAll(TYPE_ALL,TYPE_FADE);
	CloseScript(GetOwnScriptID);
}