#東方弾幕風
#Title[リグル通常1]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "リグル通常1";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_wriggle.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    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);
        LoadGraphic(imgFam);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
    }

    @MainLoop {
	GetBossShadowPosition;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(GetX, GetY, 8);
        yield;
    }

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // メインタスク
task TMain 
{
	standBy;
	Trate;
	TMove;
	shot;
	subshot;
}


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

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

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni+60);
	wait(wIni+60);
}

task shot
{
loop
{
	ascent(let i in 0..36)
	{
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer+i*10,44,30);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer+i*10, 30, 44);
		CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer+i*10,44,30);
	}
	wait(60);
}
}


task subshot
{
loop
{
	CreateEnemyFromScript("Familiar", GetX,GetY,2,0, 0);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,30, 0);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,60, 0);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,90, 0);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,120, 0);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,150, 0);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,180, 0);
	wait(240);
}
}

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_Patchouli.txt"
}

#include_script ".\..\txt/EnemyShotData.txt"

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let angle=GetAngle;
	let speed=GetSpeed;
    @Initialize {
	setGraphicFast;
        SetLife(80);
        SetTexture(imgFam);
	SetSpeed(speed);
	SetAngle(angle);
	SetDamageRateEx(100,100,50,50);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    task TMain {
        yield;
	shot;
	coll;
	Tspeed;
	eraze;
    }

task Tspeed
{
loop(80)
{
	SetSpeed(speed);
	speed-=0.02;
yield;
}
}

task coll
{
let  count=GetCommonDataDefault("famcount",0);
loop
{
if(GetKeyState(VK_SLOWMOVE) == KEY_HOLD && count<=9)
{
	count++;
}
else if(count>=1)
{
count--;
}
if(count==10)
{
        setGraphicSlow;
}
if(count==0)
{
        SetCollisionA(GetX, GetY, 32);
        setGraphicFast;
}
GetCommonData("famcount");
yield;
SetCommonData("famcount",count);
}
}

task shot
{
wait(150);
loop(20)
{
//	CreateShot01(GetX,GetY,rand(1,2),rand(0,360),YELLOW01,30);
//		CreateShotFromScript( "shot1",GetX, GetY, rand(1,2), rand(0,360), 30, YELLOW01);
	CreateShot01ToItem(GetX,GetY,rand(1,2),rand(0,360),YELLOW01,30);
wait(10);
}
VanishEnemy;
}

task eraze
{
loop
{
	if(GetX<=GetClipMinX-64 || GetX>=GetClipMaxX+64 || GetY<=GetClipMinY-64 || GetY>=GetClipMaxY+64)
	{
		VanishEnemy;
	}
yield;
}
}

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

#include_function ".\..\txt/StageEnemydata.txt"

}