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

#include"./functions1.txt"

timer = 60;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	
	TEnemyWork;
	ObjEnemy_Render;
	ObjEffect_Shadow(false);
	TLife(objEnemy,240,20,20,2.5,2.5,15,7.5);
	TEnd;
}

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

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(500);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(timer);
		}
}

task TEnemyWork
{
	TXY;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-96,15,5);
	loop(90){yield;}
	let angleA = [60,90,45];
	TShot1;
	TShot2;
	TShot3;
	task TShot3
		{
		let spread = 8;	
		let time = 20;
		loop
			{
			ascent(i in 0..spread)
				{
				i = i-spread/2+0.5;
				CreateShotOA2(objEnemy,10,i*90/spread+GetAngleToPlayer(objEnemy),-10/15,3,DS_RICE_S_SKY,0);
				}
			PlaySound(se_DeepShotHigh,77.5);
			loop(ceil(time)){yield;}
			if(time > 6)
				{
				time-=1;
				}
			}
		}
	task TShot2
		{
		let spread = 3;
		loop
			{
			ascent(i in 0..2)
				{
				i = i*2-1;
				ascent(i0 in 0..3)
					{
					i0 -=1;
					ascent(i1 in 0..3)
						{
 						i1-=1;
						let angle0 = 270+i*60+i*i0*angleA[0]/3;
						CreateShotA1(enmx+64*cos(angle0),enmy+48*sin(angle0),6,(angle0-270)*3.5+90+i*60+i1*(60-i0*30)/3,DS_ICE_GREEN,8);	
						}
					}
				}
			loop(10){yield;}
			}
		}	
	task TShot1
		{
		let spread = [3,3,3];
		let time = 30;
		loop
			{
			ascent(i3 in 0..2)
				{
				i3 = i3*2-1;
				loop(8)
					{
					ascent(i in 0..2)
						{
						i = i*2-1;
						ascent(i0 in 0..spread[0])
							{
							i0 = i0-spread[0]/2+0.5;
							ascent(i1 in 0..spread[1])
								{
								i1 = i1-spread[1]/2+0.5;
								ascent(i2 in 0..spread[2])
									{
									i2 = i2-spread[2]/2+0.5;
									let angle0 = 270+i*60+i*i0*angleA[0]/spread[0];
									let angle1 = angle0+i*105+i*i1*angleA[1]/spread[1];
									let angle2 = -i*i2*angleA[2]/spread[2];
									let obj = CreateShotA2(enmx+48*cos(angle0),enmy+32*sin(angle0),6,angle0,-6/time,0,DS_ICE_D_GREEN+i3*4,16);
									ObjMove_AddPatternA2(obj,time*1.25,6,angle1,-6/time,0,0);
									ObjMove_AddPatternA4(obj,time*2.5,4.5,angle2,0,0,0,GetPlayerObjectID,NO_CHANGE);
									}
								}
							}
						}
					PlaySound(se_CuteShotShort,77.5);
					PlaySound(se_DeepShotMed,77.5);
					loop(5){yield;}
					}
				loop(45){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);
		
}