#東方弾幕風
#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 {
	GetBossShadowPosition;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(GetX, GetY, 8);
        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(1040);
	SetDamageRateEx(100,100,50,10);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
        yield;
Dangle+=6;
	if(GetLife>1000)
	{
	SetCollisionA(GetX(),GetY(),32);
        SetCollisionB(GetX(),GetY(),4);
	}
    }

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

    task TMain {
        yield;
	shot;
	move;
	eraze;
	Explode(4);
    }

task eraze
{
	wait(600);
	VanishEnemy;
}

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;
      	 	}

	yield;
}
}

task shot
{
wait(15);
loop
{
	if(GetLife<=1000)
	{
		break;
	}
/*	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);
	CreateShotFromScript( "shot2",GetX, GetY,0, GetAngle-90, 10, 43);
	CreateShotFromScript( "shot2",GetX, GetY,0, GetAngle+90, 10, 43);
*/	ShotYuka2(GetX,GetY,0,0.01,3, GetAngle-90,10,43);
	ShotYuka2(GetX,GetY,0,0.01,3, GetAngle+90,10,43);
	wait(15);
}
}

task ShotYuka2(let x,let y,let Pspeed,let aspeed,let stopspeed,let angle,let delay,let graphic)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, Pspeed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);

	loop(delay)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	loop(30)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	while(!Obj_BeDeleted(obj))
	{
		if(Pspeed<stopspeed)
		{
		Pspeed+=aspeed;
		}
		Obj_SetSpeed(obj, Pspeed);
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}

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

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

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

