#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell 4"]
#Text["Woop"]

let objBoss;
let BossX;
let BossY;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderorin(objBoss);
	BossShotSound(objBoss, 100, 600);
	BottomEnemyMarker(objBoss, objBoss);
	
	ObjMove_SetDestAtWeight(objBoss,384/2,150,5,5);
	mainTask;
	//widescreen;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4500);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(50);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,24);
	yield;
} 

@Finalize {

} 
task mainTask { 
wait(90);
let reverse = 1;
loop{
	attack = true;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargelong.wav", 50);
	wait(20);
	let angle = rand(0,360);
	loop(8){
		let obj = SummonGhost(ObjMove_GetX(objBoss)+24, ObjMove_GetY(objBoss)-35,400,3000, false,false);
		MoveFunction(obj, 0.5, angle, 0.01, 4);
		ObjMove_SetAngularVelocity(obj, 0.4*reverse);
		Behavior(obj);
		angle += 360/8;
	}
		if(reverse==-1){reverse=1;}
		else{reverse=-1;}
	wait(90);
	attack = false;
	wait(180);
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2+rand(-50,50),150+rand(-25,25),15,5);
	wait(60);
	}
}

task Behavior(obj){
	Shoot;
	while(!Obj_IsDeleted(obj)){
		if(trunc(ObjRender_GetX(obj))>GetStgFrameWidth){Glow; Obj_Delete(obj);}
		if(trunc(ObjRender_GetX(obj))<0){Glow; Obj_Delete(obj);}
		if(trunc(ObjMove_GetY(obj))>GetStgFrameHeight){Glow; Obj_Delete(obj);}
		if(trunc(ObjRender_GetY(obj))<0){Glow; Obj_Delete(obj);}
		yield;
		}
		task Glow{
		GlowExplosion(obj, 25, 25, 10, true, -1, 0, false, ORB_BLUE, 35);
			let angle = GetAngleToPlayer(obj);
			loop(12){
			let shot = CreateShotA2(ObjMove_GetX(obj)+30*cos(angle), ObjMove_GetY(obj)+30*sin(angle), 0.5, angle,0.01, 4, LARGE_BLUE, 25);
			angle += 360/12;
			}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/explosion.wav", 60);
		}
		task Shoot{
		while(!Obj_IsDeleted(obj)){
			let angle = 0;
			loop(8){
			let shot = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0.5, angle,0.015, 5, SMALL_BLUE, 10);
			angle += 360/8;
			}
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 50);
			wait(60);
		}
		}
	}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
	SetCommonData("deathsound",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
