#e
#Title[܁utNV[U[v]
#Text[]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {
    let name    = "܁utNV[U[v";
let csd = GetCurrentScriptDirectory;
    let imgBoss = "script\img\ExRumia.png";
let imgFam  = csd ~ "img\familiar.png";

SetRateScoreSystemEnable(false);
    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;

    @Initialize {
        SetLife(1500);
        SetDamageRate(0, 0);
        LoadGraphic(imgFam);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
        setGraphicPose;
        TMain;
    }

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

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // C^XN
task TMain 
{
	yield;
	standBy;
	spell;
	setfam;
	wait(60);
	TRate;
	RefractionShot;
	LShot;

}

sub standBy//ʒu
{
	let wIni = 60;
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

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

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


sub setfam//g
{
	let a = -3;
	let b = 4;
	ascent(let i in a..b)
	{
	CreateEnemyFromScript("Fam", GetX, GetY,0, 0, i);
	CreateEnemyFromScript("Fam2", GetX, GetY,0, 0, i);
	CreateEnemyFromScript("Fam3", GetX, GetY,0, 0, i);
	CreateEnemyFromScript("Fam4", GetX, GetY,0, 0, i);
	CreateEnemyFromScript("Fam5", GetX, GetY,0, 0, i);
	CreateEnemyFromScript("Fam6", GetX, GetY,0, 0, i);
	}
}


task LShot
{
loop
{
CreateLaser01(GetX,GetY,4,GetAngleToPlayer,150,8,PURPLE21,0);
CreateLaser01(GetX,GetY,4,GetAngleToPlayer-5,150,8,PURPLE21,0);
CreateLaser01(GetX,GetY,4,GetAngleToPlayer+5,150,8,PURPLE21,0);
CreateLaser01(GetX,GetY,4,GetAngleToPlayer-15,150,8,PURPLE21,0);
CreateLaser01(GetX,GetY,4,GetAngleToPlayer+15,150,8,PURPLE21,0);
wait(60);
}
}

task RefractionShot//܃[U[
{
let speed=7;
let x=[GetX,GetX-50,GetX+50,GetX-100,GetX+100,GetX-150,GetX+150];
let y=[GetY-100,GetY-50,GetY,GetY+50,GetY+100,GetY+150];
	loop
	{
let yy=y[rand_int(0,5)];
let xx=0;
if(yy==y[0] || yy==y[1])
{
	xx=x[rand_int(0,6)];
}
if(yy==y[2] || yy==y[3])
{
	xx=x[rand_int(1,6)];
}
if(yy==y[4])
{
	xx=x[rand_int(3,6)];
}
if(yy==y[5])
{
	xx=x[rand_int(5,6)];
}
let angle=atan2(yy-GetY,xx-GetX);
let d=((GetX-xx)^2+(GetY-yy)^2)^(1/2);

let yy2=y[rand_int(0,5)];
let xx2=0;
if(yy2==y[0] || yy2==y[1])
{
	xx2=x[rand_int(0,6)];
}
if(yy2==y[2] || yy2==y[3])
{
	xx2=x[rand_int(1,6)];
}
if(yy2==y[4])
{
	xx2=x[rand_int(3,6)];
}
if(yy2==y[5])
{
	xx2=x[rand_int(5,6)];
}
if(yy2==yy && xx2==xx)
{
yy2=y[rand_int(0,5)];
xx2=x[rand_int(0,6)];
}
let angle2=atan2(yy2-yy,xx2-xx);
let d2=((xx2-xx)^2+(yy2-yy)^2)^(1/2);
let angle3=atan2(GetPlayerY-yy2,GetPlayerX-xx2);
		CreateLaserC(1,GetX,GetY,10,32,BLUE21,0);
		SetLaserDataC(1,0,speed,angle,0,0,0);
		SetLaserDataC(1,d/speed,speed,angle2,0,0,0);
		SetLaserDataC(1,d/speed+d2/speed,speed,angle3,0,0,0);
		FireShot(1);
		wait(15);
		yield;
	}
}
    sub setGraphicStop  { SetGraphicRect(  0,   0,  64,  64); }
    sub setGraphicPose  { SetGraphicRect( 64,   0, 128,  64); }
    sub setGraphicLeft  { SetGraphicRect(128,   0, 192,  64); }
    sub setGraphicRight { SetGraphicRect(192,   0, 256,  64); }
#include_function ".\data.h.txt"
}

script_enemy Fam
{
let csd = GetCurrentScriptDirectory;
let imgFam  = csd ~ "img\familiar.png";
let num = GetArgument;
	@Initialize 
	{
	SetTexture(imgFam);
	setGraphicFast;
	SetDamageRateEx(50, 0, 25, 0);
	SetLife(7000);
	SetMovePosition02(GetEnemyX+50*num,GetEnemyY,60);
	}

	@MainLoop 
	{
		if(GetKeyState(VK_SLOWMOVE) == KEY_HOLD) {
		setGraphicSlow;
	} 
	else 
	{
		SetCollisionA(GetX, GetY, 16);
		setGraphicFast;
	}
	if(num==0)
	{
	VanishEnemy;
	}
	yield;
	}

	@DrawLoop 
	{
	DrawGraphic(GetX, GetY);
	}

    @Finalize {
}

sub setGraphicFast { SetGraphicRect( 0,  0, 48, 48); }
sub setGraphicSlow { SetGraphicRect( 0, 48, 48, 96); }

#include_function ".\data.h.txt"
}


script_enemy Fam2
{
let csd = GetCurrentScriptDirectory;
let imgFam  = csd ~ "img\familiar.png";
let num = GetArgument;
	@Initialize 
	{
	SetTexture(imgFam);
	setGraphicFast;
	SetDamageRateEx(50, 0, 25, 0);
	SetLife(7000);
	SetMovePosition02(GetEnemyX+50*num,GetEnemyY-50,60);
	}

	@MainLoop 
	{

	if(GetKeyState(VK_SLOWMOVE) == KEY_HOLD) 
	{
		setGraphicSlow;
	} 
	else 
	{
		SetCollisionA(GetX, GetY, 16);
		setGraphicFast;
	}
	yield;
	}

	@DrawLoop 
	{
	DrawGraphic(GetX, GetY);
	}

    @Finalize {
}

sub setGraphicFast { SetGraphicRect( 0,  0, 48, 48); }
sub setGraphicSlow { SetGraphicRect( 0, 48, 48, 96); }

#include_function ".\data.h.txt"
}

script_enemy Fam3
{
let csd = GetCurrentScriptDirectory;
let imgFam  = csd ~ "img\familiar.png";
let num = GetArgument;
	@Initialize 
	{
	SetTexture(imgFam);
	setGraphicFast;
	SetDamageRateEx(50, 0, 25, 0);
	SetLife(7000);
	SetMovePosition02(GetEnemyX+50*num,GetEnemyY-100,60);
	}

	@MainLoop 
	{
	if(GetKeyState(VK_SLOWMOVE) == KEY_HOLD) 
	{
		setGraphicSlow;
	} 
	else 
	{
		SetCollisionA(GetX, GetY, 16);
		setGraphicFast;
	}
	yield;
	}

	@DrawLoop 
	{
	DrawGraphic(GetX, GetY);
	}

    @Finalize {
}

sub setGraphicFast { SetGraphicRect( 0,  0, 48, 48); }
sub setGraphicSlow { SetGraphicRect( 0, 48, 48, 96); }

#include_function ".\data.h.txt"
}

script_enemy Fam4
{
let csd = GetCurrentScriptDirectory;
let imgFam  = csd ~ "img\familiar.png";
let num = GetArgument;
	@Initialize 
	{
	SetTexture(imgFam);
	setGraphicFast;
	SetDamageRateEx(50, 0, 25, 0);
	SetLife(7000);
	SetMovePosition02(GetEnemyX+50*num,GetEnemyY+50,60);
	}

	@MainLoop 
	{
	if(GetKeyState(VK_SLOWMOVE) == KEY_HOLD) 
	{
		setGraphicSlow;
	} 
	else 
	{
		SetCollisionA(GetX, GetY, 16);
		setGraphicFast;
	}
	if(num==0)
	{
	VanishEnemy;
	}
	yield;
	}

	@DrawLoop 
	{
	DrawGraphic(GetX, GetY);
	}

    @Finalize {
}

sub setGraphicFast { SetGraphicRect( 0,  0, 48, 48); }
sub setGraphicSlow { SetGraphicRect( 0, 48, 48, 96); }

#include_function ".\data.h.txt"
}

script_enemy Fam5
{
let csd = GetCurrentScriptDirectory;
let imgFam  = csd ~ "img\familiar.png";
let num = GetArgument;
	@Initialize 
	{
	SetTexture(imgFam);
	setGraphicFast;
	SetDamageRateEx(50, 0, 25, 0);
	SetLife(7000);
	SetMovePosition02(GetEnemyX+50*num,GetEnemyY+100,60);
	}

	@MainLoop 
	{
	if(GetKeyState(VK_SLOWMOVE) == KEY_HOLD) 
	{
		setGraphicSlow;
	} 
	else 
	{
		SetCollisionA(GetX, GetY, 16);
		setGraphicFast;
	}
	if(num==0 || num==1 || num==-1)
	{
	VanishEnemy;
	}
	yield;
	}

	@DrawLoop 
	{
	DrawGraphic(GetX, GetY);
	}

    @Finalize {
}

sub setGraphicFast { SetGraphicRect( 0,  0, 48, 48); }
sub setGraphicSlow { SetGraphicRect( 0, 48, 48, 96); }

#include_function ".\data.h.txt"
}

script_enemy Fam6
{
let csd = GetCurrentScriptDirectory;
let imgFam  = csd ~ "img\familiar.png";
let num = GetArgument;
	@Initialize 
	{
	SetTexture(imgFam);
	setGraphicFast;
	SetDamageRateEx(50, 0, 25, 0);
	SetLife(7000);
	SetMovePosition02(GetEnemyX+50*num,GetEnemyY+150,60);
	}

	@MainLoop 
	{
	if(GetKeyState(VK_SLOWMOVE) == KEY_HOLD) 
	{
		setGraphicSlow;
	} 
	else 
	{
		SetCollisionA(GetX, GetY, 16);
		setGraphicFast;
	}
	if(num==0 || num==1 || num==-1 || num== 2 || num==-2)
	{
	VanishEnemy;
	}
	yield;
	}

	@DrawLoop 
	{
	DrawGraphic(GetX, GetY);
	}

    @Finalize {
}

sub setGraphicFast { SetGraphicRect( 0,  0, 48, 48); }
sub setGraphicSlow { SetGraphicRect( 0, 48, 48, 96); }

#include_function ".\data.h.txt"
}