#e
#Title[fPʏ2-Easy]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "fPʏ2-Easy";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_eiki.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
SetRateScoreSystemEnable(false);
    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetTimer(40);
        SetLife(3000);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
    }

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


    @DrawLoop {
	DrawBossShadow( imgBoss,150,255,0,255);
	DrawBoss( imgBoss );

    }

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // C^XN
task TMain 
{
	wait(180);
	standBy;
	Trate;
	TMove;
	Shot1;
	Shot3;
}


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

task TMove
{
	loop
	{
	wait(120);
	moveToPlayer(rand(40, 60), rand(-30, 30), 30,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	wait(30);
	}
}

sub standBy//ʒu
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni+60);
	wait(wIni+60);
}

task Shot1
{
let color=164;
let angle=0;
let speed=3;
let rad=[];
rad=[20,40,60,80];
let way=20;
loop
{
	angle=GetAngleToPlayer;
	ascent(let i in 0..6)
	{
		ascent(let j in 0..way)
		{
		//	CreateShot01(GetX,GetY,speed,angle+j*360/way,color,5);
			CreateShot01ToItem(GetX,GetY,speed,angle+j*360/way,color,5);
		}
	wait(10);
	}
	angle=GetAngleToPlayer;
	ascent(let i in 0..6)
	{
		ascent(let j in 0..way)
		{
		//	CreateShot01(GetX,GetY,speed,angle+j*360/way+180/way,color,5);
			CreateShot01ToItem(GetX,GetY,speed,angle+j*360/way+180/way,color,5);
		}
	wait(10);
	}
	wait(30);
}
}

task Shot3
{
	CreateEnemyFromScript("Familiar", GetX,GetY,0,0,200);
	CreateEnemyFromScript("Familiar", GetX,GetY,1,0,200);
}

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 ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Eiki.txt"
}

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let angle=GetAngle;
	let star=GetSpeed;
	let x=[];
	let y=[];
	let x=[GetX-120,GetX+120,GetX-80,GetX-70,GetX+0,GetX+70,GetX+150];
	let y=[GetY+50,GetY+50,GetY-45,GetY+20,GetY+60,GetY+90,GetY+70];
    @Initialize {
        SetLife(100);
	SetDamageRateEx(100,100,50,10);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
	SetGraphicAngle(0,0,angle);
	SetGraphicScale(0.8,0.8)
    }

    task TMain {
        yield;
	shot;
	move;
    }

task move
{
	SetMovePositionHermite(x[star],y[star],100,0,100,0,60)
}

task shot
{
LshotFire;
wait(60);
let color=0;
if(star==0)
{
color=153;
}
if(star==1)
{
color=158;
}
let way=20;
loop
{
let angle=rand(0,360);
	ascent(let i in 0..way)
	{
		CreateLaserA(0,GetX,GetY,500,30,color,60);		
		SetLaserDataA(0,0,angle+360/way*i,0,0,0,0);
		SetShotKillTime(0,180);
		FireShot(0);
	}
wait(240);
}
wait(60);
VanishEnemy;
}

task LshotFire
{
let t=0;
if(star==0)
{
t=41;
}
if(star==1)
{
t=46;
}
loop
{
	Lshot(GetX,GetY,t);
	wait(3);
}
}

task Lshot(x,y,color)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	//Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, color);
	ObjShot_SetDelay(obj, 5);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,150);
	ObjShot_SetBombResist(obj,true);
	loop(5)
	{
		ObjShot_SetDelay(obj, 3);
		yield;
	}
	Obj_Delete(obj);
}

function wait(w)
{
loop(w){yield;}
}
}
