#e
#Title[╗uR[hEBhv]
#Text[B]
#ScriptVersion[2]

script_enemy_main
{
	let count=-60;
	let lv = GetCommonDataDefault("lv",2);
	let bg=0;
	let cx=GetCenterX();//STGV[̒SxW擾
	let cy=GetCenterY();//STGV[̒SxW擾
	let name        = "╗uR[hEBhv";
	#include_function ".\lib\lib_anime_Remilia.txt"
	let cirno=0;
	let player=0;
	let vx=1;
	let imageBoss = ".\script\wx\img\dot_cirno.png";
	if (lv>2) {name = "╗uR[huU[hv";}
	@Initialize{
		CutIn(KOUMA, name, "", 0, 0, 0, 0);
		LoadGraphic(imageBoss);
		InitializeAction();
		SetLife(3000);
		SetTimer(50);
		SetDamageRate(100,100);
       		SetScore(5000000);
		SetMovePosition02(cx,100,60);
		SetAction(ACT_SPELL,60);
		PlaySE(".\script\wx\sound\enemy_powereffect.wav");
		Concentration02(60);
		LoadGraphic("script\wx\img\bg.png");
	}
	
	@MainLoop
	{
		Player;
		Cirno;
		if(0 < GetHitCount)
		{
			PlaySE(".\script\wx\sound\enemy_damage.wav");
		}
		if (GetTimer>0 && GetTimer<12 && count%60==0)
		{
			PlaySE(".\script\wx\sound\clock.wav");
		}
		count++;
		if (count>0) {
		if (count==120)
		{
			StopSE(".\script\wx\sound\enemy_powereffect.wav");
			PlaySE(".\script\wx\sound\enemy_vanish.wav");
			let x=0;
			let y=0;
			loop(9)
			{
				y=0;
				loop(9)
				{
					IceShot(x,y);
					y+=cy/4.5;
				}
				x+=cx/4.5;
			}
		}
		if (count>120)
		{
			if ((count%30==15 && lv>2) || (count%30==0 && lv>1) || (count%60==0 && lv==1))
			{
				PlaySE(".\script\wx\sound\shot2.wav");
				loop(2)
				{
					if (lv<3)
					{
						CreateShot12(cx*2,rand(0,cy*2),0,2,vx,-rand(1,5)/100,rand(vx*10,vx*20)/5,0,WHITE22,60);
						CreateShot12(0,rand(0,cy*2),0,2,vx,-rand(1,5)/100,rand(vx*10,vx*20)/5,0,WHITE22,60);
					} else {
						CreateShot12(cx*2,rand(0,cy*2),0,2,vx,-rand(1,5)/100,rand(vx*10,vx*20)/3.5,0,WHITE22,60);
						CreateShot12(0,rand(0,cy*2),0,2,vx,-rand(1,5)/100,rand(vx*10,vx*20)/3.5,0,WHITE22,60);
					}
				}
			}
			if ((count%45==22 && lv>3) || (count%90==45 && lv>2) || (count%90==0 && lv>1) || (count%180==0 && lv==1))
			{
				PlaySE(".\script\wx\sound\shot1.wav");
				let angle=getAngleToPlayer(GetX,GetY)-90;
				loop(5){CreateShot01(GetX+cos(angle)*30,GetY+sin(angle)*30,3,angle,BLUE11,60);angle+=45;}
			}
			if ((count%300==0 && lv>1) || (count%300==150 && lv>2) || (count%600==0 && lv==1))
			{
				PlaySE(".\script\wx\sound\enemy_vanish.wav");
				vx=-vx;
			}
			if (count%600==300)
			{
				SetMovePosition02(cx*2-GetPlayerX,cy*2-GetPlayerY,180);
				SetAction(ACT_MOVE,180);
			}
			if (count%600==0)
			{
				SetMovePosition02(GetPlayerX,GetPlayerY,180);
				SetAction(ACT_MOVE,180);
			}
		}
		SetCollisionA(GetX(),GetY(),24);//蔻(e)o^
		SetCollisionB(GetX(),GetY(),12);//蔻(̓)o^
		}
		yield;
	}
	@DrawLoop{DrawBoss( imageBoss);}
	@BackGround{SetTexture("script\wx\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);
		ObjShot_SetBombResist(cirno,true);
		Obj_SetCollisionToPlayer(cirno,false);
		Obj_SetAlpha(cirno,0);
		yield;
		Obj_Delete(cirno);
	}
	task Player
	{
		player = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(player,GetPlayerX,GetPlayerY);
		ObjShot_SetGraphic(player,RED02);
		Obj_SetAlpha(player,0);
		ObjShot_SetBombResist(player,true);
		Obj_SetCollisionToPlayer(player,false);
		yield;
		Obj_Delete(player);
	}
	task IceShot(let x,let y)
	{
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,0);
		Obj_SetAlpha(obj,0);
		Obj_SetSpeed(obj,0);
		ObjShot_SetGraphic(obj,AQUA03);
		ObjShot_SetBombResist(obj,true);
		Obj_SetCollisionToPlayer(obj,false);
		let alpha=0;
		while(!Obj_BeDeleted(obj))
		{
			if (Collision_Obj_Obj(obj,player))
			{
				alpha-=12.8;
			}
			if (Collision_Obj_Obj(obj,cirno))
			{
				alpha+=2;
			}
			alpha+=0.5;
			if (alpha<1) {alpha=2;}
			if (alpha>255) {alpha=255;}
			if (alpha>127) {Obj_SetCollisionToPlayer(obj,true);} else {Obj_SetCollisionToPlayer(obj,false);}
			Obj_SetAlpha(obj,alpha);
			yield;
		}
	}
	function getAngleToPlayer(x, y)
	{
  		return atan2(GetPlayerY - y, GetPlayerX - x);
 	}	
	@Finalize
	{//ǂ݂񂾃t@C폜
		loop(16){CreateItem(ITEM_SCORE,GetX+rand(-50,50),GetY+rand(-50,50));}
	}
	
}