#Title[uJSmgv]
#Text[̃XyJ[h]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
        let count=0;
        let count2=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd     = GetCurrentScriptDirectory;
        let imgBoss =csd~"img\dot_devil.png";
        let name    = "uJSmgv";
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
        let angle = 0;
        let bngle = 0;
	let Motion=0;
	let j=0;
        let imgSPELL =csd~"img\SPELL_H.png";
        let imgAngle2 = 0;
	let shotseA = csd~"se\ShotSE02.wav";

    @Initialize {
    CutIn(YOUMU, name, 0, 0, 0, 0, 0);

        SetLife(3000);
        SetTimer(50);
        SetScore(1000000);
        SetDamageRate(0,0);

        SetInvincibility(0);
        SetShotDirectionType(ABSOLUTE);

        SetInvincibility(0);
        SetMovePosition02(cx,150,60);
	LoadGraphic(imgBoss);
	LoadGraphic(imgSPELL);
        TAnime1;
    }

        @MainLoop
        {
	imgAngle2++;
	if(imgAngle2>360){imgAngle2=0;}
	if(count==150){
		Motion=1;
		Concentration01(60);
		}
	if(count==200){
		count2=0;
		Motion=0;
		j=0;
		angle=GetAngleToPlayer;
        	SetDamageRate(100,50);
		}
	if(count>=200&&count<300&&count%2==0){
		PlaySE(shotseA);
		let i=0;
		while(i<18)
		{
        	FiraShot(angle+i*20);
		i++;
		}
		}
	if(count==305){
		TAnime2;
		SetMovePositionRandom01(rand(5,150),rand(10,40),2,GetClipMinX()+100,100,GetClipMaxX()-100,175);
		}
	if(count>=305&&count%5==0){
		PlaySE(shotseA);
		let i=0;
		while(i<9)
		{
        	let shot01 = 1;
        	CreateShotA(shot01,GetX+cos(i*40+bngle)*(60-j),GetY+sin(i*40+bngle)*(60-j),10);
        	SetShotDataA(shot01,0,3,i*40+bngle,0,-0.05,rand(0.1,1.5),PURPLE04);
        	FireShot(shot01);
		i++;
		}
		bngle=rand(0,360);
		j=j+2;
		}
	if(count>=400){
		count=199;
		}
	SetCollisionA(GetX(),GetY(),18);
        SetCollisionB(GetX(),GetY(),18);
        count++;
        count2++;
        yield;
        }

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		SetGraphicAngle(0,0,0);
	if(Motion==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());
		}
	if(Motion==1){
		if(int(GetSpeedX())==0)
		{SetGraphicRect(0,128*AnimationB,127,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());
		}
	}

	@BackGround
	{
		//wi`
		SetGraphicRect(0,0,81,81);
		SetTexture(imgSPELL);
		SetRenderState(ALPHA);
		SetGraphicScale(12,12);
		SetColor(0,0,100);
		SetAlpha(255);
		SetGraphicAngle(0,0,-imgAngle2*4);
		DrawGraphic(cx,cy);

		SetGraphicScale(7,7);
		SetColor(155,0,155);
		SetAlpha(155);
		SetGraphicAngle(0,0,imgAngle2*3);
		DrawGraphic(cx,cy);

		SetGraphicScale(4,4);
		SetColor(55,55,55);
		SetAlpha(155);
		SetGraphicAngle(0,0,-imgAngle2*2);
		DrawGraphic(cx,cy);

		SetGraphicScale(2,2);
		SetColor(0,0,155);
		SetAlpha(155);
		SetGraphicAngle(0,0,imgAngle2);
		DrawGraphic(cx,cy);
	}
        
        @Finalize
        {
	loop(30)
	{
		angle=rand(0,360);
		CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(35,50),GetY+sin(angle)*rand(35,50));
	}
        } 
	
    	task TAnime1{
			AnimationB=0;
			AnimationC=3;
        		loop(16){yield;}
			AnimationB=1;
        		loop(56){yield;}
			AnimationB=0;
        		loop(8){yield;}
		loop{
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			AnimationB=3;
        		loop(10){yield;}
			}
		}

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

    	task FiraShot(Angle){
    let obj = Obj_Create(OBJ_SHOT);
	let shotseB = csd~"se\ShotSE01.wav";

    Obj_SetPosition(obj,GetX,GetY);
    Obj_SetSpeed(obj,4);
    Obj_SetAngle(obj,Angle);
    ObjShot_SetGraphic(obj,BLUE31);
    ObjShot_SetDelay(obj,10);

    loop(10){ yield; }
    
    while(!Obj_BeDeleted(obj)) {
        //[
        if(Obj_GetX(obj)<GetClipMinX){
	PlaySE(shotseB);
            Obj_SetX(obj,GetClipMinX*2-Obj_GetX(obj));
            ObjShot_SetGraphic(obj,RED31);
            Obj_SetAngle(obj,0);
            count2--;
        }
        //E[
        if(Obj_GetX(obj)>GetClipMaxX){
	PlaySE(shotseB);
            Obj_SetX(obj,GetClipMaxX*2-Obj_GetX(obj));
            ObjShot_SetGraphic(obj,RED31);
            Obj_SetAngle(obj,180);
            count2--;
        }
        //[
        if(Obj_GetY(obj)<GetClipMinY){
	PlaySE(shotseB);
            Obj_SetY(obj,GetClipMinY*2-Obj_GetY(obj));
            ObjShot_SetGraphic(obj,RED31);
            Obj_SetAngle(obj,90);
            count2--;
        }
        //[
        if(Obj_GetY(obj)>GetClipMaxY){
	PlaySE(shotseB);
            Obj_SetY(obj,GetClipMaxY*2-Obj_GetY(obj));
            ObjShot_SetGraphic(obj,RED31);
            Obj_SetAngle(obj,270);
            count2--;
        }
        if(count2<=-500){ break; }
        yield;
    }
}
}