#Title[禁忌「パンドラの箱」]
#Text[小悪魔のスペルカード]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let rcx=0;
        let rcy=0;
        let csd     = GetCurrentScriptDirectory;
        let imgBoss =csd~"img\dot_devil.png";
        let imgBoss2 =csd~"img\dot_yousei3.png";
	let imgEnemy=csd~"img\familiar.png";
        let name    = "禁忌「パンドラの箱」";
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
        let angle = 0;
        let angleA = 0;
        let angleB = 0;
	let Motion=0;
	let Flag=false;
        let imgSPELL =csd~"img\SPELL_H.png";
        let imgAngle2 = 0;
	let shotseA = csd~"se\ShotSE05.wav";
	let shotseB = csd~"se\BOM.wav";

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

        SetLife(7500);
        SetTimer(120);
        SetScore(1000000);
        SetDamageRate(0,0);

        SetInvincibility(0);
	SetEffectForZeroLife(60,0,1);
        SetMovePosition02(cx,120,60);
	LoadGraphic(imgBoss);
	LoadGraphic(imgBoss2);
	LoadGraphic(imgEnemy);
	LoadGraphic(imgSPELL);
        TAnime1;
    }

        @MainLoop
        {
	imgAngle2++;
	if(imgAngle2>360){imgAngle2=0;}
	if(count==150){
		Motion=1;
		Concentration01(60);
		}
	if(count==200){
        SetDamageRate(100,0);
		Motion=0;
		CreateEnemyFromScript("DOLL01",rand(GetX-100,GetX+100),rand(GetY-100,GetY+100),0,0,1);
		rcx=GetX;
		rcy=GetY;
		}
	if(count>=250&&count%150==0){
        	TAnime2;
		PlaySE(shotseA);
		SetMovePositionRandom01(rand(5,150),rand(10,40),2,GetClipMinX()+100,100,GetClipMaxX()-100,175);
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),0);
			SetShotDataA(shotA,0,1,0,0,0.01,5,BLUE03);
			let j=5;
			while(j<360)
			{
			angleA=rand(-15,15);
			angleB=rand(-15,15);
        		SetShotDirectionType(ABSOLUTE);
			let ta=1;
			CreateShotA(ta,angleA,angleB,10);
			SetShotDataA(ta,0,rand(0.5,1.5),rand(0,360),0,0,0,BLUE31);
			SetShotKillTime(ta,50);
			AddShot(j,shotA,ta,0);
			j++;
			}
			FireShot(shotA);
		}
	if(count>=250&&count%150==75&&GetEnemyLife<3000){
        	TAnime2;
		PlaySE(shotseA);
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),0);
			SetShotDataA(shotA,0,1,0,0,0.01,5,BLUE03);
			let j=5;
			while(j<360)
			{
			angleA=rand(-15,15);
			angleB=rand(-15,15);
        		SetShotDirectionType(ABSOLUTE);
			let ta=1;
			CreateShotA(ta,angleA,angleB,10);
			SetShotDataA(ta,0,rand(0.5,1.5),rand(0,360),0,0,0,BLUE31);
			SetShotKillTime(ta,50);
			AddShot(j,shotA,ta,0);
			j++;
			}
			FireShot(shotA);
		}
	if(count>=600&&count%500==200){
		CreateEnemyFromScript("DOLL01",GetX,GetY,0,0,1);
		SetX(rand(100,348));
		SetY(rand(100,175));
		}
	if(count>=600&&count%500==201){
		rcx=GetX;
		rcy=GetY;
		}
        if(GetEnemyLife<=1&&!Flag){
			Flag=true;
			Explosion01(GetX(),GetY(),1/60*255,0.3,60);
			PlaySE(shotseB);
        	}
	SetCollisionA(GetX(),GetY(),32);
        SetCollisionB(GetX(),GetY(),24);
        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
        {
		PlaySE(shotseB);
        } 
	
    	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 Animation=0;
        let angle = 0;
        let csd     = GetCurrentScriptDirectory;
        let imgBoss2 =csd~"img\dot_yousei3.png";
	let Zoom=0;
	let imgEnemy=csd~"img\familiar.png";
	let imgAngle=0;
	let imgAlpha=0;
	let shotseA = csd~"se\ShotSE02.wav";
	let deathse = csd~"se\DEATH.wav";

    @Initialize {
        SetX(GetEnemyX);
        SetY(GetEnemyY);
        SetLife(10);
        SetScore(0);
        SetDamageRateEx(0,0,75,0);
        Tup;
    }

    @MainLoop {
	imgAngle+=4;
	if(imgAngle>360){imgAngle=0;}
        	if(count>=0&&count<=110)
        	{
        	imgAlpha+=2.5;
        	if(imgAlpha>255){imgAlpha=255;}
        	}
        	if(count<=500&&count>=100&&count%25==0)
        	{
                SetShotDirectionType(PLAYER);
		PlaySE(shotseA);
                angle=rand(-2,2);
        		let i = 0;
        		while( i < 24 )
        		{
        		let shot01 = 1;
        		SetShotDirectionType(PLAYER);
        		CreateShotA(shot01,GetX(),GetY(),0);
        		SetShotDataA(shot01,0,2,15*i,0,-0.01,1.5,GREEN04);
        		SetShotDataA(shot01,50,NULL,NULL,angle,0,1.5,GREEN04);
        		SetShotDataA(shot01,80,NULL,NULL,0,0,1.5,GREEN04);
        		FireShot(shot01);
        		i++;
        		}
        	}
		if(GetHitCount){
			SetShotDirectionType(ABSOLUTE);
			PlaySE(deathse);
        		let i = 0;
        		while( i < 3 )
        		{
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),0);
			SetShotDataA(shotA,0,6,rand(0,360),0,-0.2,0,PURPLE03);
			SetShotDirectionType(PLAYER);
			SetShotDataA(shotA,40,1,-30+30*i,0,0.1,8,PURPLE03);
			FireShot(shotA);
        		i++;
        		}
		}
        	if(count==500)
        	{
                VanishEnemy();
        	}
        SetCollisionA(GetX(),GetY(),10);
        count++;
        yield;
    }


        @DrawLoop {
		SetAlpha(imgAlpha);
		SetGraphicRect(0,0,47,47);
		SetTexture(imgEnemy);
		SetGraphicScale(2+0.02*Zoom,2+0.02*Zoom);
		SetRenderState(ALPHA);
		SetGraphicAngle(0,0,imgAngle);
		DrawGraphic(GetX(),GetY());
		SetRenderState(ALPHA);
		SetGraphicAngle(0,0,-imgAngle);
		DrawGraphic(GetX(),GetY());

		SetRenderState(ALPHA);
		SetTexture(imgBoss2);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		SetGraphicRect(195,1,216,32);
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
        }
    	task Tup{
		loop{
			Zoom=0;
        		loop(1){yield;}
			Zoom=1;
        		loop(2){yield;}
			Zoom=2;
        		loop(2){yield;}
			Zoom=3;
        		loop(2){yield;}
			Zoom=4;
        		loop(3){yield;}
			Zoom=5;
        		loop(15){yield;}
			Zoom=4;
        		loop(3){yield;}
			Zoom=3;
        		loop(2){yield;}
			Zoom=2;
        		loop(2){yield;}
			Zoom=1;
        		loop(1){yield;}
			}
		}
}