#東方弾幕風
#Title[幽香通常2-Lunatic]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "幽香通常2-Lunatic";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_yuka.png"; 
    let imgFam  = csd ~ "..\img\FlowerShot.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetTimer(40);
        SetLife(2500);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
    }

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

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // メインタスク
task TMain 
{
	standBy;
	wait(180);
	Trate;
	TMove;
	summon;
}


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

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

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

task summon
{
let rangle=rand(0,360);
loop
{
	let dir=rand_int(0,1)*2-1;
	let angle=GetAngleToPlayer;
	ascent(let i in 0..18)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,4,i*20+angle, dir);
	}
	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_Yuka.txt"
}

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\FlowerShot.png";
	let num = GetArgument;
	let angle=GetAngle;
	let speed=GetSpeed;
	let Dangle=0;
	let IniX=GetX;
	let IniY=GetY;

    @Initialize {
        SetLife(40);
	SetDamageRateEx(100,100,50,10);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
        yield;
Dangle+=6;
        SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
	SetGraphicAngle(0,0,Dangle);
	SetGraphicScale(0.8,0.8)
    }

    task TMain {
        yield;
	shot;
	move;
    }

task move
{
	let count1=0;
	let count2=0;
loop
{
		if(GetX<GetClipMinX && count1==0)
		{
			SetAngle(180 - GetAngle);
			count1=1;
    		}
		if(GetX>GetClipMaxX && count1==0)
		{
			SetAngle(180 - GetAngle);
			count1=1;
		}
		if(GetY<GetClipMinY && count2==0)
		{
			SetAngle(360 - GetAngle);
			count2=1;
      	 	}
		if(GetY>GetClipMaxY)
		{
			VanishEnemy;
      	 	}
	yield;
}
}

task shot
{
wait(15);
loop
{
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,0,GetAngle+90,0,0,3,43);
	SetShotDataA(0,30,0,GetAngle+90,0,0.01,3,43);
	FireShot(0);
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,0,GetAngle-90,0,0,3,43);
	SetShotDataA(0,30,0,GetAngle-90,0,0.01,3,43);
	FireShot(0);
	wait(15);
}
}


    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 0, 64, 64); }
function wait(w)
{
loop(w){yield;}
}
}


