#東方弾幕風
#Title[冷菓「シェイヴドアイス」]
#Text[かき氷。]
#ScriptVersion[2]

script_enemy_main
{
	let count=-60;
	let bg=0;
	let cx=GetCenterX();//STGシーンの中心x座標を取得
	let cy=GetCenterY();//STGシーンの中心x座標を取得
	let name        = "冷菓「シェイヴドアイス」";
	#include_function ".\lib\lib_anime_Remilia.txt"
	let cirno=0;
	let lv = GetCommonDataDefault("lv",2);
	let imageBoss = ".\script\『冷』\img\dot_cirno.png";
	@Initialize{
		CutIn(KOUMA, name, "", 0, 0, 0, 0);
		LoadGraphic(imageBoss);
		InitializeAction();
		SetLife(2000);
		SetTimer(60);
		SetDamageRate(100,100);
       		SetScore(5000000);
		SetMovePosition02(cx,100,60);
		SetAction(ACT_SPELL,60);
		PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
		Concentration02(60);
		LoadGraphic("script\『冷』\img\bg.png");
	}
	
	@MainLoop
	{
		if(0 < GetHitCount)
		{
			PlaySE(".\script\『冷』\sound\enemy_damage.wav");
		}
		if (GetTimer>0 && GetTimer<12 && count%60==0)
		{
			PlaySE(".\script\『冷』\sound\clock.wav");
		}
		count++;
		if (count>0) {
		Cirno;
		if (GetLife>1000)
		{
			if (lv<3)
			{
			if ((count%60==0 && lv==2) || (count%120==0 && lv==1))
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				let x=0;
				loop(5)
				{
					IceShot(x,1);
					x+=cx/2.25;
				}
				SetMovePosition02(rand(50,cx*2-50),rand(50,cy-50),30);
				SetAction(ACT_MOVE,30);
			}
			if ((count%60==30 && lv==2) || (count%120==60 && lv==1))
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				let x=cx/4.5;
				loop(5)
				{
					IceShot(x,1);
					x+=cx/2.25;
				}
				SetMovePosition02(rand(50,cx*2-50),rand(50,cy-50),30);
				SetAction(ACT_MOVE,30);
			}
			} else {
			if ((count%60==0 && lv==4) || (count%120==0 && lv==3))
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				let x=0;
				loop(10)
				{
					IceShot(x,1);
					x+=cx/4.5;
				}
				SetMovePosition02(rand(50,cx*2-50),rand(50,cy-50),30);
				SetAction(ACT_MOVE,30);
			}
			if ((count%60==30 && lv==4) || (count%120==60 && lv==3))
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				let x=cx/9;
				loop(10)
				{
					IceShot(x,1);
					x+=cx/4.5;
				}
				SetMovePosition02(rand(50,cx*2-50),rand(50,cy-50),30);
				SetAction(ACT_MOVE,30);
			}
			}
		} else {
			if (lv<3)
			{
			if ((count%30==0 && lv==2) || (count%60==0 && lv==1))
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				let x=0;
				loop(5)
				{
					IceShot(x,2);
					x+=cx/2.25;
				}
				SetMovePosition02(rand(50,cx*2-50),rand(50,cy-50),15);
				SetAction(ACT_MOVE,15);
			}
			if ((count%30==15 && lv==2) || (count%60==30 && lv==1))
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				let x=cx/4.5;
				loop(5)
				{
					IceShot(x,2);
					x+=cx/2.25;
				}
				SetMovePosition02(rand(50,cx*2-50),rand(50,cy-50),15);
				SetAction(ACT_MOVE,15);
			}
			} else {
			if ((count%30==0 && lv==4) || (count%60==0 && lv==3))
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				let x=0;
				loop(10)
				{
					IceShot(x,2);
					x+=cx/4.5;
				}
				SetMovePosition02(rand(50,cx*2-50),rand(50,cy-50),15);
				SetAction(ACT_MOVE,15);
			}
			if ((count%30==15 && lv==4) || (count%60==30 && lv==3))
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				let x=cx/9;
				loop(10)
				{
					IceShot(x,2);
					x+=cx/4.5;
				}
				SetMovePosition02(rand(50,cx*2-50),rand(50,cy-50),15);
				SetAction(ACT_MOVE,15);
			}
			}
		}

		SetCollisionA(GetX(),GetY(),24);//当たり判定(自弾)登録
		SetCollisionB(GetX(),GetY(),12);//当たり判定(体当たり)登録
		}
		yield;
	}
	@DrawLoop{DrawBoss( imageBoss);}
	@BackGround{SetTexture("script\『冷』\img\bg.png");SetAlpha(64);SetGraphicRect(bg,bg,cx*2+bg,cy*2+bg);bg++;DrawGraphic(cx,cy);SetGraphicRect(-bg,-bg,cx*2-bg,cy*2-bg);DrawGraphic(cx,cy);SetGraphicRect(bg,-bg,cx*2+bg,cy*2-bg);DrawGraphic(cx,cy);SetGraphicRect(-bg,bg,cx*2-bg,cy*2+bg);DrawGraphic(cx,cy);}
	task Cirno
	{
		cirno = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(cirno,GetX,GetY);
		ObjShot_SetGraphic(cirno,RED02);
		Obj_SetAlpha(cirno,0);
		yield;
		Obj_Delete(cirno);
	}
	task IceShot(let x,let speed)
	{
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,0);
		ObjShot_SetDelay(obj,60);
		Obj_SetAngle(obj,90);
		Obj_SetSpeed(obj,speed);
		let img=WHITE03;
		if (speed==2 && rand_int(0,4)==0)
		{
			img=RED03+rand_int(0,7);
		}
		ObjShot_SetGraphic(obj,img);
		while(!Obj_BeDeleted(obj) && ((GetLife>1000 && speed==1) || speed==2))
		{
			if (Collision_Obj_Obj(obj,cirno))
			{
				if (img==WHITE03)
				{
					CreateShot02(Obj_GetX(obj),Obj_GetY(obj),(2400-count)/2000+4,rand(85,95),-0.01,0.1,WHITE02,0);
				} else {
					loop(2){CreateShot02(Obj_GetX(obj),Obj_GetY(obj),(2400-count)/2000+4,rand(85,95),-0.01,0.1,img-8,0);}
				}
				Obj_Delete(obj);
			}
			yield;
		}
		ObjShot_FadeDelete(obj);
	}
	function getAngleToPlayer(x, y)
	{
  		return atan2(GetPlayerY - y, GetPlayerX - x);
 	}	
	@Finalize
	{//読みこんだファイルを削除
		loop(16){CreateItem(ITEM_SCORE,GetX+rand(-50,50),GetY+rand(-50,50));}
	}
	
}