#東方弾幕風
#Title[ミスティア通常3Hard]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "ミスティア通常3Hard";
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(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,0,0);
	DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // メインタスク
task TMain 
{
	standBy;
	wait(180);
	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(180);
	}
}

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

task shot
{
loop
{
let angle=rand(0,360);
	playershot(GREEN01,1,1,angle);
	wait(30);
	playershot(BLUE01,-1,2,angle+10);
	wait(210);
}
}

task playershot(let color,let dir,let speed,angle)
{
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,120,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+2,0,0,0,color);
	SetShotDataA(1,20,0,angle+j*30*dir+2,0,0,0,color);
	SetShotDataA(1,120,2,angle+j*30*dir+2,0,0.04,8,color);
	FireShot(1);
	CreateShotA(2,GetX,GetY,5);
	SetShotDataA(2,0,speed+i,angle+j*30*dir+4,0,0,0,color);
	SetShotDataA(2,20,0,angle+j*30*dir+4,0,0,0,color);
	SetShotDataA(2,120,2,angle+j*30*dir+4,0,0.04,8,color);
	FireShot(2);
	CreateShotA(3,GetX,GetY,5);
	SetShotDataA(3,0,speed+i,angle+j*30*dir+6,0,0,0,color);
	SetShotDataA(3,20,0,angle+j*30*dir+6,0,0,0,color);
	SetShotDataA(3,120,2,angle+j*30*dir+6,0,0.04,8,color);
	FireShot(3);
*/	ShotMis3(GetX,GetY,speed+i,2,0.04,angle+j*30*dir,5,color);
	ShotMis3(GetX,GetY,speed+i,2,0.04,angle+j*30*dir+2,5,color);
	ShotMis3(GetX,GetY,speed+i,2,0.04,angle+j*30*dir+4,5,color);
	ShotMis3(GetX,GetY,speed+i,2,0.04,angle+j*30*dir+6,5,color);
	}
wait(1);
}
}

task ShotMis3(let x,let y,let Pspeed,let speed,let aspeed,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(20)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, 0);
	loop(100)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, speed);
	while(!Obj_BeDeleted(obj))
	{
		speed+=aspeed;
		Obj_SetSpeed(obj, speed);
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}

task subshot
{
loop
{
	wait(180);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,GetAngleToPlayer, 0);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,GetAngleToPlayer+20, 0);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,GetAngleToPlayer-20, 0);

}
}

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
{
if(((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5>30)
{
/*		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,ORANGE02);
		SetShotDataA(1,120,0,0,0,0,0,PURPLE02);
		SetShotKillTime(1,180);
		FireShot(1);
*/		ShotMis3(GetX,GetY,30,ORANGE02,PURPLE02);
}
wait(15);
}
}

task ShotMis3(let x,let y,let delay,let graphic,let graphic2)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	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(120)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	ObjShot_SetGraphic(obj, graphic2);
	loop(60)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_Delete(obj);
}

    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\..\txt/StageEnemydata.txt"

}