#e
#Title[uŖ̒-Hardv]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "uŖ̒-Hardv";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_mystia.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
    let imgBlind  = csd ~ "..\img\blind.png";
    let imgBG  = csd ~ "..\img\st2bg1.png";
SetRateScoreSystemEnable(false);
    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;

	#include_function ".\..\txt\SpellCardBonusDefine.txt"
	let SpellTimer=50;

	let bgx=0;
	let bgy=0;
    @Initialize {
	SetShotAutoDeleteClip(32,32,32,32);
    LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(21);
        SetLife(800);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        LoadGraphic(imgBlind);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;
	bgx-=1;
	bgy-=1;
    }

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

    @Finalize {
        DeleteGraphic(imgBoss);
	EndSpellHistory(21);
	loop(15)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(bgx,bgy,1280,960);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
	}

    // C^XN
task TMain 
{
	standBy;
	spell;
	Trate;
	Shot;
	Blind;
}

task Trate
{
	while(OnBomb==true){yield;}
	wait(120);
        SetDamageRate(25, 25);
}


sub standBy//ʒu
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

sub spell//[V
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(SpellTimer);
        SetScore(SpellBonus);
	SetAction(ACT_SPELL,90);
	wait(90);
}

task Blind
{
		let x=GetPlayerX;
		let y=GetPlayerY;
		let scax=22;
		let scay=22;
		let angle=180;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBlind);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexUV(obj, 0,    0,    0);
		ObjEffect_SetVertexUV(obj, 1,    0,  448);
		ObjEffect_SetVertexUV(obj, 2,  384,    0);
		ObjEffect_SetVertexUV(obj, 3,  384,  448);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1, -192,  224);
		ObjEffect_SetVertexXY(obj, 2,  192, -224);
		ObjEffect_SetVertexXY(obj, 3,  192,  224);

		ObjEffect_SetLayer(obj,5);
		ObjEffect_SetRenderState(obj, MULTIPLY);
		ObjEffect_SetScale(obj, scax,scay);

		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
			ObjEffect_SetScale(obj, scax,scay);
			if(scax>=4)
			{
			scax-=0.1;
			scay-=0.1;
			}
			if(scax<4)
			{
				break;
			}
			yield;
		}
		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
			ObjEffect_SetScale(obj, scax,scay);
			scax=5+cos(angle);
			scay=5+cos(angle);
			angle+=2;
			yield;
		}
}

task Shot
{
loop
{
	CreateEnemyFromScript("Familiar", rand(GetClipMinX+30,GetCenterX), GetClipMinY,2,rand(90,110), 0);
	CreateEnemyFromScript("Familiar", rand(GetCenterX,GetClipMaxX-30), GetClipMaxY,2,rand(270,290), 0);
	CreateEnemyFromScript("Familiar", GetClipMinX, rand(GetClipMinY+30,GetCenterY),2,rand(-20,0), 0);
	CreateEnemyFromScript("Familiar", GetClipMaxX,rand(GetCenterY,GetClipMaxY-30),2,rand(160,180), 0);
	wait(180);
	CreateEnemyFromScript("Familiar", rand(GetClipMaxX-30,GetCenterX), GetClipMinY,2,rand(70,90), 0);
	CreateEnemyFromScript("Familiar", rand(GetCenterX,GetClipMinX+30), GetClipMaxY,2,rand(250,270), 0);
	CreateEnemyFromScript("Familiar", GetClipMinX, rand(GetClipMaxY-30,GetCenterY),2,rand(0,20), 0);
	CreateEnemyFromScript("Familiar", GetClipMaxX,rand(GetCenterY,GetClipMinY+30),2,rand(180,200), 0);
	wait(180);
}
}


#include_function ".\..\txt\data.txt"
#include_function ".\..\txt\Spelldata.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
{
loop
{
if(((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5>20)
{
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,30,0,angle-90,0,0.01,1.5,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,30,0,angle+90,0,0.01,1.5,RED21);
		FireShot(1);

		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,40,0,angle-90,0,0.01,1.5,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,40,0,angle+90,0,0.01,1.5,RED21);
		FireShot(1);

		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,50,0,angle-90,0,0.01,1.5,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,0,0,0,0,RED01);
		SetShotDataA(1,50,0,angle+90,0,0.01,1.5,RED21);
		FireShot(1);
}

wait(15);
}
}


    // OtBbN̐ݒ
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
function wait(w) 
{
    loop(w) { yield; }
}

}