#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell4N"]

#include"./functions1.txt"

timer = 60;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID());
	
	TEnemyWork;
	ObjEnemy_Render;
	ObjEffect_Shadow(true);
	TLife(objEnemy,180,20,20,2.5,2.5,7.5,3.75);
	TEnd;
}

@MainLoop
{
	timer-=1/60;
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(500);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(timer);
		}
	case(EV_REQUEST_SPELL_SCORE)
		{
		SetScriptResult(30000);
		}
	case(EV_START_BOSS_SPELL)
		{
		SetScriptResult(true);
		}
}

task TEnemyWork
{
	TSpellName("Old God \"Yasaka of the Wind and Rain\"");
	TXY;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-70,15,5);
	loop(90){yield;}
	let dirA = 0;
	let spread = 12;
	TSpam1;
	loop
		{
		loop(150)
			{
			dirA+=0.5;
			yield;
			}
		TMovement;
		}
	task TSpam1
		{
		let counter = 0;
		let time = 8;
		loop
			{
			counter+=1;
			if(counter%ceil(time) == 0)
				{
				TShot1;
				PlaySound(se_DeepShotMed,76.5);
				if(time > 6)
					{
					time-=0.0625;
					}
				}
			yield;
			}
		}
	task TShot1
		{
		let dirB = rand(-1,1)*15;
		let x = rand(-32,GetStgFrameWidth+32);
		let y = rand(0,GetStgFrameHeight/3);
		let speed = 1+1.5*absolute(cos(90+90*sin(dirA)));
		let angle = 90+30*sin(dirA+dirB);
		let obj =
				[
				CreateShotA2(x,y,0,angle,0.025,speed,DS_BALL_S_GREEN-round(rand(0,1)),5),
				CreateShotA2(x,y,0,angle,0.05,speed,DS_RICE_S_D_SKY+round(rand(0,1)),5),
				];
		ObjRender_SetAlpha(obj[0],200);
		ObjRender_SetBlendType(obj[0],BLEND_ADD_ARGB);
		TMove;
		while(!Obj_IsDeleted(obj[1]) && ObjMove_GetY(obj[1]) < GetStgFrameHeight){yield;}
		PlaySound(se_CuteShotLong,77.5);
		ObjMove_AddPatternB2(obj[1],0,1.5*cos(ObjMove_GetAngle(obj[1])),-rand(1,1.5),0,0.0125,0,10);
		task TMove
			{
			let counter = 0;
			while(!Obj_IsDeleted(obj[0]))
				{
				counter+=1;
				if(counter < 60)
					{
					ObjMove_SetAngle(obj[0],90+60*sin(dirA+dirB));
					}
				yield;
				}
			}
		}

}		

task TMovement
{
	let distM = 25;
	let distm =distM/2;
	let numb = round(rand(0,1))*2-1;
		if(ObjMove_GetX(objEnemy) < 175)
			{
			numb =1;	
			}
		else if (ObjMove_GetX(objEnemy) > GetStgFrameWidth-175)
			{	
			numb = -1;
			}
	ObjMove_SetDestAtWeight(objEnemy,ObjMove_GetX(objEnemy)+numb*rand(distm,distM),rand(120,170),30,5);
		
}