#e
#Title[uNCbN^Cv]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {
    let name    = "uNCbN^Cv";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "lib/dot_sakuya.png"; 
    let imgFam  = csd ~ "img\familiar.png";
SetRateScoreSystemEnable(false);
let a =99;
let judg=0;
    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
let count=0;

    @Initialize {

        SetLife(6200);
        SetDamageRate(5, 0);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
	SetEffectForZeroLife(90,100,100);
        TMain;
	}

    @MainLoop {
	if(!OnBomb)
	{
		SetAlpha(255);
		if(count>=300)
		{
			a=GetTimer;
		}
		SetCollisionA(GetX, GetY, 32);
		if(judg==1)
		{
			SetDamageRate(50, 0);
		}
	}

	if(OnBomb)
	{
		SetAlpha(100);
       		 SetTimer(a+1);
		SetDamageRate(0, 0);
		judg=1;

	}
	count++;
        yield;
    }

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // C^XN
task TMain 
{
	yield;
	standBy;
	spell;
	wait(60);
	Trate;
	Shot;
}

task Trate
{
	wait(500);
        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(110);
        SetScore(22000000/3);
	SetDurableSpellCard;
	SetAction(ACT_SPELL,90);
	wait(90);
}


task Shot
{
let delay1=90;
let delay2=13;
let speed =2.5;
let count=1;
	loop
	{
		let time=0;
		let angle =rand(0,360);
		ascent(let j in 0..21)
		{
			ascent(let i in 0..11)
			{
				if(count%2==1)
				{
					shot(GetX,GetY,0.25,angle+i*36+j*4,RED32,time, speed);
				}
				else
				{
					shot(GetX,GetY,0.25,angle+i*36-j*4,BLUE32,time, speed);
				}
			}
			time+=delay2;
			wait(delay2);
					if(OnBomb)
			{
				loop
				{
					yield;
					if(!OnBomb)
					{
						break;
					}
				}
			}
		}

		wait(delay1);
		delay1-=5;
		if(GetEnemyLife>=2000)
		{
		delay2=truncate((GetEnemyLife-2000)/1000)+3;
		}
		count++;
			if(OnBomb)
			{
				loop
				{
					yield;
					if(!OnBomb)
					{
						break;
					}
				}
			}
		if(GetTimer<=25)
		{
			delay1=0;
			delay2=3.5;
			speed=2.5;
		}
	}
}


task shot(let x, let y, let speed,let angle, let graphic, let time, let speed2)
{
	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, 0);
	ObjShot_SetBombResist(obj,true);

	while(!Obj_BeDeleted(obj))
	{

		if(Obj_GetX(obj)<=GetClipMinX && count==0)//[ł̋
		{
			Obj_SetX(obj, GetClipMinX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-angle);
			count=1;
        	}
		if(Obj_GetX(obj)>=GetClipMaxX && count==0)//E[ł̋
		{
			Obj_SetX(obj, GetClipMaxX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-angle);
			count=1;
        	}

			Obj_SetSpeed(obj, speed);
		if(time>=300)
		{
			Obj_SetSpeed(obj, speed2);

		}
		if(OnBomb)
		{
			loop
			{
				Obj_SetSpeed(obj, 0);
				ObjShot_SetGraphic(obj, WHITE32);
			if(!OnBomb)
			{
				ObjShot_SetGraphic(obj, graphic);
				break;
			}
			yield;
			}
		}
		time++;
		yield;
    	}


}


#include_function ".\data.txt"
#include_function ".\lib/lib_anime_Sakuya.txt"
}