#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell 2 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);
	
	
	//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(4000);
		}
		case(EV_REQUEST_TIMER) {
			SetScriptResult(50);
		}

}

@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);
	
	SetShotAutoDeleteClip(20,20,20,20);
	
	
	yield;
	
}

@Finalize{


}

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

task mainTask{
	end;
	MagicCircle;
	wait(60);
	ConcentrationQ;
	wait(110);
	fire4;
	fire3;
}


task fire4{
	let spin = 0;
	let dir = 0;
	let x = 0;
	let i = 0;
	let up = 213;
	
	loop{
		ascent(i in 0..4){
			while(x<4){
		LoadSound(GetCurrentScriptDirectory ~ "SE/shot3.wav");
		PlaySE(GetCurrentScriptDirectory ~ "SE/shot3.wav");
			let obj = CreateShotA1(BossX+(20-i)*cos(dir-(spin/3)),BossY+(20-i)*sin(dir-(spin/3)),i,dir,175,30);
			
				ObjMove_AddPatternA3(obj,0,2,dir-(spin),-0.05,0.4,1,up);
				
			let obj1 = CreateShotA1(BossX+(20-i)*cos(dir+(spin/3)),BossY+(20-i)*sin(dir+(spin/3)),i,dir,173,30);
			
				ObjMove_AddPatternA3(obj1,0,2,dir+(spin),-0.05,-0.4,1,up);
				
				dir+=360/4;
				x++;
				spin+=1;
				up+=(1/8);
			}
			x = 0;
			dir = 0;
			
	if(up == 217){
		up = 213;
	}
		}
		wait(90);
	}
	if(spin == 360){
		spin = 0;
	}
	
}

task fire3{
	let spin = 0;
	let dir = 0;
	let x = 0;
	let i = 0;
	let up = 197;
	
	loop{
		ascent(i in 0..1){
			while(x<30){
		LoadSound(GetCurrentScriptDirectory ~ "SE/shot4.wav");
		PlaySE(GetCurrentScriptDirectory ~ "SE/shot4.wav");
			let obj = CreateShotA1(BossX+0*cos(dir+90),BossY+0*sin(dir+90),1,dir,up,30);
			
				ObjMove_AddPatternA3(obj,0,2,dir,-0.005,0,2,up);
				ObjMove_AddPatternA3(obj,10,2,dir,-0.05,0,1,up);
				ObjMove_AddPatternA3(obj,30,1,dir,-0.05,0.4,1,up);
				
			let obj1 = CreateShotA1(BossX+0*cos(dir+90),BossY+0*sin(dir+90),1,dir,up,30);
			
				ObjMove_AddPatternA3(obj1,0,2,dir,-0.005,0,2,up);
				ObjMove_AddPatternA3(obj1,10,2,dir,-0.05,0,1,up);
				ObjMove_AddPatternA3(obj1,30,1,dir,-0.05,-0.4,1,up);
				
				dir+=360/30;
				x++;
				spin+=1;
				up+=(1/60);
			}
			x = 0;
			dir = 0;
			if(up >= 201){
				up = 197;
			}
		}
		wait(160);
	}
	if(spin == 360){
		spin = 0;
	}
	
}

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

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

	CloseScript(GetOwnScriptID());
}