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

#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;
	TLife(objEnemy,180,20,20,2.5,2.5,10,5);
	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("Consumption \"Mountain Harvest\"");
	TXY;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-50,15,5);
	EnemySpell = true;
	loop(90){yield;}
	EnemySpell2 = true;
	let spread = 30;
	loop
		{
		ascent(i0 in 0..2)
			{
			i0 = i0*2-1;
			let angle = rand(0,360);
			ascent(i in 0..spread)
				{
				TShot(enmx+i0*75,enmy,0,i*360/spread+angle,i*360/spread+angle,1,0.5+i0*0.5);
				}
			PlaySound(se_DeepShotHigh,80);
			loop(180){yield;}
			}
		}

	task TShot(x,y,speed,angle,angle1,dir,graph)
		{
		let accel = dir*0.0875-0.025*(dir+1)/2;
		if(x < 0-8 || x > GetStgFrameWidth+8 || y < 0-8 || y > GetStgFrameHeight+8){return;}
		let obj = CreateShotA2(x,y,speed,angle,accel,5+dir*5,DS_RICE_S_RED+120.5-dir*120.5+graph,16);
		loop(16){yield;}
		loop(50){yield;}
		if(Obj_IsDeleted(obj)){return;}
		TShot(ObjMove_GetX(obj),ObjMove_GetY(obj),ObjMove_GetSpeed(obj),GetAngleToPlayer(obj)/2+dir*GetAngleToPlayer(obj)/2+angle1/2-dir*angle1/2,angle1,-dir,graph);
		if(dir == 1)
			{
			PlaySound(se_CuteShotLong,80);
			}
		Obj_Delete(obj);
		}
}		

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);
		
}