#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_devil.png";
        let imgBoss2 =csd~"img\dot_yousei3.png";
        let name    = "召喚「死霊小編隊」";
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
        let angle = 0;
	let Motion=0;
        let imgSPELL =csd~"img\SPELL_H.png";
        let imgAngle2 = 0;

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

        SetLife(5000);
        SetTimer(99);
        SetScore(1000000);
        SetDamageRate(0,0);

        SetGraphicRect(64,1,127,64);
        SetInvincibility(150);
        SetShotDirectionType(ABSOLUTE);

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

        @MainLoop
        {
	imgAngle2++;
	if(imgAngle2>360){imgAngle2=0;}
	if(count==150){
		Motion=1;
		Concentration01(60);
		}
	if(count>=200&&count<=350&&count%5==0){
		CreateEnemyFromScript("DOLL01",GetX,GetY,2,GetAngleToPlayer-180+angle,1);
		Motion=0;
        	angle=angle+20;
		}
	if(count==351){
        	angle=0;
        	SetShotDirectionType(PLAYER);
        		let i = 0;
        		while( i < 18 )
        		{
        		let shot01 = 1;
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,3,i*20,0,-0.01,2,ORANGE02);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,2,i*20,0,-0.01,1,ORANGE02);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,2,i*20+10,0,-0.01,1,ORANGE02);
        		FireShot(shot01);
        		i++;
			}
		}
	if(count>=400&&count<=550&&count%5==0){
		CreateEnemyFromScript("DOLL02",GetX,GetY,2,GetAngleToPlayer-180-angle,1);
		Motion=0;
        	SetDamageRate(100,50);
        	angle=angle+20;
		}
	if(count==600){
        	count=199;
        	angle=0;
        	SetShotDirectionType(PLAYER);
        		let i = 0;
        		while( i < 18 )
        		{
        		let shot01 = 1;
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,3,i*20,0,-0.01,2,ORANGE02);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,2,i*20,0,-0.01,1,ORANGE02);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX,GetY,0);
        		SetShotDataA(shot01,0,2,i*20+10,0,-0.01,1,ORANGE02);
        		FireShot(shot01);
        		i++;
			}
		}
	SetCollisionA(GetX(),GetY(),18);
        SetCollisionB(GetX(),GetY(),18);
        count++;
        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
	{
		//背景描画
		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(50)
	{
		angle=rand(0,360);
		CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(35,50),GetY+sin(angle)*rand(35,50));
	}
		CreateItem(ITEM_BOMB,GetX,GetY);
        } 
	
    	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;}
		}
}

script_enemy DOLL01 {
        let count=0;
        let angle = GetAngle;
        let r = 0;
	let Animation=0;
	let Animation2=0;
        let csd     = GetCurrentScriptDirectory;
        let imgBoss2 =csd~"img\dot_yousei3.png";
	let shotseA = csd~"se\ShotSE02.wav";
	let deathse = csd~"se\DEATH.wav";

    @Initialize {
        SetLife(50);
        SetDamageRateEx(100,0,50,0);
        SetInvincibility(51);
        TAnime1;
        TAnime2;
    }

    @MainLoop {
        if(count%50==0)
        	{
		r=r+50;
		SetMovePosition01(GetEnemyX+cos(angle)*r,GetEnemyY+sin(angle)*r,1);
        	angle=angle+2;
        	}
	if(count%150==0){
			Shot;
		}

        	if(GetX<0||GetX>448||GetY>480||GetY<0)
        	{
        		VanishEnemy();
        	}
	SetCollisionA(GetX(),GetY(),10);
        SetCollisionB(GetX(),GetY(),10);
        count++;
        yield;
    }

        @DrawLoop {
		SetTexture(imgBoss2);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(Animation*32,0,31+Animation*32,31)}
		else if(GetSpeedX()>0){SetGraphicRect(128+Animation2*32,33,159+Animation2*32,64);}
		else if(GetSpeedX()<0){SetGraphicRect(Animation2*32,33,31+Animation2*32,64);}
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
	if(!BeVanished){
		PlaySE(deathse);
		DeleteEnemyShotImmediatelyInCircle(SHOT,GetX,GetY,30);
		}
        }

    	task TAnime1{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
    	task TAnime2{
		loop{
			Animation2=0;
        		loop(10){yield;}
			Animation2=1;
        		loop(10){yield;}
			Animation2=2;
        		loop(10){yield;}
			Animation2=3;
        		loop(10){yield;}
			}
		}
    	task Shot{
		loop(5){shotFudaA;
			shotFudaB;
			shotFudaC;
			PlaySE(shotseA);
			yield;
			}
		}
    sub shotFudaA {
        	SetShotDirectionType(ABSOLUTE);
		CreateShotA(1,GetX,GetY,0);
		SetShotDataA(1,0,5,angle-270,0,-0.1,2,RED12);
		FireShot(1);
		yield;
	}
    sub shotFudaB {
        	SetShotDirectionType(ABSOLUTE);
		CreateShotA(1,GetX,GetY,0);
		SetShotDataA(1,0,5,angle-150,0,-0.1,2,RED12);
		FireShot(1);
		yield;
	}
    sub shotFudaC {
        	SetShotDirectionType(ABSOLUTE);
		CreateShotA(1,GetX,GetY,0);
		SetShotDataA(1,0,5,angle-30,0,-0.1,2,RED12);
		FireShot(1);
		yield;
	}
}

script_enemy DOLL02 {
        let count=0;
        let angle = GetAngle;
        let r = 0;
	let Animation=0;
	let Animation2=0;
        let csd     = GetCurrentScriptDirectory;
        let imgBoss2 =csd~"img\dot_yousei3.png";
	let shotseA = csd~"se\ShotSE02.wav";
	let deathse = csd~"se\DEATH.wav";

    @Initialize {
        SetLife(50);
        SetDamageRateEx(100,100,100,100);
        SetInvincibility(51);
        TAnime1;
        TAnime2;
    }

    @MainLoop {
        if(count%50==0)
        	{
		r=r+50;
		SetMovePosition01(GetEnemyX+cos(angle)*r,GetEnemyY+sin(angle)*r,1);
        	angle=angle+2;
        	}
	if(count%150==0){
			Shot;
		}

        	if(GetX<0||GetX>448||GetY>480||GetY<0)
        	{
        		VanishEnemy();
        	}
	SetCollisionA(GetX(),GetY(),10);
        SetCollisionB(GetX(),GetY(),10);
        count++;
        yield;
    }

        @DrawLoop {
		SetTexture(imgBoss2);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(Animation*32,0,31+Animation*32,31)}
		else if(GetSpeedX()>0){SetGraphicRect(128+Animation2*32,33,159+Animation2*32,64);}
		else if(GetSpeedX()<0){SetGraphicRect(Animation2*32,33,31+Animation2*32,64);}
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
	if(!BeVanished){
		PlaySE(deathse);
		DeleteEnemyShotImmediatelyInCircle(SHOT,GetX,GetY,30);
		}
        }

    	task TAnime1{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
    	task TAnime2{
		loop{
			Animation2=0;
        		loop(10){yield;}
			Animation2=1;
        		loop(10){yield;}
			Animation2=2;
        		loop(10){yield;}
			Animation2=3;
        		loop(10){yield;}
			}
		}
    	task Shot{
		loop(5){shotFudaA;
			shotFudaB;
			shotFudaC;
			PlaySE(shotseA);
			yield;
			}
		}
    sub shotFudaA {
        	SetShotDirectionType(ABSOLUTE);
		CreateShotA(1,GetX,GetY,0);
		SetShotDataA(1,0,5,angle+270,0,-0.1,2,BLUE12);
		FireShot(1);
		yield;
	}
    sub shotFudaB {
        	SetShotDirectionType(ABSOLUTE);
		CreateShotA(1,GetX,GetY,0);
		SetShotDataA(1,0,5,angle+150,0,-0.1,2,BLUE12);
		FireShot(1);
		yield;
	}
    sub shotFudaC {
        	SetShotDirectionType(ABSOLUTE);
		CreateShotA(1,GetX,GetY,0);
		SetShotDataA(1,0,5,angle+30,0,-0.1,2,BLUE12);
		FireShot(1);
		yield;
	}
}