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

    @MainLoop {
	if(!OnBomb)
	{
	SetAlpha(255);
        SetCollisionA(GetX, GetY, 32);
	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;
	Trate;
	TMove;
	Shot;
}

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

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


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
{
let w=0;
	loop
	{
	let angle=GetAngleToPlayer;
		ascent(let i in 0..10)
		{
		shot(GetCenterX+(i-4)*45+cos(angle),GetClipMinY+sin(angle),3+w/100,90,RED32,0,w);
		}
		wait(30);
		w+=2;
		yield;
	}
}

task shot(let x, let y, let speed,let angle, let graphic, let delay,let w)
{
	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)>GetClipMaxY)//[ł̋
		{
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1,rand(230,310),RED31,0);
			ascent(let i in 0..10)
			{
			shot2(Obj_GetX(obj),Obj_GetY(obj),i*-20,90+w);
			}
			Obj_Delete(obj);
        	}
		yield;
    	}

}

task shot2(let x, let y,let angle, let w)
{
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, 1);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, RED31);
	ObjShot_SetDelay(obj, 0);
	wait(w);
	ObjShot_FadeDelete(obj);

}

    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"
}
