#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;
	let shotseA = csd~"se\ShotSE02.wav";

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

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

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

        SetInvincibility(0);
        SetMovePosition02(cx,150,60);
	LoadGraphic(imgBoss);
	LoadGraphic(imgBoss2);
	LoadGraphic(imgSPELL);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
        TAnime1;
    }

        @MainLoop
        {
	imgAngle2++;
	if(imgAngle2>360){imgAngle2=0;}
	if(count==150){
		Motion=1;
		Concentration01(60);
        	SetDamageRate(20,10);
		let angleFam   = [0,60,120,180,240,300];
		ascent(i in 0..6) {CreateEnemyFromScript("DOLL01",GetX,GetY,1,angleFam[i],1);}
		ascent(i in 0..6) {CreateEnemyFromScript("DOLL02",GetX,GetY,2,angleFam[i]+30,1);}
		}
	if(count==200){
		Motion=0;
        	SetDamageRate(100,50);
		}
	if(count>=400&&count%5==0){
		PlaySE(shotseA);
		let i=0;
		while(i<3)
		{
        	let shot01 = 1;
        	CreateShotA(shot01,GetX+cos(angle)*30,GetY+sin(angle)*30,10);
        	SetShotDataA(shot01,0,3,i*120+angle,0,-0.02,1,BLUE01);
        	FireShot(shot01);
        	CreateShotA(shot01,GetX+cos(angle-180)*30,GetY+sin(angle-180)*30,10);
        	SetShotDataA(shot01,0,3,i*120+angle-180,0,-0.02,1,PURPLE01);
        	FireShot(shot01);
		i++;
		}
		angle=angle+11;
		}
	if(count>=300&&count%300==0){
		TAnime2;
		SetMovePositionRandom01(rand(5,150),rand(10,40),2,GetClipMinX()+100,100,GetClipMaxX()-100,175);
		}
	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(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;}
		}
}

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 shotseB = csd~"se\laser001.wav";

    @Initialize {
        SetLife(50);
        TAnime1;
    }

    @MainLoop {
        	if(count==50)
        	{
        	SetMovePosition01(GetX,GetY,50);
        	r=((GetEnemyX-GetX)^2+(GetEnemyY-GetY)^2)^0.5;
        	}
	if(count>=150&&count%50==0){
        SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseB);
        	Slaser(angle+120);
        	Slaser(angle-60);
		}
        if(count>=150&&count%10==0)
        	{
		SetMovePosition02(GetEnemyX+cos(angle)*r,GetEnemyY+sin(angle)*r,10);
        	angle=angle+10;
        	}
        SetCollisionB(GetX(),GetY(),10);
        count++;
        yield;
    }

        @DrawLoop {
		SetTexture(imgBoss2);
		SetAlpha(155);
		SetGraphicRect(Animation*32,0,31+Animation*32,31);
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
        }
    	task TAnime1{
		loop{
			Animation=3;
        		loop(10){yield;}
			Animation=4;
        		loop(10){yield;}
			Animation=5;
        		loop(10){yield;}
			}
		}

    	task Slaser(angle){
		let obj = Obj_Create(OBJ_LASER);
		let l = 0;
		Obj_SetPosition(obj,GetX(),GetY());
		Obj_SetAngle(obj,angle);
		ObjShot_SetGraphic(obj,71);
		ObjShot_SetDelay(obj,40);
		ObjLaser_SetSource(obj,false);
		ObjLaser_SetWidth(obj,10);
	loop(50){
		ObjLaser_SetLength(obj,l*10);
		l++;
		yield;}
	loop(50){yield;}
	Obj_Delete(obj);
	}
}

script_enemy DOLL02 {
        let count=0;
        let angle = GetAngle;
        let angleB = GetAngle;
        let r = 0;
	let Animation=0;
	let Animation2=0;
        let csd     = GetCurrentScriptDirectory;
        let imgBoss2 =csd~"img\dot_yousei3.png";
	let shotseB = csd~"se\laser001.wav";

    @Initialize {
        SetLife(50);
        TAnime1;
    }

    @MainLoop {
        	if(count==50)
        	{
        	SetMovePosition01(GetX,GetY,50);
        	r=((GetEnemyX-GetX)^2+(GetEnemyY-GetY)^2)^0.5;
        	}
	if(count>=150&&count%50==0){
        SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseB);
        	Slaser(angle+120);
        	Slaser(angle-60);
		}
        if(count>=150&&count%10==0)
        	{
		SetMovePosition02(GetEnemyX+cos(angle)*r,GetEnemyY+sin(angle)*r,10);
        	angle=angle-10;
        	}
        SetCollisionB(GetX(),GetY(),10);
        count++;
        yield;
    }

        @DrawLoop {
		SetTexture(imgBoss2);
		SetAlpha(155);
		SetGraphicRect(Animation*32,0,31+Animation*32,31);
		DrawGraphic(GetX(),GetY());
	}
        
        @Finalize
        {
        }
    	task TAnime1{
		loop{
			Animation=3;
        		loop(10){yield;}
			Animation=4;
        		loop(10){yield;}
			Animation=5;
        		loop(10){yield;}
			}
		}

    	task Slaser(angle){
		let obj = Obj_Create(OBJ_LASER);
		let l = 0;
		Obj_SetPosition(obj,GetX(),GetY());
		Obj_SetAngle(obj,angle);
		ObjShot_SetGraphic(obj,71);
		ObjShot_SetDelay(obj,40);
		ObjLaser_SetSource(obj,false);
		ObjLaser_SetWidth(obj,10);
	loop(50){
		ObjLaser_SetLength(obj,l*10);
		l++;
		yield;}
	loop(50){yield;}
	Obj_Delete(obj);
	}
}