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

let bossObj;
let bossX;
let bossY;
let damage = 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);
	ObjMove_SetDestAtFrame(bossObj,192,104,5);
	SetCommonData("ForceLifebar",0);
	SetCommonData("WaveCircle",1);
	SetCommonData("Music",1);
	SetCommonData("Timer",0);
	SetCommonData("End",0);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	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(30);}}

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

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

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

@Finalize{}

task mainTask{TEtama;damage=1;
	while(!Obj_IsDeleted(bossObj)){
	attack=1;wait(30);TShot(1);wait(30);TShot(-1);wait(120);
	ascent(i in -1..2){THelix(i*60,0);THelix(i*60,180);}
	wait(60);attack=0;
	ObjMove_SetDestAtWeight(bossObj,192+rand(-50,50),120+rand(-20,20),5,2);
		wait(60);}}

task THelix(ang,turn){
	let color = 255;
	let speed = 5;
	let move = 0;
	let rad = 0;
	ShotSE();
	loop(60){
		if(Obj_IsDeleted(bossObj)){break;}
		let shot = CreateShotA1(bossX+rad*sin(move+turn+ang),bossY+rad*cos(move+turn+ang),3,0,371,10);
		ObjMove_AddPatternA1(shot,0,NO_CHANGE,GetAngleToPlayer(shot)+ang);
		ObjRender_SetColor(shot,255,color,color);
	rad+=2;move+=8;color-=1;yield;}}

task ShotSE{loop(25){PlaySE(sho);wait(3);}}

task TShot(turn){
	PlaySE(sho);
	ascent(ang in 0..15){ ascent(speed in 0..5){
		let obj = CreatePotato(bossX,bossY);
		ObjMove_AddPatternA3(obj,0,2+speed/1,ang*24,0,0,0,NO_CHANGE);
		ObjMove_AddPatternA3(obj,10,NO_CHANGE,NO_CHANGE,0,5*turn,0,NO_CHANGE);
		ObjMove_AddPatternA3(obj,60,NO_CHANGE,NO_CHANGE,0,0.6*turn,0,NO_CHANGE);
		ObjMove_AddPatternA3(obj,90,ObjMove_GetSpeed(obj)-1.5,NO_CHANGE,0,0.6*turn,0,NO_CHANGE);
		ObjMove_AddPatternA3(obj,180,NO_CHANGE,NO_CHANGE,0,0,0,NO_CHANGE);}}}

function CheckOutsideScreenA2(x, y, distance){
	return x>GetStgFrameWidth+distance||x<-distance||y>GetStgFrameHeight+distance||y<-distance;}

function CreatePotato(x,y){
	let spirit = CreateEnemy(100);
	ObjMove_SetPosition(spirit,x,y);
	DrawEnemy(spirit);
	return spirit;}

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

task DrawEnemy(id){
	let enemyX;
	let enemyY;
	let angleZ = rand(0,180);
	ObjPrim_SetTexture(id,akishot);
	while(!Obj_IsDeleted(id)){
		enemyX = ObjMove_GetX(id);
		enemyY = ObjMove_GetY(id);
		ObjSprite2D_SetDestCenter(id);
		ObjSprite2D_SetSourceRect(id,76,211,106,239);
		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+=2;yield;}}