#e
#Title[ʏ2]
#Text[]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {
    let name    = "ʏ2";
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(90);
        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ƈړ
{
	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 x=GetX+rand(-30,30);
		let y=GetY+rand(-30,30);
		let angle=atan2(GetPlayerY-y,GetPlayerX-x);
		ascent(let i in 1..12)
		{
			CreateShot01(x,y,i*0.5,angle,RED32,30);
			CreateShot01(x,y,i*0.5,angle+15,RED32,30);
			CreateShot01(x,y,i*0.5,angle-15,RED32,30);
		}
		wait(60);
	}
}

task SubShot
{
let angle=rand(0,45);
	wait(30);
	loop
	{
		loop(24)
		{
		CreateShot01(GetX,GetY,2,angle,BLUE32,10);
		angle+=15;
		}
		wait(30);
		loop(24)
		{
		CreateShot01(GetX,GetY,2,angle+11.15,BLUE32,10);
		angle+=15;
		}
		wait(60);
		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"
}
