#Title[お燐通常２]
#Text[火焔猫燐の通常]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\ExOrin.png";
        let angle=0;
	let l=0;
	let shotseA=csd~"se\ShotSE02.wav";
	let shotseB=csd~"se\ShotSE04.wav";

    @Initialize {
        SetLife(2000);
        SetTimer(50);
        SetDamageRate(100,100);
	SetEnemyMarker(true);

        SetInvincibility(200);
	LoadGraphic(imgBoss);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
    }

        @MainLoop
        {
	if(count==150){
		Concentration01(50);
		}
	if(count>=200&&count<=230)
		{
		PlaySE(shotseA);
        	SetShotDirectionType(ABSOLUTE);
		let i=0;
		while(i<12){
        		let shot01 = 1;
        		CreateShotA(shot01,GetX+cos(i*45+angle)*(30+l*5),GetY+sin(i*45+angle)*(30+l*5),15);
        		SetShotDataA(shot01,0,0,i*45+angle+175,0,0,0,117);
        		SetShotDataA(shot01,250-count,0,NULL,0,0.01,1.5,117);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX+cos(i*45+angle)*(30+l*5),GetY+sin(i*45+angle)*(30+l*5),15);
        		SetShotDataA(shot01,0,0,i*45+angle,0,0,0,111);
        		SetShotDataA(shot01,250-count,0,NULL,0,0.01,1.5,111);
        		FireShot(shot01);
			i++;
			}
		angle=rand(0,360);
		l++;
		}
	if(count==300){
		PlaySE(shotseB);
        	SetShotDirectionType(PLAYER);
		let i=0;
		while(i<10){
        		let shot01 = 1;
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,2,i*36,0,-0.02,0.5,37);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,3,i*36,0,-0.02,1.5,37);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,4,i*36,0,-0.02,2.5,37);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,5,i*36,0,-0.02,3.5,37);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,6,i*36,0,-0.02,4.5,37);
        		FireShot(shot01);
			i++;
			}
		move;
		l=0;
		count=170;
		}
        SetCollisionB(GetX(),GetY(),18);
	SetCollisionA(GetX(),GetY(),18);
        count++;
        yield;
        }

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		SetGraphicAngle(0,0,0);
		if(GetSpeedX()==0){SetGraphicRect(128,0,255,127);}
		else if(GetSpeedX()>0){SetGraphicRect(384,0,511,127);}
		else if(GetSpeedX()<0){SetGraphicRect(256,0,383,127);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
		DeleteGraphic(imgBoss);
        }

task move{
	let wMove = 30;
	moveToPlayer(rand(80,120),rand(-40,40),wMove,GetClipMinX+48,GetClipMinY+32,GetClipMaxX-48,GetClipMinY+128);
	wait(wMove);
	}

function moveToPlayer(xMove,yAdd,frame,left,top,right,bottom){
	let x;
	let y;

	if(GetPlayerX<GetX){//プレイヤーより右に敵がいれば、敵は左に動きます。
		x=GetX-xMove;

		//但し、敵が可動領域の左端よりも左にいくようなら、右に動きます。
			if(x<left){
				x=GetX+xMove;
 			}
		} else {
		//さもなくば、敵は右に動きます。
		x=GetX+xMove;

		// 但し、敵が可動領域の右端よりも右にいくようなら、左に動きます。
		if(right<x){
			x=GetX-xMove;
			}
		}
	y=GetY+yAdd;
	if(y<top) {
		y=top;
	} else if(bottom<y){
		y=bottom;
		}
	SetMovePosition02(x,y,frame);
	}
function wait(w) {
	loop(w){yield;}
	}
}