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

#include "./functions2.txt"

timer = 52;

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

	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID());
	bspell = true;

	TEnemyWork;
	ObjEnemy_Render; 
	TLife(450,20,20,0,0,11,11);
	TEnd;
}

@MainLoop
{
	yield;
}

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

task TEnemyWork
{
	TXY;
	TSpellName;
	TSpellFace(pathReisen);
	loop(60){yield;}
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-90,15,5);
	loop(45){yield;}
	let spread = [5-Dif*2,5,1,2];	
	let counter = 0;
	loop
		{
		let angleA = 30;
		descent(i in 0..2)
			{
			i = i*2-1;
			ascent(t in 0..3)
				{
				ascent(dir in 0..2)
					{
					TShot(angleA,dir*2-1);
					loop(105)
						{
						counter+=1;
						if(counter%135 == 0)
							{
							ObjEnemy_Move(objEnemy,30,2,20,20,75,105,125,0);
							}
						yield
						}
					angleA+=i*15/6;
					}
				}
			}
		}
	task TShot(angleA,dir)
		{
		PlaySound("se_Shot3",100);
		PlaySound("se_Shot5B",40);
		let scale = 0;
		let angle = 90-dir*angleA;
		let speed = 3;
		let accel = dir*1/10;
		let max = dir*10;
		let shot = CreateBulletB2(GetStgFrameWidth/2-dir*(GetStgFrameWidth/2-10),-32,speed*cos(angle),speed*sin(angle),accel,0,max,0,DS_TEWI,0,0);
		Obj_SetRenderPriority(shot,0.51);
		ObjShot_SetSpellResist(shot,true);
		let angleZ = angle*2;
		angleA = (round(rand(0,1))*2-1)*rand(2,7);
		let counter = floor(rand(0,spread[1]));
		while(!Obj_IsDeleted(shot) && ObjMove_GetY(shot) < GetStgFrameHeight+16)
			{
			counter+=1;
			speed = ObjMove_GetSpeed(shot);
			angle = ObjMove_GetAngle(shot);
			if(counter%spread[0] == 0 && floor(counter/spread[0])%spread[1] >= spread[2])
				{
				PlaySound("se_Shot4",35);
				ascent(t in 0..2)
					{
					ascent(i in 0..spread[3])
						{
						let spam = CreateBulletOA1(shot,0,angle+dir*(25+i*17.5/spread[3])+t*180,DS_BILL_RED,8,1.25);
						ObjMove_AddPatternA2(spam,120,NO_CHANGE,NO_CHANGE,1/75,0,1.5+i*0.75/spread[3]);
						if(dir*((i%2)*2-1) == 1)
							{
							ObjShot_SetGraphic(spam,DS_BILL_WHITE);
							}
						}
					}
				}
			angleZ+=angleA;
			if(scale < 1.125)
				{
				scale+=1.125/15;
				}
			else
				{
				scale = 1.125;
				}
			if(ObjMove_GetX(shot) < scale*16 || ObjMove_GetX(shot) > GetStgFrameWidth-scale*16)
				{
				speed*=0.95;
				angle = 180-angle;
				ObjMove_AddPatternB2(shot,0,speed*cos(angle),speed*sin(angle),accel,0,max,0);
				ObjMove_SetX(shot,GetStgFrameWidth/2-(GetStgFrameWidth/2-ObjMove_GetX(shot))*0.99);
				PlaySound("se_Shot5",100);
				PlaySound("se_Shot3",100);
				PlaySound("se_Shot5B",40);
				}
			ObjRender_SetAngleZ(shot,angleZ-angle);
			ObjShot_SetScale(shot,scale);
			yield;
			}
		}
}	