#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell 1 Normal"]
#Text[" Test "]

let bossObj;
let BossX = 0;
let BossY = 0;
let imgBoss = GetCurrentScriptDirectory ~ "IMG/ghost.png";

#include "script/default_system/Default_ShotConst.txt"
#include "./Render.txt"

@Initialize{
	// Initialize: Works when starting up Danmakufu PH3
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);

	//  Defines a Boss and Registers it.
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	
	
	LoadSound(GetCurrentScriptDirectory ~ "SE/shot5.wav");
	LoadSound(GetCurrentScriptDirectory ~ "SE/shot2.wav");
	
	//Textures the Boss and Indicates the Boss's True Center.
	ObjPrim_SetTexture(bossObj,imgBoss);
	renderBoss;
	Normal;
	ObjSprite2D_SetDestCenter(bossObj);
	
	// Moves Boss to XY Location at wanted Speed (Parameters:Obj,X,Y,V)
	ObjMove_SetDestAtWeight(bossObj,GetStgFrameWidth/2,GetStgFrameHeight/2,10,5);
	
	mainTask; //Runs Maintask
	
}

@Event{
	// Event: Sets the Boss's Specs
	
		// Sets Boss's Life and Timer
		alternative(GetEventType() )
		case(EV_REQUEST_LIFE) {
			SetScriptResult(3500);
		}
		case(EV_REQUEST_TIMER) {
			SetScriptResult(40);
		}

}

@MainLoop{
	// MainLoop: Runs throughout the script.
	
	// Indicates that BossX = GetEnemyX and BossY = GetEnemyY
	BossX = ObjMove_GetX(bossObj);
	BossY = ObjMove_GetY(bossObj);
	
	// Sets the Boss's Collision Circle(Hitbox) For the Shots and Player.
	ObjEnemy_SetIntersectionCircleToShot(bossObj,BossX,BossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,BossX,BossY,24);
	
	yield;
	

}

@Finalize{


}

// Your best friend. FOREVER!!! The Wait Function
function wait(w) { loop(w){ yield;} }

task mainTask{
	end;
	MagicCircle;
	wait(100);
	ConcentrationQ;
	wait(110);
	fire4;
	fire5;
	loop{
	fire3;
	wait(320);
	fire2;
	wait(320);
	}
}

task fire2{
	let spin = 0;
	let dir = 0;
	let x = 0;
	let i = 0;
	
	ascent(i in 0..5){
		while(x<3){
		PlaySE(GetCurrentScriptDirectory ~ "SE/shot5.wav");
		let obj = CreateShotA1(BossX+20*cos(dir-i*6),BossY+20*sin(dir-i*6),5,dir,115,30);
		
			ObjMove_AddPatternA3(obj,0,1,dir-i*6,-0.005,-0.5,-2,212);
			
		let obj1 = CreateShotA1(BossX+20*cos(dir-i*6),BossY+20*sin(dir-i*6),5,dir,115,30);
		
			ObjMove_AddPatternA3(obj1,0,1,dir-i*6,-0.005,0.5,-2,212);
			
			dir+=360/3;
			x++;
			spin++;
		}
		x = 0;
		dir = 0;
		wait(10);
	}
	if(spin == 359){
		spin = 0;
	}
	
}

task fire3{
	let spin = 0;
	let dir = 0;
	let x = 0;
	let i = 0;
	
	ascent(i in 0..5){
		while(x<3){
		PlaySE(GetCurrentScriptDirectory ~ "SE/shot5.wav");
		let obj = CreateShotA1(BossX+20*cos(dir+i*6),BossY+20*sin(dir+i*6),5,dir,113,30);
		
			ObjMove_AddPatternA3(obj,0,1,dir+i*6,-0.005,0.5,-2,210);
			
		let obj1 = CreateShotA1(BossX+20*cos(dir+i*6),BossY+20*sin(dir+i*6),5,dir,113,30);
		
			ObjMove_AddPatternA3(obj1,0,1,dir+i*6,-0.005,-0.5,-2,210);
			
			dir+=360/3;
			x++;
			spin++;
		}
		x = 0;
		dir = 0;
		wait(10);
	}
	if(spin == 359){
		spin = 0;
	}
	
}

task fire4{
	let spin = 0;
	let dir = 0;
	let x = 0;
	let i = 0;
	
	loop{
		ascent(i in 10..50){
			while(x<3){
	let soundObj = ObjSound_Create;
	ObjSound_Load(soundObj,GetCurrentScriptDirectory ~ "SE/shot2.wav");
	ObjSound_SetVolumeRate(soundObj,85);
	ObjSound_Play(soundObj);
			let obj = CreateShotA1(BossX+20*cos(dir-(i*2)-45),BossY+20*sin(dir-(i*2)-45),i,dir,175,30);
			
				ObjMove_AddPatternA3(obj,0,5,dir-(i*2)-90,-0.05,-0.4,-1,175);
				
				dir+=360/3;
				x++;
				spin++;
			}
			x = 0;
			dir = 0;
			wait(5);
		}
		wait(150);
	}
	if(spin == 359){
		spin = 0;
	}
	
}


task fire5{
	let spin = 0;
	let dir = 0;
	let x = 0;
	let i = 0;
	
	wait(150);
	loop{
		ascent(i in 10..50){
			while(x<4){
	let soundObj = ObjSound_Create;
	ObjSound_Load(soundObj,GetCurrentScriptDirectory ~ "SE/shot2.wav");
	ObjSound_SetVolumeRate(soundObj,85);
	ObjSound_Play(soundObj);
			let obj = CreateShotA1(BossX+20*cos(dir+(i*2)+45),BossY+20*sin(dir+(i*2)+45),i,dir,173,30);
			
				ObjMove_AddPatternA3(obj,0,5,dir+(i*2)-90,-0.05,0.4,-1,173);
				
				dir+=360/3;
				x++;
				spin++;
			}
			x = 0;
			dir = 0;
			wait(5);
		}
		wait(150);
	}
	if(spin == 359){
		spin = 0;
	}
	

}

task end{
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){ yield;}

	Obj_Delete(bossObj);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	

	CloseScript(GetOwnScriptID());
}