
#ScriptVersion[3]
#Title["Nonspell 2"]
#Text[" Parsee Mizuhashi "]
#System["./System.txt"]
#Background["./Background.dnh"]

let bossObj;
let BossX = 0;
let BossY = 0;
let shot = GetCurrentScriptDirectory ~ "se/shot.wav";
let wave = GetCurrentScriptDirectory ~ "se/wave.wav";
let imgBoss = GetCurrentScriptDirectory ~ "img/Parsee.png";

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

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

	//  Defines a Boss and Registers it.
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	
	Render;
	
	//Textures the Boss and Indicates the Boss's True Center.
	ObjPrim_SetTexture(bossObj,imgBoss);
	ObjSprite2D_SetDestCenter(bossObj);
	
	// Moves Boss to XY Location at wanted Speed (Parameters:Obj,X,Y,V)
	ObjMove_SetDestAtWeight(bossObj,GetScreenWidth/2,GetScreenHeight/2-128,15,10);
	
	mainTask; //Runs Maintask
	
}

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

}

@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,20);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,BossX,BossY,20);
	
	yield;

}

@Finalize{


}

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

task mainTask{
	wait(80);
	movement;
	ConcentrationQ;
	wait(70);
	fire;
	end;
}

task movement{
	wait(100);
	loop{
		RandMove(bossObj,100,100,10,5,64,64,GetScreenWidth-64,GetScreenHeight/2-64);
		wait(70);
	}
}

task fire{
	let spin = 0;
	let dir = 0;
	let x = 0;
	sound;
	loop{
		ascent(k in 0..3){
			ascent(i in 0..3){
				while(x<45){
					let obj = CreateShotA1(BossX,BossY,3,dir,46,30);
					ObjMove_AddPatternA3(obj,0,5,dir+spin,-0.1,0,0,46);
					ObjMove_AddPatternA3(obj,60,2,dir+spin,-0.1,0,2,43);
					ObjRender_SetScaleXYZ(obj,0.75,0.75,0.75);
				
					let obj1 = CreateShotA1(BossX,BossY,3,dir,46,30);
					ObjMove_AddPatternA3(obj1,0,5,dir-spin,-0.1,0,0,46);
					ObjMove_AddPatternA3(obj1,60,3,dir-spin*2,-0.1,0,3,46);
					ObjRender_SetScaleXYZ(obj1,0.75,0.75,0.75);
					
					spin+=0.0125;
					dir+=360/45;
					x++;
				}
				x = 0;
				dir = 0;
			}
		wait(10);
		}
	wait(70);
	}
}

task sound{
	loop{
	wait(30);
		ascent(a in 0..3){
		Play(shot);
		wait(10);
		}
		ascent(s in 0..3){
		Play(wave);
		wait(10);
		}
	wait(10);
	}
}

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

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

	CloseScript(GetOwnScriptID());
}