#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell 3 Hard"]
#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);
	
	
	//Textures the Boss and Indicates the Boss's True Center.
	ObjPrim_SetTexture(bossObj,imgBoss);
	renderBoss;
	ObjSprite2D_SetDestCenter(bossObj);
	
	// Moves Boss to XY Location at wanted Speed (Parameters:Obj,X,Y,V)
	ObjMove_SetDestAtSpeed(bossObj,GetStgFrameWidth/2,GetStgFrameHeight/2,5);
	
	mainTask; //Runs Maintask
	
}

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

}

@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(60);
	ConcentrationQ;
	wait(110);
	loop{
	sound;
	fire2;
	fire3;
	wait(550);
	}
}

task sound{
sound2;
	wait(360);
	ConcentrationQ;
	loop(5){
	LoadSound(GetCurrentScriptDirectory ~ "SE/wave3.wav");
	PlaySE(GetCurrentScriptDirectory ~ "SE/wave3.wav");
	wait(30);
	}
}

task sound2{
	wait(240);
	loop(4){
	LoadSound(GetCurrentScriptDirectory ~ "SE/wave.wav");
	PlaySE(GetCurrentScriptDirectory ~ "SE/wave.wav");
	wait(50);
	}
}

task fire2{
	let spin = 0;
	let dir = 0;
	let x = 0;
	let i = 0;
	
	ascent(i in 0..4){
		while(x<6){
	LoadSound(GetCurrentScriptDirectory ~ "SE/effect2.wav");
	PlaySE(GetCurrentScriptDirectory ~ "SE/effect2.wav");
		let obj = CreateShotA1(BossX+0*cos(dir-i),BossY+0*sin(dir-i),i,dir,115,60);
		
			ObjMove_AddPatternA3(obj,0,i+1,dir,-0.05,0,0,255);
			ObjMove_AddPatternA3(obj,240,0,dir-i*4-180+i*5,0.1,0,1.5,255);
			
		let obj1 = CreateShotA1(BossX+0*cos(dir-i),BossY+0*sin(dir-i),i,dir,115,60);
		
			ObjMove_AddPatternA3(obj1,0,i,dir,-0.05,0,0,255);
			ObjMove_AddPatternA3(obj1,240,0,dir-i*4+180-i*5,0.1,0,1.5,255);
			
			dir+=360/6;
			x++;
			spin++;
		}
		x = 0;
		dir = 0;
		wait(50);
	}
	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<14){
	LoadSound(GetCurrentScriptDirectory ~ "SE/effect.wav");
	PlaySE(GetCurrentScriptDirectory ~ "SE/effect.wav");
		let obj = CreateShotA1(BossX+20*cos(dir),BossY+20*sin(dir),5,dir,113,30);
		
			ObjMove_AddPatternA3(obj,0,2,dir+i,-0.05,i/20,-0.5,210);
			ObjMove_AddPatternA3(obj,360,-0.5,dir+i,0.1,i/7.5,2,210);
			
		let obj1 = CreateShotA1(BossX+20*cos(dir),BossY+20*sin(dir),5,dir,113,30);
		
			ObjMove_AddPatternA3(obj1,0,2,dir-i,-0.05,-i/20,-0.5,212);
			ObjMove_AddPatternA3(obj1,360,-0.5,dir-i,0.1,-i/7.5,2,212);
			
			dir+=360/14;
			x++;
			spin++;
		}
		x = 0;
		dir = 0;
		wait(30);
	}
	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());
}