#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Minoriko NonSpell 04"]
#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(45);}}

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

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

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

@Finalize{}

task mainTask{wait(1);TEtama;dam=1;let ra;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);
	ObjMove_SetDestAtWeight(bossObj,192,100,5,4);wait(60);
	while(!Obj_IsDeleted(bossObj)){ra = rand(0,24);
	TShot(1,ra);wait(35);TShot(-1,ra);
	ObjMove_SetDestAtWeight(bossObj,192+rand(-10,10),140,5,2);
		wait(35);}}

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

task TShot(turn,r){
	if(!Obj_IsDeleted(bossObj)){
	PlaySE(sho);
	ascent(ang in 0..15){ ascent(speed in 0..3){
		let obj = CreatePotato(bossX,bossY);
		ObjMove_AddPatternA3(obj,0,3+speed/1.5,ang*24+r,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.5*turn,0,NO_CHANGE);
		ObjMove_AddPatternA3(obj,120,NO_CHANGE,NO_CHANGE,0,0,0,NO_CHANGE);}}}}

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,37,215,72,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,25)){
			Obj_Delete(id);break;}
		angleZ+=2;yield;}}