#Title[災害「風下バイオハザード」]
#Text[メディスン・メランコリーのスペルカード]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\dot_medicine.png";
        let name="災害「風下バイオハザード」";
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let LockonX=0;
	let LockonY=0;
        let angle=0;
	let shotseA=csd~"se\ShotSE02.wav";

	@Initialize {
	CutIn(YOUMU,name,0,0,0,0,0);
	SetMovePosition02(cx,cy,60);
	SetLife(600);
	SetTimer(55);
	SetScore(1750000);
	SetDamageRate(30,20);
	SetInvincibility(200);
	LoadGraphic(imgBoss);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
	TAnime1;
	}

        @MainLoop
        {
        if(count==200){
		PlaySE(shotseA);
		LockonX=(GetPlayerX-GetX);
		LockonY=(GetPlayerY-GetY);
		SetMovePosition01(GetX+LockonX*50,GetY+LockonY*50,4);
		TAnime2;
		}
	if(GetX>448){
		SetX(0);
		SetMovePosition01(GetX+LockonX*50,GetY+LockonY*50,5);
		}
	if(GetX<0)
        	{
		SetX(448);
		SetMovePosition01(GetX+LockonX*50,GetY+LockonY*50,5);
		}
	if(GetY>480)
        	{
		SetY(0);
		SetMovePosition01(GetX+LockonX*50,GetY+LockonY*50,5);
		}
	if(GetY<0)
        	{
		SetY(480);
		SetMovePosition01(GetX+LockonX*50,GetY+LockonY*50,5);
		}
        if(count==300){
		SetMovePosition01(GetX,GetY,1);
        	SetShotDirectionType(ABSOLUTE);
		let i=0;
		while(i<150){
        		let shot01=1;
        		CreateShotA(shot01,rand(0,448),rand(0,480),50);
        		SetShotDataA(shot01,0,rand(0.2,0.4),atan2(LockonY,LockonX),0,0,0,227);
			let j=249;
			while(j<250){
				let id2=2;
				CreateShotA(id2,0,0,20);
				SetShotDataA(id2,0,0,0,0,0,0,227);
				SetShotKillTime(id2,0);
				AddShot(j,shot01,id2,0);
				j++;
				}
			SetShotKillTime(shot01,250);
        		FireShot(shot01);
			i++;
			}
		DeleteEnemyShotInCircle(SHOT,GetPlayerX,GetPlayerY,40);
		}
        if(count>=200&&count<300&&count%5==0){
        	SetShotDirectionType(PLAYER);
		PlaySE(shotseA);
		let i=0;
		while(i<5){
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,1,i*72,0,0.1,2,27);
			FireShot(shotA);
			i++;
			}
		}
        if(count>=200&&count<300){
        	SetShotDirectionType(PLAYER);
		let shotA=0;
		CreateShotA(shotA,GetX,GetY,5);
		SetShotDataA(shotA,0,rand(0.1,0.5),rand(0,360),0,0,0,61);
		FireShot(shotA);
		}
        if(count>=400){
		count=100;
		}
	SetCollisionA(GetX(),GetY(),18);
	SetCollisionB(GetX(),GetY(),18);
        count++;
        yield;
        }

       @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(128*AnimationC,128*AnimationB,127+128*AnimationC,127+128*AnimationB);}
		else if(GetSpeedX()>0){SetGraphicRect(256,256+128*AnimationA,383,383+128*AnimationA);}
		else if(GetSpeedX()<0){SetGraphicRect(256,128*AnimationA,383,127+128*AnimationA);}
		DrawGraphic(GetX(),GetY());
	}

	@Finalize {
		if(!IsTimeOut){
			loop(50){
				angle=rand(0,360);
				CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(35,45),GetY+sin(angle)*rand(35,45));
			}
		}
		DeleteGraphic(imgBoss);
	}

    	task TAnime1{
		loop{
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			}
		}

    	task TAnime2{
			AnimationA=0;
        		loop(10){yield;}
			AnimationA=1;
        		loop(80){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}
}