// 星さんの基本設定＆関数まとめ

let imgBoss	= GetCurrentScriptDirectory() ~ "\img\mychara.png";
let imgHoutou = GetCurrentScriptDirectory() ~ "\img\effect_circle.png";

//魔方陣
let CC_RED	= 255;
let CC_GREEN	= 255;
let CC_BLUE	= 128;

#include_function ".\lib\common.txt"

// グラフィックの設定
sub setGraphicStop  { SetGraphicRect(  0, 416,  64, 512); }
sub setGraphicRight { SetGraphicRect(128, 416, 192, 512); }
sub setGraphicLeft  { SetGraphicRect( 64, 416, 128, 512); }
sub setGraphicAttack{ SetGraphicRect(192, 416, 256, 512); }

sub setGraphicMove {
	if(GetSpeedX == 0) {
		setGraphicStop;
	} else if(GetSpeedX < 0) {
		setGraphicLeft;
	} else {
		setGraphicRight;
	}
}

sub Draw_Toramaru
{
	if(GetSpeedX == 0) {
		if (ATTACK_FLAG)
		{
			setGraphicAttack;
		}
		else
		{
			setGraphicStop;
		}
	} else if(GetSpeedX < 0) {
		setGraphicLeft;
	} else {
		setGraphicRight;
	}
	
	DrawGraphic(GetX, GetY);
}

// ===========================================================
// 星さん用エフェクト　宝塔使用時 ATTACK_FLAG!=0の時のみ作動
// ===========================================================
task effect_toramaru()
{
	let EYE_SIZE = 2;	//眼？の動く範囲
	
	//初期設定
	let obj=Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj, imgHoutou);
	ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_SetLayer(obj, 3);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexUV(obj, 0, 128, 256);
	ObjEffect_SetVertexUV(obj, 1, 256, 256);
	ObjEffect_SetVertexUV(obj, 2, 256, 384);
	ObjEffect_SetVertexUV(obj, 3, 128, 384);
	ObjEffect_SetVertexXY(obj, 0, -30, -30);
	ObjEffect_SetVertexXY(obj, 1,  30, -30);
	ObjEffect_SetVertexXY(obj, 2,  30,  30);
	ObjEffect_SetVertexXY(obj, 3, -30,  30);

	//一旦消しておく
	ObjEffect_SetScale(obj, 0, 0);

	let base_size = 1;
	let henka_size = 0.01; 
	let t = 0;
	//ずっとループのターン
	loop
	{
		if (ATTACK_FLAG && GetSpeedX == 0) {
			if (t%3 == 0)
			{
				ObjEffect_SetScale(obj, base_size+henka_size, base_size+henka_size);
				Obj_SetPosition(obj, GetX, GetY);
				henka_size = -henka_size;
			}
			t++;
		}
		else
		{
			ObjEffect_SetScale(obj, 0, 0);
		}
		yield;
	}

	Obj_Delete(obj);
}
