#Title[枯死「散り行く死桜」]
#Text[西行寺幽々子のスペルカード]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name="枯死「散り行く死桜」";
        let csd=GetCurrentScriptDirectory;
        let imgBoss =csd~"img\dot_yuyuko.png";
        let imgEnemy=csd~"img\familiar3.png";
        let angle=0;
	let Xcount=GetX;
	let Ycount=0;
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let Flag=false;
	let shotseA=csd~"se\ShotSE02.wav";
	let imgAngle=0;
	let imgALP1=255;
	let imgALP2=0;

    @Initialize {
        CutIn(YOUMU,name,0,0,0,0,0);
        SetLife(900);
        SetTimer(75);
        SetScore(3000000);
        SetDamageRate(20,0);
        SetInvincibility(200);
        SetMovePosition02(GetCenterX(),150,50);
	LoadGraphic(imgBoss);
	LoadGraphic(imgEnemy);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
        TAnime1;
	}

        @MainLoop
        {
	imgAngle+=0.5;
	if(imgAngle>=360){imgAngle=0;}

        if(!OnBomb){
        SetCollisionB(GetX(),GetY(),22);
	SetCollisionA(GetX(),GetY(),22);
        imgALP2=255;
        imgALP1=100;
	SetDamageRate(20,0);
        SetEnemyMarker(true);}
        else {
        imgALP2=0;
        imgALP1=255;
	SetDamageRate(0,0);
	SetEnemyMarker(false);}

	if(count==150){
		Concentration01(60);
		}
	if(count>=200&&count%2==0){
		PlaySE(shotseA);
		Ycount=GetY+rand(-20,20);
		FiraShot(270,Xcount,Ycount);
		FiraShot(90,Xcount,Ycount);
		}
	if(count>=200&&Flag==false){
		Xcount-=5;
		if(Xcount<GetClipMinX){Flag=true;}
		}
	if(count>=200&&Flag==true){
		Xcount+=5;
		if(Xcount>GetClipMaxX){Flag=false;}
		}
	if(count>=200&&count%200==150){
        	SetShotDirectionType(PLAYER);
        	CreateShotA(1,GetX,GetY,50);
        	SetShotDataA(1,0,2.5,0,0,0,0,37);
        	FireShot(1);
        	CreateShotA(1,GetX,GetY,50);
        	SetShotDataA(1,0,2,0,0,0,0,37);
        	FireShot(1);
        	CreateShotA(1,GetX,GetY,50);
        	SetShotDataA(1,0,1.5,0,0,0,0,37);
        	FireShot(1);
        	CreateShotA(1,GetX,GetY,50);
        	SetShotDataA(1,0,1,0,0,0,0,37);
        	FireShot(1);
        	CreateShotA(1,GetX,GetY,50);
        	SetShotDataA(1,0,0.5,0,0,0,0,37);
        	FireShot(1);
		}
	if(count>=200&&count%200==50){
		TAnime2;
		SetMovePositionRandom01(rand(50,60),rand(20,40),1,GetClipMinX()+150,100,GetClipMaxX()-150,175);
		}
        count++;
        yield;

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

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgEnemy);
		SetGraphicRect(0,0,192,192);
		SetAlpha(imgALP1);
		SetColor(255,255,255);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,imgAngle);
		DrawGraphic(GetX(),GetY());

		SetTexture(imgBoss);
		SetAlpha(255);
		SetColor(imgALP2,imgALP2,imgALP2);
		SetGraphicAngle(0,0,0);
		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());
		}

    	task TAnime1{
			AnimationB=0;
			AnimationC=3;
        		loop(16){yield;}
			AnimationB=1;
        		loop(46){yield;}
			AnimationB=0;
        		loop(8){yield;}
		loop(2){
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			}
			AnimationB=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=0;
			AnimationC=5;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(130){yield;}
		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(50){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}

task FiraShot(Angle,x,y){
	let obj=Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj,x,y);
	Obj_SetSpeed(obj,rand(1,4));
	Obj_SetAngle(obj,Angle);
	ObjShot_SetGraphic(obj,67);
    
	while(!Obj_BeDeleted(obj)){
		if(Obj_GetY(obj)<GetClipMinY){
			ObjShot_SetGraphic(obj,67);
			Obj_SetAngle(obj,rand(80,100));
			Obj_SetSpeed(obj,1.5);
			break;
			}
		yield;
		}
	}
}