#e
#Title[ʏ4]
#Text[]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {
    let name    = "ʏ4";
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;
    @Initialize {

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

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
        yield;
    }

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // C^XN
task TMain 
{
	yield;
	standBy;
	wait(60);
        SetTimer(40);
	Trate;
	TMove;
	Shot;
	SubShot;
}

task Trate
{
	wait(120);
        SetDamageRate(100, 100);
}

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

task TMove// gƈړ
{
wait(30);
	loop
	{
	wait(135);
	moveToPlayer(rand(40, 60), rand(-30, 30), 30,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	}
}


task Shot
{
	loop
	{
	let angle1=GetAngleToPlayer;
	let angle2=atan2(GetPlayerY-GetY,2*GetClipMaxX-GetPlayerX-GetX);
	let angle3=atan2(GetPlayerY-GetY,2*GetClipMinX-GetPlayerX-GetX);
		loop(5)
		{
		shot(GetX,GetY,4,angle1,BLUE32,0);
		shot(GetX,GetY,4,angle2,BLUE32,0);
		shot(GetX,GetY,4,angle3,BLUE32,0);
		wait(3);
		}
	wait(120);
	}
}


task SubShot
{
	loop
	{
	let angle=rand(0,360);
		ascent(let i in 0..37)
		{
		CreateShot01(GetX,GetY,2,angle+i*10,RED31,0)
		}
		wait(20);
	}
}

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_GetX(obj)<GetClipMinX)//[ł̋
		{
			Obj_SetX(obj, GetClipMinX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-Obj_GetAngle(obj));
        	}
		if(Obj_GetX(obj)>GetClipMaxX)//E[ł̋
		{
			Obj_SetX(obj, GetClipMaxX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-Obj_GetAngle(obj));
        	}
		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"
}