
#Title["NonSpell 6"]
#Text["6th NonSpell Attack"]
#include"./Index.txt"

let bossObj;
let bossX = 0;
let bossY = 0;
let AnimFrame = 0;
let AnimFrame2 = 0;

let imgBoss = CSD ~ "/Texture/Ferry.png";
let AttackSFX = CSD ~ "/SFX/ATTACK3.wav";
let Attack2SFX = CSD ~ "/SFX/TWINKLE3.wav";

@Initialize {

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

	ObjMove_SetPosition(bossObj,190,-100);
	ObjMove_SetDestAtWeight(bossObj,190,120,8,5);
	
	LoadSound(AttackSFX);
	LoadSound(Attack2SFX);
	mainTask;
 }

@Event {
	
	alternative(GetEventType())
	case(EV_REQUEST_LIFE) {
		SetScriptResult(3500);
	}		
	case(EV_REQUEST_TIMER) {
		SetScriptResult(50);
	}
 }

@MainLoop {
	
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	
	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,15);
		
	yield;
 }

@Finalize {

 }

task mainTask{
	renderBoss;
	callbackboss;
	Fire;
	Fire2;
	Fire3;
	//movement;
	TEnd;
 }
 
task movement{
	wait(70);
	loop{
		ObjMove_SetDestAtFrame(bossObj,rand(270,111),rand(90,131),100);
		wait(100);
	}
}
 
task renderBoss{
	let Z=0;
	let X=0;
	let dir;
	
	ObjPrim_SetTexture(bossObj, imgBoss);
	ObjSprite2D_SetSourceRect(bossObj,0,0,250,250);
	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.4+0.03*sin(Z),0.4-0.03*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.4+0.03*sin(Z),0.4-0.03*sin(Z),0);
				Z+=3;
				ObjRender_SetAngleXYZ(bossObj,0,X,0);
				if(X<180){X+=2;}
		wait(1);
			}}
		yield;
	}
 }
 
task Fire{
	wait(120);
	let B = rand(360,0);
	let angle= 0;
	loop{
		loop(40){
		while (angle<360){
			let obj = CreateShotA2(bossX+40*sin(angle+B),bossY-40*cos(angle+B),5,angle+B-90,-0.1,2,108,12);
			angle+=360/10;
		}
		angle=0;
		B-=1.2;
		if(ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0) {break;}
		wait(3);
		}
		Fire3;
		wait(120);
		B = rand(360,0);
		loop(40){
		while (angle<360){
			let obj = CreateShotA2(bossX+40*sin(angle+B),bossY-40*cos(angle+B),5,angle+B-90,-0.1,2,108,12);
			angle+=360/10;
		}
		angle=0;
		B+=1.2;
		if(ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0) {break;}
		wait(3);
		}
		Fire3;
		wait(120);
		B = rand(360,0);
		yield;
	}
}
 
task Fire2{
	wait(120);
	let B = rand(360,0);
	let angle= 0;
	loop{
		loop(40){
		PlaySound(Attack2SFX);
		while (angle<360){
			let obj = CreateShotA2(bossX+30*sin(angle+B),bossY-30*cos(angle+B),5,angle+B-90,-0.1,2,110,12);
			angle+=360/5;
		}
		angle=0;
		B+=1.6*3;
		if(ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0) {break;}
		wait(3);
		}
		wait(120);
		B = rand(360,0);
		loop(40){
		PlaySound(Attack2SFX);
		while (angle<360){
			let obj = CreateShotA2(bossX+30*sin(angle+B),bossY-30*cos(angle+B),5,angle+B-90,-0.1,2,110,12);
			angle+=360/5;
		}
		angle=0;
		B-=1.6*3;
		if(ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0) {break;}
		wait(3);
		}
		wait(120);
		B = rand(360,0);
		yield;
	}
}
 
task Fire3{
	ObjMove_SetDestAtFrame(bossObj,rand(270,111),rand(90,131),60);
	wait(60);
	let B = rand(360,0);
	let angle= 0;
	PlaySound(AttackSFX);
		while (angle<360){
			let obj = CreateShotA2(bossX+35*sin(angle+B),bossY-35*cos(angle+B),6,angle+B-90,-0.1,0,301,12);
			let obj2 = CreateShotA2(bossX+35*sin(angle+B),bossY-35*cos(angle+B),6,angle+B-90,-0.1,0,301,12);
			ObjMove_AddPatternA2(obj,30,0,NO_CHANGE,0.1,0.5,2);
			ObjMove_AddPatternA2(obj2,30,0,NO_CHANGE,0.1,-0.5,2);
			ObjMove_AddPatternA2(obj,120,2,NO_CHANGE,0.1,0,2);
			ObjMove_AddPatternA2(obj2,120,2,NO_CHANGE,0.1,0,2);
			angle+=360/30;
		}
}

 task TEnd {
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0) {
		yield;
	}
	DeleteShotAll(TYPE_ALL,TYPE_ITEM);
	Obj_Delete(bossObj);
	ResetShaderI(0, 100);
	wait(60);
	DeleteShotAll(TYPE_ALL,TYPE_FADE);
	CloseScript(GetOwnScriptID);
}