#e
#Title[yu}bhEH[v]
#Text[]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {
    let name    = "yu}bhEH[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(1100);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

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

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // C^XN
task TMain 
{
	yield;
	standBy;
	spell;
	Trate;
	TMove;
	Shot;
	SubShot;
}

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




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>=90)
	{
	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 dir=1;
	loop
	{
	let x1=rand(GetClipMinX+48,GetCenterX-112);
	let x2=rand(GetCenterX+112,GetClipMaxX-48);
	let y=GetClipMaxY;
	let a=50;
	let delay=30;
	let wtime=90;
	let angle=rand(60,120);
	ascent(let i in 0..21)
	{
		loop(21-i)
		{
		let angle=rand(50,130);
		CreateShotA(1,rand(x1-a,x1+a),y+rand(-5,5),delay);
		SetShotDataA(1,0,0,angle,0,0,3,YELLOW01);
		SetShotDataA(1,180-i*8,0,angle,0,0.05,3,YELLOW21);
		FireShot(1);
		CreateShotA(1,rand(x2-a,x2+a),y+rand(-5,5),delay);
		SetShotDataA(1,0,0,angle,0,0,3,YELLOW01);
		SetShotDataA(1,180-i*8,0,angle,0,0.05,3,YELLOW21);
		FireShot(1);
		}
	wait(4);
	a-=2.5;
	y-=(GetClipMaxY-GetClipMinY)/20;
	}
		wait(wtime);
		if(wtime>=60)
		{
		wtime-=5;
		}
		a=50;
		y=GetClipMaxY;
		let x3=GetPlayerX;
	ascent(let i in 0..21)
	{
		loop(21-i)
		{
		let angle=rand(50,130);
		CreateShotA(1,rand(x3-a,x3+a),y+rand(-5,5),delay);
		SetShotDataA(1,0,0,angle,0,0,3,YELLOW01);
		SetShotDataA(1,180-i*8,0,angle,0,0.05,3,YELLOW21);
		FireShot(1);
		}
	wait(4);
	a-=2.5;
	y-=(GetClipMaxY-GetClipMinY)/20;
	}
	wait(wtime);
		if(wtime>=60)
		{
		wtime-=5;
		}
	}
}

task SubShot
{
wait(60);
let wtime=60;
loop
{
	ascent(let i in -1..2)
	{
	CreateShot01(GetX,GetY,2,GetAngleToPlayer+i*360/16,YELLOW03,30);
	}
	if(GetTimer<=30)
	{
	CreateShot01(GetX,GetY,2,GetAngleToPlayer-2*360/16,YELLOW03,30);
	CreateShot01(GetX,GetY,2,GetAngleToPlayer+2*360/16,YELLOW03,30);
	}
wait(wtime);

}
}
task shot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let count=0;
	let count1=0;
	let width=90;
	let length=0;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	ObjLaser_SetLength(obj, width);
	ObjLaser_SetWidth(obj, length);
	ObjLaser_SetSource(obj,false);
	while(!Obj_BeDeleted(obj))
	{
	ObjLaser_SetLength(obj, length);
	ObjLaser_SetWidth(obj,width );
	length+=2;
		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_Patchouli.txt"
}
