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

        SetLife(1500);
        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;
	spell;
	Trate;
	TMove;
	Shot;
}

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

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 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
{
let w=90;
let dir=1;
	loop
	{
		loop(4)
		{
			CreateShot01(rand(GetClipMinX-64,GetClipMaxX+64), GetClipMinY,rand(2,3),w,GREEN11,30);
		}
		if(w<=170 && dir==1)
		{
			w+=2;
		}
		if(w>=10 && dir==-1)
		{
			w-=2;
		}
		if(w>=170)
		{
			dir=-1;
			wait(30);
		}
		if(w<=10)
		{
			dir=1;
			wait(30);
		}
	wait(2);
	}
}


    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_Patchouli.txt"
}
