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

#include "./functions2.txt"

timer = 52;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);

	TEnemyWork;
	ObjEnemy_Render; 
	TLife(150,20,20,0,0,13.75,13.75);
	TEnd;
}

@MainLoop
{
	yield;
}

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

task TEnemyWork
{
	TXY;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-115,15,2);
	loop(45){yield;}
	let spread = [5,5,5];
	let spreadA = spread[2]+4-Dif*2;
	let dir = 1;
	let counter = 0;
	loop
		{
		ascent(i in 0..spread[0])
			{
			PlaySound("se_Option2",80);
			TFam(150-i*100/spread[0],dir);
			loop(60)
				{
				counter+=1;
				if(counter%150 == 0)
					{
					ObjEnemy_Move(objEnemy,20,3,50,50,105,125,110,0);
					}
				yield;
				}
			dir*=-1;
			}
		if(spread[0]%2 == 0)
			{
			dir*=-1;
			}
		}
	task TFam(y,dir)
		{
		let scale = 48;
		let obj = CreateBasicEnemyA1(GetStgFrameWidth/2+dir*(GetStgFrameWidth/2+64),y,1.5,90+dir*90+rand(-1,1)*10,50,35,type_flame,flame_blue,scale);
		let counter = [floor(rand(0,spread[1])),floor(rand(0,spread[2]))];
		while(!Obj_IsDeleted(objEnemy) && !Obj_IsDeleted(obj) && counter[0] < (GetStgFrameWidth+128)/1.5+spread[1])
			{
			counter[0]=counter[0]+1;
			if(counter[0]%spread[1] == 0)
				{
				if(counter[1]%spreadA < spread[2])	
					{
					let numb = counter[1]%spreadA;
					let speedM = 3.5+(spread[2]-numb)*1/spread[2];
					let speedm = 1-(Dif+0.75)*0.125+numb*(1+(Dif+0.75)*0.25)/spread[2];
					ascent(i in 0..2)
						{
						TShot(i,numb,speedM,speedm);
						}
					}
				counter[1]=counter[1]+1;
				}
			ObjEnemy_SetIntersectionCircleToShot(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),scale*0.4);	
			yield;
			}
		Obj_Delete(obj);
		task TShot(i,numb,speedM,speedm)
			{
			if(numb == 0)
				{
				PlaySound("se_Shot3",60);
				}
			let shot = CreateBulletOA2(obj,speedM,90+i*180,-speedM/45,0,0,DS_MISSILE_BLUE+((dir+1)/2)*5,8,1.125);
			loop(65){yield;}
			ObjMove_AddPatternA2(shot,0,speedm,ObjMove_GetAngle(shot)+dir*(20+(spread[2]-numb)*(15+Dif*5)/spread[2]),0,0,0);
			}
		}
}	