#東方弾幕風
#Title[ミスティア通常2]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "ミスティア通常2";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_mystia.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(3200);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
    }

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

    @DrawLoop {
        DrawGraphic(GetX, GetY);
	DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // メインタスク
task TMain 
{
	yield;
	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
{
	playershot(GREEN01,1,1);
	wait(30);
	playershot(BLUE01,-1,2);
	wait(90);
}
}

task playershot(let color,let dir,let speed)
{
let angle=rand(0,360);
ascent(let j in 0..12)
{
	ascent(let i in 0..5)
	{
	CreateShotA(0,GetX,GetY,5);
	SetShotDataA(0,0,speed+i,angle+j*30*dir,0,0,0,color);
	SetShotDataA(0,20,0,angle+j*30*dir,0,0,0,color);
	SetShotDataA(0,180,2,angle+j*30*dir,0,0.04,8,color);
	FireShot(0);
	CreateShotA(1,GetX,GetY,5);
	SetShotDataA(1,0,speed+i,angle+j*30*dir+3,0,0,0,color);
	SetShotDataA(1,20,0,angle+j*30*dir+3,0,0,0,color);
	SetShotDataA(1,180,2,angle+j*30*dir+3,0,0.04,8,color);
	FireShot(1);
	}
wait(1);
}
}

task subshot
{
loop
{
	CreateEnemyFromScript("Familiar", GetX,GetY,2,180, 0);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,0, 0);
	wait(120);
}
}

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

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let angle=GetAngle;
	let speed=GetSpeed;
    @Initialize {
        SetLife(2000);
        SetScore(10000);
        SetDamageRate(50, 50);
        SetTexture(imgFam);
        setGraphic;
	SetSpeed(speed);
	SetAngle(angle);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    task TMain {
        yield;
	shot;
    }



task shot
{
wait(15);
loop
{
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,GREEN02);
		SetShotDataA(1,30,0,90,0,0.02,5,PURPLE02);
		FireShot(1);
wait(15);
}
}


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

}