#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Minoriko NonSpell 03"]
#include"./LoadGraphics.txt"
#include"./../Functions/Enemy_Functions.txt"

let bossObj;
let bossX;
let bossY;
let dam = 0;

let short = GetCurrentScriptDirectory ~ "./../Sounds/se_ch00.wav";
let kira = GetCurrentScriptDirectory ~ "./../Sounds/se_kira02.wav";
let sho = GetCurrentScriptDirectory ~ "./../Sounds/se_tan00b.wav";
let sho1 = GetCurrentScriptDirectory ~ "./../Sounds/se_tan01.wav";
#include"./DrawBoss.txt"

@Initialize{
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	SetCommonData("End",0);
	LoadShotData;
	animateBossM;
	mainTask;
	TEnd;

	LoadSound(sho);
	LoadSound(sho1);
	LoadSound(kira);
	LoadSound(short);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(1200);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	if(dam==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(dam==1){ObjEnemy_SetDamageRate(bossObj, 50, 25);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);
	yield;}

@Finalize{}

task mainTask{
	wait(1);TEtama;
	ObjMove_SetDestAtWeight(bossObj,192,120,5,4);let r = 0;
	loop(80){PowerS(bossX+r*cos(r*15),bossY+r*sin(r*15));r+=1;}r = 0;
	loop(80){Point(bossX+r*cos(r*15+180),bossY+r*sin(r*15+180));r+=1;}
	ascent(i in 0..25){Fruit(bossX+80*cos(i*14.4),bossY+80*sin(i*14.4));}
	wait(120);
	THarvesterWreath(2.3,180,1);wait(30);
	THarvesterWreath(2.0,150,-1);wait(120);
	TLightAura;
	wait(30);dam=1;
	TShot;wait(150);
	THelixSt;
	wait(150);
	TMove;}

task THelixSt{
	while(!Obj_IsDeleted(bossObj)){
		THelix(0,1);
		THelix(180,-1);
		wait(180);}}

task TMove{ let move = 0;let move2 = 270;
	while(!Obj_IsDeleted(bossObj)){
		ObjMove_SetDestAtWeight(bossObj,192+150*cos(270+120*sin(move)),192+150*sin(270+120*sin(move)),1,1);
		move+=0.5;yield;}}
		
task THelix(ang,turn){
	let move = 0;let r = 0;
	TSeShot;
	loop(60){
		let shot = CreateCarrot(bossX+r*sin(move+turn+ang),bossY+r*cos(move+turn+ang),0.5,0,1);
		ObjMove_AddPatternA1(shot,0,NO_CHANGE,GetAngleToPlayer(shot));
		ObjMove_AddPatternA1(shot,60,5,GetAngleToPlayer(shot));
		if(Obj_IsDeleted(bossObj)){break;}
		if(r==90){r=90;}
	r+=3;move+=10;yield;}}

task TSeShot{loop(20){PlaySE(sho);wait(3);}}

task TShot{
	let m = 0; let tr = 0;
	while(!Obj_IsDeleted(bossObj)){
		PlaySE(sho);
		ascent(ang in 0..12){
			let x = CreateShotA1(bossX+70*cos(ang*30+m),bossY+70*sin(ang*30+m),3,ang*30+m,23,15);
			ObjMove_AddPatternA3(x,0,NO_CHANGE,NO_CHANGE,0,0.6,0,NO_CHANGE);}
			m+=5;
		wait(20);
		PlaySE(sho);
		ascent(ang in 0..12){
			let x = CreateShotA1(bossX+70*cos(ang*30-m),bossY+70*sin(ang*30-m),3,ang*30-m,23,15);
			ObjMove_AddPatternA3(x,0,NO_CHANGE,NO_CHANGE,0,-0.6,0,NO_CHANGE);}
			m+=5;
		wait(20);}}

function CreateCarrot(x,y,speed,angle,graphic){
	let spirit = CreateEnemy(100);
	ObjMove_SetPosition(spirit,x,y);
	ObjMove_SetSpeed(spirit,speed);
	ObjMove_SetAngle(spirit,angle);
	DrawEnemy(spirit,graphic);
	return spirit;}

function CreateEnemy(objlife){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(obj);
	ObjEnemy_SetLife(obj,objlife);
	return obj;}

task DrawEnemy(id,gr){
	let enemyX;
	let enemyY;
	let angleZ = rand(0,180);
	ObjPrim_SetTexture(id,akishot);
	ObjRender_SetScaleXYZ(id,1.2,1.2,0);
	while(!Obj_IsDeleted(id)){
		enemyX = ObjMove_GetX(id);
		enemyY = ObjMove_GetY(id);
		ObjSprite2D_SetDestCenter(id);
			if(gr == 1){ObjSprite2D_SetSourceRect(id,21,159,33,201);}
			if(gr == 2){ObjSprite2D_SetSourceRect(id,1,242,32,269);}
		ObjEnemy_SetIntersectionCircleToPlayer(id,enemyX,enemyY,10);
		ObjRender_SetAngleZ(id,angleZ);
		if(GetCommonData("End",0)!=0){DisappearBulletEffect(enemyX,enemyY,id,255,25,25);}
		if(CheckOutsideScreenA2(enemyX,enemyY,64)){
			Obj_Delete(id);break;}
		angleZ=ObjMove_GetAngle(id)-90;yield;}}