#Title[呪術「ゾンビメサイア」]
#Text[火焔猫燐のスペルカード]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name="呪術「ゾンビメサイア」";
        let csd=GetCurrentScriptDirectory;
        let imgBoss =csd~"img\ExOrin.png";
        let imgBoss2=csd~"img\dot_yousei3.png";
        let imgBoss3=csd~"img\familiar.png";
	let angle=0;
	let r=0;
	let l=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let shotseA=csd~"se\ShotSE02.wav";

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

        SetLife(800);
        SetTimer(60);
        SetScore(3000000);
        SetDamageRate(20,20);

        SetInvincibility(100);
	LoadGraphic(imgBoss);
	LoadGraphic(imgBoss2);
	LoadGraphic(imgBoss3);
        SetMovePosition02(cx,cy,60);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
    }

        @MainLoop
        {
	if(count==150){
		r=GetCommonDataDefault("zako",10);
		if(r>19){l=1}
		if(r>9&&r<=19){l=2}
		if(r<=9){l=3}
		let i=0;
		while(i<r){
			CreateEnemyFromScript("DOLLA",GetX+cos(360/r*i+90)*100,GetY+sin(360/r*i+90)*100,0,0,0);
			i++;
			}
		}
	if(count>=250&&count%5==0){
		PlaySE(shotseA);
        		let i = 0;
        		while(i<l)
        		{
        		let shot01 = 1;
        		SetShotDirectionType(ABSOLUTE);
        		CreateShotA(shot01,GetX(),GetY(),5);
        		SetShotDataA(shot01, 0,2,360/l*i+angle+rand(-10,10),0,-0.01,0.5,45);
        		FireShot(shot01);
        		i++
        		}
		angle=angle+11;
		}
	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
        {
		if(!IsTimeOut){
			loop(50){
				angle=rand(0,360);
				CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(35,45),GetY+sin(angle)*rand(35,45));
			}
		}
		DeleteGraphic(imgBoss);
		DeleteGraphic(imgBoss2);
		DeleteGraphic(imgBoss3);
        }
}

script_enemy DOLLA{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei3.png";
        let imgBoss3=csd~"img\familiar.png";
	let imgAngle=0;
	let imgAlpha=0;
	let imgAlpha2=0;

	@Initialize {
	SetLife(1);
	SetScore(0);
	SetDamageRate(0,0);
	SetX(GetX);
	SetY(GetY);
	CreateEnemyFromScript("DOLLB",GetX,GetY,0,0,0);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
	}

	@MainLoop {
	if(count<=50){
		imgAngle+=6;
		imgAlpha+=5;
		imgAlpha2+=5;
		if(imgAngle>=360){imgAngle=0;}
		}
	if(count==101){
		CreateEnemyFromScript("DOLL2",GetX,GetY,0,0,0);
		}
	if(count>50&&count<=101){
		imgAngle+=6;
		imgAlpha-=5;
		if(imgAngle>=360){imgAngle=0;}
		}
	if(count>101&&count<=152){
		imgAlpha2-=5;
		}
        if(count>=153)
        	{
        	VanishEnemy();
        	}
	count++;
	}

        @DrawLoop {
		SetTexture(imgBoss3);
		SetGraphicAngle(0,0,imgAngle);
		SetAlpha(imgAlpha);
		SetGraphicRect(0,0,48,48);
		DrawGraphic(GetX(),GetY());
		SetGraphicAngle(0,0,-imgAngle);
		SetGraphicRect(0,0,48,48);
		DrawGraphic(GetX(),GetY());
		SetTexture(imgBoss2);
		SetGraphicAngle(0,0,0);
		SetAlpha(imgAlpha2);
		SetGraphicRect(261,0,282,31);
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
        }
}

script_enemy DOLLB{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei3.png";
	let imgAngle2=0;
	let imgAlpha2=0;
	let deathse=csd~"se\Hitugi.wav";

	@Initialize {
	SetLife(1);
	SetScore(0);
	SetDamageRateEx(0,0,0,0);
	SetX(GetX);
	SetY(GetY);
	}

	@MainLoop {
	if(count<=50){
		imgAlpha2+=5;
		}
	if(count==102){
		SetMovePositionHermite(GetX-40,GetY-30,60,225,10,90,51);
		PlaySE(deathse);
		}
	if(count>101&&count<=152){
		imgAngle2+=4;
		if(imgAngle2>=90){imgAngle2=90;}
		imgAlpha2-=5;
		}
        if(count>=153)
        	{
        	VanishEnemy();
        	}
	count++;
	}

        @DrawLoop {
		SetTexture(imgBoss2);
		SetGraphicAngle(imgAngle2,imgAngle2,0);
		SetAlpha(imgAlpha2);
		SetGraphicRect(229,0,250,31);
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
        }
}

script_enemy DOLL2{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei3.png";
	let deathse=csd~"se\DEATH.wav";
	let shotseA=csd~"se\ShotSE02.wav";

    @Initialize {
        SetLife(30);
        SetScore(0);
        SetDamageRateEx(100,2,150,1);
        SetX(GetX);
        SetY(GetY);
        SetInvincibility(50);
        TAnime;
	}

	@MainLoop {
	if(count<=50&&count%2==0){
        	SetShotDirectionType(ABSOLUTE);
		let shotA=0;
		CreateShotA(shotA,GetX+rand(-5,5),GetY+rand(-5,5),20);
		SetShotDataA(shotA,0,0,0,0,0,0,67);
		SetShotKillTime(shotA,0);
		FireShot(shotA);
		}
        if(count>=120&&count%10==0){
        	SetMovePosition01(GetPlayerX,GetPlayerY,1.2);
        	}
	if(count>=150&&count%100==0)
        	{
                SetShotDirectionType(PLAYER);
		PlaySE(shotseA);
		let shot01=1;
        	CreateShotA(shot01,GetX,GetY,10);
        	SetShotDataA(shot01,0,2,0,0,-0.01,1,51);
        	FireShot(shot01);
        	}
	SetCollisionA(GetX(),GetY(),10);
	SetCollisionB(GetX(),GetY(),10);
	count++;
	yield;
	}

        @DrawLoop {
		SetTexture(imgBoss2);
		SetGraphicAngle(0,0,0);
		SetAlpha(255);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(Animation*32,0,31+Animation*32,31);}
		else if(GetSpeedX()>0){SetGraphicRect(Animation*32+128,32,159+Animation*32,63);}
		else if(GetSpeedX()<0){SetGraphicRect(Animation*32,32,31+Animation*32,63);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
        	if(GetEnemyLife>0){
		PlaySE(deathse);
		CreateEnemyFromScript("DOLL11",GetX,GetY,0,0,1);
        	}
        } 

    	task TAnime{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
}

script_enemy DOLL11 {//死亡
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss3=csd~"img\dot_yousei3.png";

    @Initialize {
        SetLife(100);
        SetScore(0);
        TAnime;
    }

    @MainLoop{
        	if(count==1)
        	{
        		let i = 0;
        		while(i<10)
        		{
        		let shot01=1;
        		CreateShotA(shot01,GetX(),GetY(), 0);
        		SetShotDataA(shot01,0,rand(1.5,3),rand(0,360),0,-0.02,1.5,1);
        		FireShot(shot01);
        		i++;
        		}
        	}
        	if(count==250)
        	{
		VanishEnemy();
        	}
        count++;
        yield;
	}

        @DrawLoop {
		SetTexture(imgBoss3);
		SetGraphicRect(Animation*32+96,0,127+Animation*32,31);
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize {
        	if(GetEnemyLife>0){
        		CreateEnemyFromScript("DOLL2",GetX,GetY,0,0,1);
        	}
        }
    	task TAnime{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
}