
#Title[逃亡]
#Text[] 
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_sunnymilk.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=30;
    @Initialize {
	SetCommonData("NoCollision",true);
	SetX(GetCommonDataDefault("BossX",0));
	SetY(GetCommonDataDefault("BossY",0));
	MagicCircle(false);
       LoadUserShotData(GetCurrentScriptDirectory~".\img\shot_All.txt");
        SetLife(1);
	InitializeAction();
        TMain;
    }

    @MainLoop {
	//SetCollisionA(GetX, GetY, 48);
        yield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @Finalize {
	SetCommonData("NoCollision",false);
    }

    // メインタスク
task TMain 
{
	//Lissajous(0,84,166);
	BossShadowAnimation(imgBoss2,0,0,255,255);
	//SetCommonData("BOSSDEFEAT",true);
	standBy;
}

sub standBy//初期位置へ
{
	FlowerEffect;
	wait(30);
	SetAction(ACT_TURN, 30);
	//SetMovePosition02(GetClipMaxX+128, GetClipMinY+0, wIni);
	descent(i in 0..30)
	{
		SetAlpha(255/30*i);
		BossBlurAlphaRate=i/30;
		yield;
	}
	//VanishEnemy;
}

task FlowerEffect
{
	LoadGraphic(csd ~ "../img/Magic.png");
	loop(30)
	{
		let angle=rand(0,360);
		FireEffect(angle);
		angle=rand(0,360);
		FireEffect(angle);
		wait(1);
	}
	loop(10)
	{
		let angle=rand(0,360);
		FireEffect(angle);
		wait(3);
	}
/*
	let angle=rand(0,360);
	ascent(i in 0..5)
	{
		ascent(j in -12..13)
		{
			FireEffect3(angle+i*72+j*3,2.5-absolute(j)*0.070);
			FireEffect3(angle+i*72+j*3+36,4.5-absolute(j)*0.070*5/3);
		}
	}
*/
	wait(30);
	SetCommonData("YukaVanish",true);
	//wait(150);
	VanishEnemy;
}

task FireEffect(angle)
{
FireEffect2;
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd ~ "../img/Magic.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		let Alpha=255;
		let StandardAlpha=255;
		let R;let G;let B;
		R=255;G=237;B=237;
		ObjEffect_SetLayer(obj,1);
		let X=GetX; let Y=GetY+25;
		Obj_SetPosition(obj,X+30*sin(angle),Y+10*sin(angle));
		let speed=rand(0.5,5.0);
		angle+=rand(-5,5);
		let Scale=rand(0.5,0.5);
		ObjEffect_SetScale(obj,Scale,Scale);
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}
		let Xspeed=0;
		let Yspeed=0;
		loop(30)
		{
			Obj_SetPosition(obj,X+30*cos(angle),Y+10*sin(angle));
			Y-=2;
			angle+=3;
			Alpha-=255/30;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		Obj_Delete(obj);
}

task FireEffect2
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd ~ "../img/Magic.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		let Alpha=255;
		let StandardAlpha=255;
		let R;let G;let B;
		R=255;G=237;B=237;
		ObjEffect_SetLayer(obj,1);
		let X=GetX; let Y=GetY;
		Obj_SetPosition(obj,X,Y);
		let speed=rand(0.5,5.0);
		let Scale=rand(0.5,0.5);
		ObjEffect_SetScale(obj,Scale,Scale);
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}
		let Xspeed=rand(-3,3);
		let Yspeed=rand(-4,4);
		loop(30)
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+Xspeed,Obj_GetY(obj)+Yspeed);
			Alpha-=255/30;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			Yspeed+=0.01;
			yield;
		}
		Obj_Delete(obj);
}

task FireEffect3(angle,speed)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd ~ "../img/Magic.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		let Alpha=200;
		let StandardAlpha=255;
		let R;let G;let B;
		R=253;G=217;B=217;
		ObjEffect_SetLayer(obj,1);
		let X=GetX; let Y=GetY;
		Obj_SetPosition(obj,X,Y);
		//let speed=rand(0.5,5.0);
		let Scale=rand(0.5,0.5);
		ObjEffect_SetScale(obj,Scale,Scale);
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}
		let Bspeed=speed;
		loop(30)
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			Alpha-=200/75;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			speed-=Bspeed/120;
			yield;
		}
		loop(15)
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			speed-=Bspeed/120;
			yield;
		}
		speed=0;
		let angle=rand(0,360);
		loop(120)
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			speed+=0.1;
			Alpha-=0.8;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			Scale-=0.002;
			ObjEffect_SetScale(obj,Scale,Scale);
			yield;
		}
		Obj_Delete(obj);
}


#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Yuka.txt"
}
