#Title[こいし通常１]
#Text[古明地こいしの通常]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\ExKoishi.png";
        let angleB=0;
	let shotseA=csd~"se\ShotSE02.wav";

    @Initialize {
        SetLife(1750);
        SetTimer(30);
        SetDamageRate(100,100);

	SetX(498);
	SetY(-50);
	LoadGraphic(imgBoss);
	SetEnemyMarker(true);
	SetMovePosition02(GetCenterX,150,75);
        SetInvincibility(100);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
	}

        @MainLoop
        {
	if(count>=100&&count%300==100){
                ShotA;
		}
	if(count>=100&&count%300==250){
                ShotB;
		}
	if(count>=300&&count%150==0){
		SetMovePositionRandom01(rand(20,40),rand(20,40),3,GetClipMinX()+150,150,GetClipMaxX()-150,200);
		}
        	SetCollisionA(GetX(),GetY(),18);
        	SetCollisionB(GetX(),GetY(),18);
        	count++;
        yield;

}
    @Finalize {
		if(!BeVanished){
			loop(10){
				CreateItem(ITEM_SCORE,GetX+rand(-30,30),GetY+rand(-30,30));
			}
		}
		DeleteGraphic(imgBoss);
    }

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		SetGraphicAngle(0,0,0);
		SetRenderState(ALPHA);
		SetAlpha(255);
		if(int(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());
	}

    	task ShotA{
		loop(20){
                	SetShotDirectionType(ABSOLUTE);
			PlaySE(shotseA);
        		let i=0;
        		while(i<6){
        			CreateShotA(1,GetX+cos(angleB-45)*75,GetY+sin(angleB-45)*75,5);
        			SetShotDataA(1,0,3,60*i+angleB+30,0,-0.02,1,44);
        			FireShot(1);
        			i++;
				}
        		loop(5){yield;}
                	angleB=angleB+18;
			}
		}

    	task ShotB{
		loop(20){
                	SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseA);
        	let i=0;
        	while(i<6){
        		CreateShotA(1,GetX+cos(angleB-135)*75,GetY+sin(angleB-135)*75,5);
        		SetShotDataA(1,0,3,60*i+angleB,0,-0.02,1,42);
        		FireShot(1);
        		i++;
			}
        		loop(5){yield;}
                	angleB=angleB-18;
			}
		}
}
