#Title[睡魔「闇へと誘う悪夢」]
#Text[古明地さとりのスペルカード]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name="睡魔「闇へと誘う悪夢」";
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\ExSatori.png";
	let imgEnemy=csd~"img\familiar.png";
        let Lock=0;
        let angle=0;
	let shotseA=csd~"se\Powar.wav";

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

        SetLife(500);
        SetTimer(35);
        SetScore(1000000);
        SetDamageRate(20,20);

        SetInvincibility(200);
        SetMovePosition02(GetCenterX(),150,60);
	LoadGraphic(imgBoss);
	LoadGraphic(imgEnemy);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
    }

        @MainLoop
        {
	if(count>=150&&count%300==150){
		Concentration01(60);
		}
	if(count>=200&&count%300==200){
		Lock=GetAngleToPlayer;
		PlaySE(shotseA);
		let angleFam=[Lock,Lock+45,Lock+90,Lock-45,Lock-90];
		ascent(i in 0..5){CreateEnemyFromScript("DOLL01",GetX,GetY,0,angleFam[i],1);}
		}
	if(count>=300&&count%300==100){
        	SetShotDirectionType(PLAYER);
		let i=0;
		while(i<5)
		{
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,20);
			SetShotDataA(shotA,0,1.5,i*20-40,0,0,1.5,35);
			FireShot(shotA);
			i++;
			}
		SetMovePositionRandom01(50,20,2,GetClipMinX()+75,100,GetClipMaxX()-75,150);
		}
        SetCollisionB(GetX(),GetY(),22);
	SetCollisionA(GetX(),GetY(),22);
        count++;
        }

	@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(imgEnemy);
	}

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		SetGraphicAngle(0,0,0);
		if(int(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());
	}
}

script_enemy DOLL01 {
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd=GetCurrentScriptDirectory;
	let MAnimation=0;
	let imgEnemy=csd~"img\familiar.png";
	let imgAngle=0;
        let angle=GetAngle;
        let Flag=false;
        let ranX=0;

    @Initialize {
        SetLife(1000);
        SetInvincibility(0);
	SetMovePosition01(GetEnemyX+cos(angle)*1000,GetEnemyY+sin(angle)*1000,2);
    }

        @MainLoop
        {
	imgAngle+=4;
	if(imgAngle>360){imgAngle=0;}
	MAnimation-=10;
	if(MAnimation<-360){MAnimation=0;}
	if(count>=75&&count%75==0){
        SetShotDirectionType(ABSOLUTE);
	ranX=rand(0,360);
	let i=0;
	while(i<6)
		{
		let shotA=0;
		CreateShotA(shotA,GetX,GetY,20);
		SetShotDataA(shotA,0,2,ranX+i*60,0,0,2,226);
		SetShotDataA(shotA,20,NULL,NULL,0,-0.1,0,226);
		SetShotDataA(shotA,45,NULL,NULL,-8,0.01,1,226);
		SetShotDataA(shotA,65,NULL,NULL,0,0.01,1,226);
		FireShot(shotA);
		CreateShotA(shotA,GetX,GetY,20);
		SetShotDataA(shotA,0,2,ranX+i*60,0,0,2,221);
		SetShotDataA(shotA,20,NULL,NULL,0,-0.1,0,221);
		SetShotDataA(shotA,45,NULL,NULL,8,0.01,1,221);
		SetShotDataA(shotA,65,NULL,NULL,0,0.01,1,221);
		FireShot(shotA);
		i++;
		}
	}

        	if(GetX<20||GetX>428||GetY<20||GetY>460&&!Flag){
        	if(angle>0&&angle<=90&&GetX>428){
        		angle=180-angle;
			SetMovePosition01(GetX+cos(angle)*1000,GetY+sin(angle)*1000,2);
        	}
        	if(angle>90&&angle<=180&&GetX<20){
        		angle=180-angle;
			SetMovePosition01(GetX+cos(angle)*1000,GetY+sin(angle)*1000,2);
        	}
        	if(angle>180&&angle<=270&&GetX<20){
        		angle=540-angle;
			SetMovePosition01(GetX+cos(angle)*1000,GetY+sin(angle)*1000,2);
        	} else if(angle>180&&angle<=270&&GetY<20){
        		angle=360-angle;
			SetMovePosition01(GetX+cos(angle)*1000,GetY+sin(angle)*1000,2);
        	}
        	if(angle>270&&angle<=360&&GetY<20){
        		angle=360-angle;
			SetMovePosition01(GetX+cos(angle)*1000,GetY+sin(angle)*1000,2);
        	} else if(angle>270&&angle<=360&&GetX>428){
        		angle=540-angle;
			SetMovePosition01(GetX+cos(angle)*1000,GetY+sin(angle)*1000,2);
        	}
        		Flag=true;
        	}
        	if(GetX<-20||GetX>468||GetY<-20||GetY>500)
        	{
        		VanishEnemy();
        	}
        count++;
        }

        @DrawLoop {
		SetGraphicRect(288,48,336,96);
		SetTexture(imgEnemy);
		SetGraphicScale(1,1);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetGraphicAngle(0,0,imgAngle);
		DrawGraphic(GetX(),GetY());
		SetGraphicAngle(0,0,-imgAngle);
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
        }
}
