#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell 3"]
#Text["  Mononobe no Futo "]
#System["./System.txt"]
#Background["./Background.dnh"]
#Player["./player/YukaMarisa/YukaMarisa.dnh"]

let bossObj;
let attack = false;
let BossX = 0;
let BossY = 0;

let shot = GetCurrentScriptDirectory ~ "se/Shot1.wav";
let shot3 = GetCurrentScriptDirectory ~ "se/Shot3.wav";
let wave = GetCurrentScriptDirectory ~ "se/BulletWave.wav";
let eff = GetCurrentScriptDirectory ~ "se/Eff1.wav";
let laser = GetCurrentScriptDirectory ~ "se/Laser3.wav";
let Anim_Attack = 0;

#include "./Render.dnh"
#include "./shot/AllStarShot_Const.dnh"

@Initialize{
	// Initialize: Works when starting up Danmakufu PH3

	//  Defines a Boss and Registers it.
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	
	NameFuto;
	AnimateBossFuto(bossObj);
	ObjMove_SetDestAtWeight(bossObj,GetStgFrameWidth/2,GetStgFrameHeight/2-64,15,5);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	
	
	mainTask; //Runs Maintask
	
}

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

}

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

}

@Finalize{


}

// Your best friend. FOREVER!!! The Wait Function
function wait(w) { loop(w){ yield;} }
task mainTask{
	end;	
	wait(100);
	ConcentrationQ;
	wait(80);
	fire;
}


task fire{
	let spin = 0;
	let dir = 0;
	let a = 18;
	let x = 0;
	let i = 0;
	
	loop{
	ascent(i in 0..10){
	
		while(x<a){
		
			Play(shot);
			wave1;
			wave2;
			Anim_Attack = 1;
			task wave1{
				let obj = CreateShotA1(BossX+0*cos(dir+spin),BossY+0*sin(dir+spin),3,dir+spin,366,10);
				ObjMove_SetAcceleration(obj,-0.033);
				ObjMove_SetMaxSpeed(obj,0.1);
				wait(150+i*6.5);
				Play(wave);
				ObjMove_SetAngle(obj,ObjMove_GetAngle(obj)+90);
				ObjMove_SetAngularVelocity(obj,0.125+i/40);
				ObjShot_SetGraphic(obj,364);
				ObjMove_SetAcceleration(obj,0.05);
				ObjMove_SetMaxSpeed(obj,2.5);
			}
			
			task wave2{
				let obj = CreateShotA1(BossX+0*cos(dir-spin),BossY+0*sin(dir-spin),3,dir-spin,366,15);
				ObjMove_SetAcceleration(obj,-0.033);
				ObjMove_SetMaxSpeed(obj,0.1);
				wait(155+i*6.5);
				Play(wave);
				ObjMove_SetAngle(obj,ObjMove_GetAngle(obj)-90);
				ObjMove_SetAngularVelocity(obj,-0.125-i/40);
				ObjShot_SetGraphic(obj,364);
				ObjMove_SetAcceleration(obj,0.05);
				ObjMove_SetMaxSpeed(obj,2.5);
			}
			
			dir+=360/a;
			x++;
			spin+=2/a;
		}
		x = 0;
		dir = 0;
		wait(15);
	}
	Anim_Attack = 0;
	wait(10);
	RandMove(bossObj,70,70,15,10,192,128,GetStgFrameWidth-192,GetStgFrameHeight/2-64);
	wait(140);
	}
}


task end{
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){ yield;}
	
	Obj_Delete(bossObj);
	Anim_Attack = 0;
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	

	CloseScript(GetOwnScriptID());
}