#e
#Title[uXy[XfBV[o[v]
#Text[]
#Image[.]
#Player[FREE]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {
    let name    = "uXy[XfBV[o[v";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "lib/dot_sakuya.png"; 
    let imgFam  = csd ~ "img\familiar.png";
SetRateScoreSystemEnable(false);
    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
let judg=0;
    @Initialize {

        SetLife(1700);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

    @MainLoop {
	if(!OnBomb)
	{
	SetAlpha(255);
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	if(judg==1)
	{
        SetDamageRate(50, 0);
	}
	}

	if(OnBomb)
	{
		SetAlpha(100);
      		  SetDamageRate(0, 0);
		judg=1;

	}
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
	DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // C^XN
task TMain 
{
	yield;
	standBy;
	spell;
	stop;
	cut;
	wait(120);
	summon;
	Trate;
	TMove;
	Shot;
	SubShot;
}

task Trate
{
	wait(180);
        SetDamageRate(50, 50);
}

task cut
{
CreateLaserA(1,GetClipMinX-60,185,0,4,WHITE01,0);
SetLaserDataA(1,0,0,0,10,0,0);
SetLaserDataA(1,60,0,0,0,0,0);
FireShot(1);
CreateLaserA(1,GetClipMaxX+60,185,0,4,WHITE01,0);
SetLaserDataA(1,0,180,0,10,0,0);
SetLaserDataA(1,60,180,0,0,0,0);
FireShot(1);
CreateLaserA(1,GetClipMinX-60,330,0,4,WHITE01,0);
SetLaserDataA(1,0,0,0,10,0,0);
SetLaserDataA(1,60,0,0,0,0,0);
FireShot(1);
CreateLaserA(1,GetClipMaxX+60,330,0,4,WHITE01,0);
SetLaserDataA(1,0,180,0,10,0,0);
SetLaserDataA(1,60,180,0,0,0,0);
FireShot(1);
}

task summon
{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 0, 1);
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 0, -1);
}

sub standBy//ʒu
{
	SetAction(ACT_MOVE, 60);
	let wIni = 60;
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

sub spell//[V
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(50);
        SetScore(22000000/3);
	SetAction(ACT_SPELL,90);
	wait(90);
}

task stop
{
loop
{
	if(GetPlayerY<=330)
	{
	SetPlayerY(331);
	}
yield;	
}
}

task TMove// gƈړ
{
	let angle = 0;
	let count=0;
	let y=yIni;
	loop
	{
		SetY(y + 4 * sin(angle));
		yield;
		angle += 3;
	if(count>=140)
	{
	moveToPlayer(rand(40, 60), rand(-30, 30), 30,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	
	wait(30);
	y=GetY;
	count=0;
	angle = 0;
	}
	count++;
	}
}


task Shot
{
	loop
	{
		let angle=GetAngleToPlayer;
		loop(5)
		{
			shot(GetX,GetY,3,angle,RED32,0);
			shot(GetX,GetY,3,angle-20,RED32,0);
			shot(GetX,GetY,3,angle+20,RED32,0);
			wait(5);
		}
		wait(60);
		yield;
	}
}

task SubShot
{
	wait(30);
	loop
	{
		let angle=0;
		let x=0;
		loop(120)
		{
			shot(xIni+120,yIni-60,3,GetAngleToPlayer+rand(-90,90),BLUE32,0);
			shot(xIni-120,yIni-60,3,GetAngleToPlayer+rand(-90,90),BLUE32,0);
			wait(4);
		}
		yield;
	}
}

task shot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	while(!Obj_BeDeleted(obj))
	{
		if(Obj_GetY(obj)>180 && count==0)//[ł̋
		{
			Obj_SetY(obj,330);
			count=1;
        	}
		yield;
    	}

}

    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;

        if(GetPlayerX < GetX)
	{
            x = GetX - xMove;

            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            x = GetX + xMove;

            if(right < x) {
                x = GetX - xMove;
            }
        }

        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
SetAction(ACT_MOVE,60);
    }

#include_function ".\data.txt"
#include_function ".\lib/lib_anime_Sakuya.txt"
}


script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "img\familiar.png";


    @Initialize {
        SetLife(2000);
        SetDamageRate(50, 50);
	let num = GetArgument;
        SetTexture(imgFam);
        setGraphic;
	SetMovePosition02(GetEnemyX+120*num,GetEnemyY-60,30);
        TMain;
    }

    @MainLoop {

        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    task TMain {
        yield;
    }


    // OtBbN̐ݒ
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }

}