#東方弾幕風
#Title[4面中ボス]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "4面中ボス";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_cirno.png"; 
    let imgFam  = csd ~ "img\familiar.png";
	let imgenemyeffect=csd ~ "..\img\effect_circle.png";
	let imgenemy=csd ~ "..\img\shot_all.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetLife(3000);
	SetTimer(35);
        SetDamageRate(5, 5);
	MagicCircle(false);
        LoadGraphic(imgenemyeffect);
        LoadGraphic(imgenemy);
	SetEnemyMarker(true);
        TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
    }

    @Finalize {
    }

    // メインタスク
task TMain 
{
	DrawEnemyEffect;
	DrawEnemyEffect2;
	Trate;
	TMove;
	shot;
}

task DrawEnemyEffect
{	
	let Scale=1.0;
	let angle=0;
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj, imgenemy);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetRenderState(obj, ADD); 
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexXY(obj, 0, -14, -14);
	ObjEffect_SetVertexXY(obj, 1, 14,  -14);
	ObjEffect_SetVertexXY(obj, 2, 14, 14);
	ObjEffect_SetVertexXY(obj, 3,  -14,  14);
		
	ObjEffect_SetVertexUV(obj, 0,  140,  290);
	ObjEffect_SetVertexUV(obj, 1,  167, 290);
	ObjEffect_SetVertexUV(obj, 2, 167,  317);
	ObjEffect_SetVertexUV(obj, 3, 140, 317);
	ObjEffect_SetLayer(obj,5);
	ObjEffect_SetScale(obj, Scale,Scale);
let Alpha=100;

	ObjEffect_SetVertexColor(obj,0,Alpha,255,255,255);
	ObjEffect_SetVertexColor(obj,1,Alpha,255,255,255);
	ObjEffect_SetVertexColor(obj,2,Alpha,255,255,255);
	ObjEffect_SetVertexColor(obj,3,Alpha,255,255,255);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, Scale*(1+0.3*cos(angle)),Scale*(1+0.3*cos(angle)));
		//angle+=6;
		yield;
	}
	Obj_Delete(obj);
}


task DrawEnemyEffect2
{
	let Scale=1.5;
	let angle=0;
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj, imgenemy);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetRenderState(obj, ADD); 
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexXY(obj, 0, -16, -16);
	ObjEffect_SetVertexXY(obj, 1, 16,  -16);
	ObjEffect_SetVertexXY(obj, 2, 16, 16);
	ObjEffect_SetVertexXY(obj, 3,  -16,  16);
		
	ObjEffect_SetVertexUV(obj, 0,  466,  302);
	ObjEffect_SetVertexUV(obj, 1,  495, 302);
	ObjEffect_SetVertexUV(obj, 2, 495,  331);
	ObjEffect_SetVertexUV(obj, 3, 466, 331);
	ObjEffect_SetLayer(obj,6);
	ObjEffect_SetScale(obj, Scale,Scale);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, Scale*(1+0.2*cos(angle)),Scale*(1+0.2*cos(angle)));
		angle+=6;
		yield;
	}
	Obj_Delete(obj);
}


task Trate
{
	wait(120);
        SetDamageRate(100, 100);
}

task TMove
{
let r=400;
let angle=0;
	loop(200)
	{
		SetX(GetCenterX+r*cos(angle));
		SetY(GetCenterY-100+r*sin(angle));
		r-=2;
		angle+=3;
		yield;
	}
	wait(60);
	loop(120)
	{
		SetX(GetCenterX+r*cos(angle));
		SetY(GetCenterY-100+r/2*sin(angle));
		r+=1;
		angle+=2;
		yield;
	}
	loop(120)
	{
		SetX(GetCenterX+r*cos(angle));
		SetY(GetCenterY-100+r/2*sin(angle));
		angle+=2;
		yield;
	}
	loop(120)
	{
		SetX(GetCenterX+r*cos(angle));
		SetY(GetCenterY-100+r/2*sin(angle));
		r-=1;
		angle+=2;
		yield;
	}
	wait(60);
	SetMovePosition02(GetCenterX+150, GetCenterY-150, 60);
	wait(60);
	SetMovePosition02(GetCenterX+150, GetCenterY-50, 60);
	wait(60);
	SetMovePosition02(GetCenterX-150, GetCenterY-150, 120);
	wait(120);
	SetMovePosition02(GetCenterX-150, GetCenterY-50, 60);
	wait(60);
	SetMovePosition02(GetCenterX+150, GetCenterY-100, 120);
	wait(120);
	SetMovePosition02(GetCenterX+150, GetCenterY-50, 60);
	wait(60);
	SetMovePosition02(GetCenterX, GetCenterY-100, 60);
	wait(240);
	loop(120)
	{
		SetX(GetCenterX+r*cos(angle));
		SetY(GetCenterY-100+r/2*sin(angle));
		r+=1.5;
		angle+=3;
		yield;
	}
	loop(120)
	{
		SetX(GetCenterX+r*cos(angle));
		SetY(GetCenterY-100+r/2*sin(angle));
		angle+=3;
		yield;
	}
	loop(120)
	{
		SetX(GetCenterX+r*cos(angle));
		SetY(GetCenterY-100+r/2*sin(angle));
		r-=1.5;
		angle+=3;
		yield;
	}
	wait(120);
	ItemSet(GetX,GetY,4);
	wait(120);
	SetMovePosition02(GetCenterX+300, GetCenterY-150, 60);
	wait(60);
	VanishEnemy;
}


task shot
{
wait(260);
loop(36)
{
	let rangle=rand(0,360);
	ascent(let i in 0..36)
	{
	//	CreateShot01(GetX,GetY,3,i*10+rangle,YELLOW01,10);
		CreateShotFromScript( "shot1",GetX, GetY, 3, i*10+rangle, 10, YELLOW01);
	}
	wait(10);
}
wait(60);
loop(25)
{
let rangle=rand(-10,10);
	ascent(let i in 0..7)
	{
		rfshot(GetX,GetY,2,225+15*i+rangle,124,10);
	}
	wait(15);
}
wait(280);
loop(36)
{
	let rangle=rand(0,360);
	ascent(let i in 0..18)
	{
	//	CreateShot01(GetX,GetY,3.0,i*20+rangle,YELLOW01,10);
	//	CreateShot01(GetX,GetY,2.0,i*20+rangle,YELLOW01,10);
		CreateShotFromScript( "shot1",GetX, GetY, 3, i*20+rangle, 10, YELLOW01);
		CreateShotFromScript( "shot1",GetX, GetY, 2, i*20+rangle, 10, YELLOW01);
	}
	wait(10);
}
}

task rfshot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	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;
	}
	while(!Obj_BeDeleted(obj))
	{
		if(Obj_GetX(obj)<GetClipMinX)//左端での挙動
		{
			Obj_SetX(obj, GetClipMinX*2 - Obj_GetX(obj));
			Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
	      	}
		if(Obj_GetX(obj)>GetClipMaxX)//右端での挙動
		{
			Obj_SetX(obj, GetClipMaxX*2 - Obj_GetX(obj));
			Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
		}
		if(Obj_GetY(obj)<GetClipMinY)//上端での挙動
		{
			Obj_SetY(obj, GetClipMinY*2 - Obj_GetY(obj));
			Obj_SetAngle(obj, 360 - Obj_GetAngle(obj));
        	}
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
    	}
	CreateShotChengeToItem(itemx,itemy);
}

#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Patchouli.txt"
}
#include_script ".\..\txt/EnemyShotData.txt"