#東方弾幕風[Stage]
#ScriptVersion[3]
#Title["ステージスタート"]
#Text["ステージスタート"]
#System["./System.txt"]
#Player["./player/player.txt"]

let csd = GetCurrentScriptDirectory();
let StageProgress=0;

let BGMStop=false;

#include"./txt/Menu.txt"
#include"./txt/MenuDraw.txt"
#include"./txt/Info.txt"
#include"script/default_system/Default_ShotConst.txt"

let Move_Up=0;
let Move_Down=0;
let Move_Right=0;
let Move_Left=0;


let EnemyArray=[];

let TreasureArray=[];

let ForbidDrop=false;

let StageBonusExp=0;
let StageBonusMoney=0;
let StageBonusMana=0;
let StageTime=0;
let StageTimeBorder=0;

let StageTreasure=[];

let StageGrade=0;

let EnemyKill=0;
let EnemyInstantKill=0;
let EnemyCombo=0;
let EnemySurviiveTime=0;

let EnemyEmptyTime=0;

let StageEnd=false;

@Initialize
{	
SetForbidPlayerShot(true);
SetForbidPlayerSpell(true);
LoadCommonDataAreaA1("");

SetCommonData("Title",true);

Obj_PlayBGM(GetCurrentScriptDirectory~"bgm/title.wav");

/*
SetCommonData("Status_ExperiencePoint",0);

SetCommonData("Shot_Key","マジックショット");
SetCommonData("Bomb_Key","マジックナパーム");
SetCommonData("User1_Key","エキスパンドレンジ");
SetCommonData("User2_Key","ダッシュ");

SetCommonData("SkillType_All",["マジックショット","マジックナパーム","エキスパンドレンジ","ダッシュ"]);
SetCommonData("SkillType_Attack",["マジックショット","マジックナパーム"]);
SetCommonData("SkillType_Enchant",["エキスパンドレンジ","ダッシュ"]);
SetCommonData("SkillType_Spell",["魔符｢スターダストレヴァリエ｣"]);

SetCommonData("Equip1","普通の箒");
SetCommonData("Equip2","ミニ八卦路（故障中）");
SetCommonData("Equip3","----------");
SetCommonData("Equip4","----------");
*/

	SetStgFrame(32, 16, 416+64, 464,20,80);
	SetPlayerClip(44, 32, 404, 448-48);
	SetEndSceneScriptPath(csd~"./EndScene.txt");
	SetPauseScriptPath(csd~"./Pause.txt");
	GameOverCheck;
	StageIntialize;
}

task GameOverCheck
{
while(GetPlayerLife>=0){yield;}
BGMStop=true;
wait(120);
DrawBack;
DrawGameOver;
GameOverMenu;

BGMStop=false;
Obj_PlayBGM(GetMainStgScriptDirectory~"bgm/gameover.wav");

	task GameOverMenu
	{
	let GOM_Select=0;
	loop
	{
		if(GetVirtualKeyState(VK_UP)==KEY_PUSH || GetVirtualKeyState(VK_DOWN)==KEY_PUSH)
		{
			Obj_PlaySE(SE_SelectMove);
			GOM_Select+=1;
		}
		if(GetVirtualKeyState(VK_SHOT)==KEY_PUSH)
		{
			Obj_PlaySE(SE_Decide);
			if(GOM_Select%2==0)
			{
				SetCommonData("GameOverFlag","Retry");
				CloseStgScene();
			}
			else
			{
				SetCommonData("GameOverFlag","End");
				CloseStgScene();
			}
		}
		if(GOM_Select%2==0)
		{
		DrawText("タイトルに戻る", 224-70, 300,20,255,[]);
		}
		else
		{
		DrawText("タイトルに戻る", 224-70, 300,20,150,[]);
		}
		if(GOM_Select%2==1)
		{
		DrawText("ゲーム終了", 224-50, 350,20,255,[]);
		}
		else
		{
		DrawText("ゲーム終了", 224-50, 350,20,150,[]);
		}
		yield;
	}
	}

	task DrawBack
	{
	let imgBer = GetCurrentScriptDirectory() ~ "img/system2.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	//ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,79);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, 0, 0, 0);
	ObjPrim_SetVertexPosition(obj, 1, 448,0, 0);
	ObjPrim_SetVertexPosition(obj, 2, 448, 448, 0);
	ObjPrim_SetVertexPosition(obj, 3, 0, 448, 0);

	ObjPrim_SetVertexUVT(obj, 0, 32, 16);
	ObjPrim_SetVertexUVT(obj, 1, 480, 16);
	ObjPrim_SetVertexUVT(obj, 2, 480, 464);
	ObjPrim_SetVertexUVT(obj, 3, 32, 464);


	let alpha=0;
	loop(120)
	{
	alpha+=200/60;
	ObjRender_SetAlpha(obj, alpha);
	yield;
	}

	}

	task DrawGameOver
	{
	let imgBer = GetCurrentScriptDirectory() ~ "img/system_r.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	//ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,79);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, 0, 0, 0);
	ObjPrim_SetVertexPosition(obj, 1, 448,0, 0);
	ObjPrim_SetVertexPosition(obj, 2, 448, 448, 0);
	ObjPrim_SetVertexPosition(obj, 3, 0, 448, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 448, 0);
	ObjPrim_SetVertexUVT(obj, 2, 448, 448);
	ObjPrim_SetVertexUVT(obj, 3, 0, 448);


	let alpha=0;
	loop(120)
	{
	alpha+=200/60;
	ObjRender_SetAlpha(obj, alpha);
	yield;
	}

	}

}

let GetGapFocusY=64*0;
@MainLoop
{
	//Set2DCameraFocusY(224+GetGapFocusY);
	yield;
}

@Finalize
{
	//SaveCommonDataAreaA1("");
}

sub StageIntialize
{

	StageTask();
}

		task StageTask
		{
			yield;
SkillTakeCheck;
			StageTitleDisplay;

			yield;

			TStage;

		}

sub StageTitleDisplay//メニュー画面の表示、SecretSpell部分でも呼び出して再起している。
{
	//CreateCommonDataArea("Title");
	yield;
	//LoadCommonDataAreaA1("Title");

	yield;

	//	PlayMusic(BGM[0]);
	//	LoadMenufile;
	//	TitleEffect;
		loop
		{
			alternative(StageState)	
			case(Menu)
			{
				TASK_MENU;
				MenuDraw;
		 	}
			case(Exit)
			{//メニュー画面で設定した値の保存

				break;
		 	}
			others{}
		yield;
		}
		SceneChangeEffect;
		BGMStop=true;
		wait(58);
		BGMStop=false;
		Obj_PlayBGM(GetCurrentScriptDirectory~"bgm/stage.wav");
		SetCommonData("Title",false);
		SetForbidPlayerShot(false);
		SetForbidPlayerSpell(false);
}



let StagePlayerX=0;
let StagePlayerY=50;
let StageObjectArray=[];
let StageRow=16;
let StageColumn=33;

let SceneChange=false;
SetCommonData("SceneChange",false);
let SceneNum=0;
let SceneNumMax=300;

task TStage
{
	DrawField;
	SetCommonData("SkillFlag",0);
	SetCommonData("EquipFlag",0);
	SetCommonData("PauseFlag",0);
	SetCommonData("SaveFlag",0);
	TimeCheck;
	alternative(DrawStage)
	case("魔法の森")
	{
		alternative(ScenePage)
		case(0)
		{
			alternative(SceneSelect)
			case(0)
			{
				#include"./stage/Stage1.txt"
			}
		}
		case(1)
		{
			alternative(SceneSelect)
			case(0)
			{
				#include"./stage/Stage2.txt"
			}
		}
		case(2)
		{
			alternative(SceneSelect)
			case(0)
			{
				#include"./stage/Stage3.txt"
			}
		}
	}
	wait(30);
	StageClearEffect;
	wait(180);
	StageResult;
	KeyWait;
	CloseStgScene();
}

task DrawField
{
	let path = GetCurrentScriptDirectory() ~ "img/plain.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.2);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 448, 448);
	ObjRender_SetPosition(obj,224,224*0+Get2DCameraY,0);
	Obj_SetRenderPriorityI(obj,20);
	ObjSprite2D_SetDestCenter(obj);
	loop
	{
	//	DrawText(IntToString(GetCommonData("SaveFlag",0)), 264, 330,20,255,[]);
/*
		let T=GetCommonData("魔法の森",[[1],[0],[0]]);
		let H=T[1];
		H[0]=1;
		T[1]=H;
		DrawText(T[1][0],4, 70,20,255,[]);
*/
	//	DrawText(StagePlayerX, 224-70, 300,20,150,[]);
	//	DrawText(StagePlayerY, 224-70, 350,20,150,[]);
/*
	DrawText(EnemyEmptyTime, 224-70, 400,20,150,[]);
	DrawText(EnemySurviiveTime, 224-70, 350,20,150,[]);
	DrawText(EnemyKill, 224-70, 250,20,150,[]);
	DrawText(EnemyCombo, 224-70, 300,20,150,[]);
*/
//	DrawText(SceneSelect, 224-70, 200,20,150,[]);
//	DrawText(ScenePage, 224-70, 230,20,150,[]);
	if(length(EnemyArray)==0 && GetCommonData("SceneChange",false)==false)
	{
	EnemyEmptyTime+=1;
	}
	ObjSprite2D_SetSourceRect(obj, 0+StagePlayerX, 0+StagePlayerY, 448+StagePlayerX, 448+StagePlayerY);
	yield;
	}
}

task TimeCheck
{
loop
{
wait(60);
StageTime+=1;
}
}

function KeyWait
{
wait(60);
loop
{
	
	if(GetKeyState(VK_SHOT) == KEY_PUSH)
	{
		break;
	}
	DrawText("Push Shot Key", 448-15*10, 420,20,255,[]);
	yield;
}

DrawEnd;
wait(60);
	task DrawEnd
	{
	let imgBer = GetCurrentScriptDirectory() ~ "img/system2.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	//ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,100);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, 32, 16, 0);
	ObjPrim_SetVertexPosition(obj, 1, 480,16, 0);
	ObjPrim_SetVertexPosition(obj, 2, 480, 464, 0);
	ObjPrim_SetVertexPosition(obj, 3, 32, 464, 0);

	ObjPrim_SetVertexUVT(obj, 0, 32, 16);
	ObjPrim_SetVertexUVT(obj, 1, 480, 16);
	ObjPrim_SetVertexUVT(obj, 2, 480, 464);
	ObjPrim_SetVertexUVT(obj, 3, 32, 464);


	let alpha=0;
	loop(30)
	{
	alpha+=255/30;
	ObjRender_SetAlpha(obj, alpha);
	yield;
	}
	}

}

task StageResult
{
	BGMStop=true;
	if(GetCommonData("PlayerBreakFlag",0)==0)
	{
		StageGrade+=16;
	}
	else
	{
		StageGrade-=GetCommonData("PlayerBreakFlag",0)*2;
	}
	if(GetCommonData("PlayerMissFlag",0)==0)
	{
		StageGrade+=8;
	}
	else
	{
		StageGrade-=GetCommonData("PlayerMissFlag",0)*4;
	}
	if(GetCommonData("PauseFlag",0)==0)
	{
		StageGrade+=4;
	}
	else
	{
		StageGrade-=GetCommonData("PauseFlag",0)/2;
	}
	if(GetCommonData("EquipFlag",0)==0)
	{
		StageGrade+=2;
	}
	else
	{
		StageGrade-=GetCommonData("EquipFlag",0)*2;
	}
	if(GetCommonData("SkillFlag",0)==0)
	{
		StageGrade+=1;
	}
	else
	{
		StageGrade-=GetCommonData("SkillFlag",0);
	}
	if(GetCommonData("SaveFlag",0)==0)
	{
		StageGrade+=1;
	}
	else
	{
		StageGrade-=GetCommonData("SaveFlag",0)*32;
	}

	StageGrade+=floor(EnemyCombo/64);
	StageGrade+=floor(EnemyKill/8);
	StageGrade+=floor(EnemyInstantKill/4);

	StageGrade-=floor(EnemySurviiveTime/2400);
	StageGrade-=SetCommonData("PointLackFlag",0)/2;
	StageGrade-=floor(EnemyEmptyTime/600);
	if(StageGrade<0){StageGrade=0;}

	if(StageTimeBorder-StageTime>0)
	{
	StageBonusMoney*=(StageTimeBorder-StageTime)/StageTimeBorder*2+1;
	StageGrade+=(StageTimeBorder-StageTime)/StageTimeBorder*16;
	}

	StageBonusExp*=1+StageGrade/32;
	StageBonusMoney*=1+StageGrade/64;

	let ManaGrade=floor(EnemyKill/4)+EnemyInstantKill;
	StageBonusMana*=1+(StageGrade+ManaGrade)/64;
/*
	StageTreasure=StageTreasure~[["プロテクトリング"]];
	StageTreasure=StageTreasure~[["デュランダル"]];
	StageTreasure=StageTreasure~[["マジカルブルーム"]];
	StageTreasure=StageTreasure~[["ウィザードブルーム"]];
	StageTreasure=StageTreasure~[["エメラルドリング"]];
*/
	let EquipAll=GetCommonData("Equip_All",[["----------"]]);

	ascent(i in 0..length(StageTreasure))
	{
	if(UniqueItemJudg(StageTreasure[i][0]))
	{

	}
	else
	{
	let SlotNum=SlotNumDefine(StageGrade);
	loop(SlotNum)
	{
		let SlotLevel=SlotLevelDefine(StageGrade);
		let SlotKind=SlotKindDefine;
		let AddSlot=SlotLevel~"_"~SlotKind;
		StageTreasure[i]=StageTreasure[i]~[AddSlot];
	}
	}

	}

	ascent(i in 0..length(StageTreasure))
	{
	EquipAll=EquipAll~[StageTreasure[i]];
	}

	SetCommonData("Exp",GetCommonData("Exp",0)+StageBonusExp);
	SetCommonData("Yen",GetCommonData("Yen",0)+StageBonusMoney);
	SetCommonData("Mana",GetCommonData("Mana",0)+StageBonusMana);
	SetCommonData("Equip_All",EquipAll);

	DrawBack;
	DrawLetter;
	task DrawLetter
	{
	loop
	{
		DrawText("Bonus Exp", 224-160, 70,20,255,[]);
		DrawText("Bonus Money", 224-160, 120,20,255,[]);
		DrawText("Bonus Mana", 224-160, 170,20,255,[]);

		DrawText(IntToString(StageBonusExp), 304, 70,20,255,[]);
		DrawText(IntToString(StageBonusMoney), 304, 120,20,255,[]);
		DrawText(IntToString(StageBonusMana), 304, 170,20,255,[]);

		DrawText("GetTreasure", 224-55, 234,20,255,[]);

		ascent(i in 0..length(StageTreasure))
		{
		DrawText(StageTreasure[i][0], 224-10*length(StageTreasure[i][0])/2, 274+25*i,20,255,[]);
		}
	//	DrawText(IntToString(StageGrade), 264, 300,20,255,[]);
		//DrawText(IntToString(GetCommonData("SaveFlag",0)), 264, 330,20,255,[]);
	yield;
	}
	}

	task DrawBack
	{
	let imgBer = GetCurrentScriptDirectory() ~ "img/system2.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	//ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,79);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, 0, 0, 0);
	ObjPrim_SetVertexPosition(obj, 1, 448,0, 0);
	ObjPrim_SetVertexPosition(obj, 2, 448, 448, 0);
	ObjPrim_SetVertexPosition(obj, 3, 0, 448, 0);

	ObjPrim_SetVertexUVT(obj, 0, 32, 16);
	ObjPrim_SetVertexUVT(obj, 1, 480, 16);
	ObjPrim_SetVertexUVT(obj, 2, 480, 464);
	ObjPrim_SetVertexUVT(obj, 3, 32, 464);


	let alpha=0;
	loop(30)
	{
	alpha+=150/30;
	ObjRender_SetAlpha(obj, alpha);
	yield;
	}
	}
}

function SlotNumDefine(Grade)
{
	let num=GetCommonData("Sum_Luck",0);
	alternative(GetCommonData("StageName",""))
	case("魔法の森"){num+=100;}
	others{}

	alternative(GetCommonData("SceneSelect",""))
	case("0"){num+=0}
	others{}

	alternative(GetCommonData("ScenePage",""))
	case("1"){num+=0}
	others{}

	num*=1+Grade/64;
	if(num>=rand(0,1000))
	{
		if(num>=rand(0,10000) && num>=100)
		{
			if(num>=rand(0,100000) && num>=1000)
			{
				return(3);
			}
			else
			{
			return(2);
			}
		}
		else
		{
		return(1);
		}
	}
	else
	{
		return(0);
	}
}

function SlotLevelDefine(Grade)
{
	let num=GetCommonData("Sum_Luck",0);
	alternative(GetCommonData("StageName",""))
	case("魔法の森"){num+=100;}
	others{}

	alternative(GetCommonData("SceneSelect",""))
	case("0"){num+=0}
	others{}

	alternative(GetCommonData("ScenePage",""))
	case("1"){num+=0}
	others{}

	num*=1+Grade/64;
	if(num>=rand(0,1000))
	{
		if(num>=rand(0,2000) && num>=500)
		{
			if(num>=rand(0,4000) && num>=1000)
			{
				return("4");
			}
			else
			{
			return("3");
			}
		}
		else
		{
		return("2");
		}
	}
	else
	{
		return("1");
	}
}

function SlotKindDefine
{
	let kind=rand_int(1,9);
	
	let K_Str=IntToString(kind);
	if(kind<=9)
	{
		K_Str="0"~K_Str;
	}
	return(K_Str);
}

task StageClearEffect
{
	let Letter="Stage Clear!";
	ascent(i in 0..12)
	{
	DrawLetter(Letter[i],20*i-90);
	wait(5);
	}

	task DrawLetter(text,x)
	{
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	ObjText_SetFontSize(objText, 40);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 196);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 70);
	ObjRender_SetX(objText, GetPlayerX+x);
	ObjRender_SetY(objText, GetPlayerY-10);

	let Scale=1.5;

	ObjRender_SetScaleY(objText,0.9);
	loop(120)
	{
		if(Scale>1.0)
		{
			Scale-=0.5/5;
		}
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetX(objText, 240+x);
		ObjRender_SetY(objText, 224-64);
		yield;
	}
	let alpha=255;
	loop(5)
	{
		Scale+=0.5/5;
		alpha-=255/5;
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetAlpha(objText,alpha);
		ObjRender_SetX(objText, 240+x);
		ObjRender_SetY(objText, 224-64);
		yield;
	}
	Obj_Delete(objText);
	}
}

task SceneChangeEffect
{
	DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
	let AnimeFrame=0;
	let Anime=0;
	let imgBer = GetCurrentScriptDirectory() ~ "img/system2.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	//ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,79);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, 0, 0, 0);
	ObjPrim_SetVertexPosition(obj, 1, 448,0, 0);
	ObjPrim_SetVertexPosition(obj, 2, 448, 448, 0);
	ObjPrim_SetVertexPosition(obj, 3, 0, 448, 0);

	ObjPrim_SetVertexUVT(obj, 0, 32, 16);
	ObjPrim_SetVertexUVT(obj, 1, 480, 16);
	ObjPrim_SetVertexUVT(obj, 2, 480, 464);
	ObjPrim_SetVertexUVT(obj, 3, 32, 464);

	DrawLoading;

	let alpha=255;
	loop(60)
	{
	yield;
	}
	loop(30)
	{
	alpha-=255/30;
	ObjRender_SetAlpha(obj, alpha);
	yield;
	}
	Obj_Delete(obj);

	task DrawLoading
	{
	loop(15)
	{
		DrawText("NowLoading",300, 420,20,255,[]);
		yield;
	}
	loop(15)
	{
		DrawText("NowLoading.",300, 420,20,255,[]);
		yield;
	}
	loop(15)
	{
		DrawText("NowLoading..",300, 420,20,255,[]);
		yield;
	}
	loop(15)
	{
		DrawText("NowLoading...",300, 420,20,255,[]);
		yield;
	}
	}
}

	task DrawText(let text, let mx, let my,size,alpha,color)
	{
		let obj = ObjText_Create();
		ObjText_SetText(obj, text);
		ObjText_SetFontSize(obj, size);
		ObjText_SetFontBold(obj, true);
		ObjText_SetFontColorTop(obj, 196, 196, 255);
		ObjText_SetFontColorBottom(obj, 128, 128, 255);
		ObjText_SetFontBorderType(obj, BORDER_NONE);
		ObjText_SetFontBorderColor(obj,255, 255, 255);
		ObjText_SetFontBorderWidth(obj, 0);
		Obj_SetRenderPriorityI(obj, 80);
		ObjRender_SetX(obj, mx);
		ObjRender_SetY(obj, my);
		ObjText_SetFontType(obj,"ＭＳ 明朝");

	//	ObjText_SetMaxWidth(obj,200);

		if(length(text)>=24)
		{
			ObjRender_SetY(obj, my-8);
		}

		if(length(color)!=0)
		{
		ObjText_SetFontColorTop(obj, (color[0]+255)/2, (color[1]+255)/2,(color[2]+255)/2);
		ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
		}

	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjRender_SetAlpha(obj,alpha);
		yield;

		Obj_Delete(obj);
	}

	task DrawSkillText(let text, let mx, let my,size,alpha,color)
	{
		let obj = ObjText_Create();
		ObjText_SetText(obj, text);
		ObjText_SetFontSize(obj, size);
		ObjText_SetFontBold(obj, true);
		ObjText_SetFontColorTop(obj, 196, 196, 255);
		ObjText_SetFontColorBottom(obj, 128, 128, 255);
		ObjText_SetFontBorderType(obj, BORDER_NONE);
		ObjText_SetFontBorderColor(obj,255, 255, 255);
		ObjText_SetFontBorderWidth(obj, 0);
		Obj_SetRenderPriorityI(obj, 80);
		ObjRender_SetX(obj, mx);
		ObjRender_SetY(obj, my);
		ObjText_SetFontType(obj,"ＭＳ 明朝");

	//	ObjText_SetMaxWidth(obj,200);

		if(length(text)>=24)
		{
	//		ObjRender_SetY(obj, my-8);
		}

		if(length(color)!=0)
		{
		ObjText_SetFontColorTop(obj, (color[0]+255)/2, (color[1]+255)/2,(color[2]+255)/2);
		ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
		}

	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjRender_SetAlpha(obj,alpha);
		yield;

		Obj_Delete(obj);
	}

function SetStage
{

ObjMove_SetX(GetPlayerObjectID,GetStgFrameWidth/2);
ObjMove_SetY(GetPlayerObjectID,224);

if(StagePlayerX<0)
{
	ObjMove_SetX(GetPlayerObjectID,GetStgFrameWidth/2+StagePlayerX);
	StagePlayerX=0;
}

if(StagePlayerX>=StageRow*32-GetStgFrameWidth)
{
	let a=StagePlayerX;
	StagePlayerX=StageRow*32-GetStgFrameWidth;
	ObjMove_SetX(GetPlayerObjectID,GetStgFrameWidth/2+a-(StageRow*32-GetStgFrameWidth));
}

if(StagePlayerY<0)
{
	ObjMove_SetY(GetPlayerObjectID,224+StagePlayerY);
	StagePlayerY=0;
}

if(StagePlayerY>=StageColumn*32-448)
{
	let a=StagePlayerY;
	StagePlayerY=StageColumn*32-448;
	ObjMove_SetY(GetPlayerObjectID,224+a-(StageColumn*32-448));
}

CreateMapTask;

ascent(i in 0..StageRow)
{
ascent(j in 0..StageColumn)
{

CreateMap(i,j,StageObjectElement(i,j));

}

}

}

task StageMainTask
{
while(SceneChange==false)
{
	if(GetPlayerX>=GetStgFrameWidth/2 && StagePlayerX<StageRow*32-GetStgFrameWidth)
	{
		Move_Right=GetPlayerX-GetStgFrameWidth/2;
			Obj_SetValue(GetPlayerObjectID,"Move_Right",GetPlayerX-GetStgFrameWidth/2);
			StagePlayerX+=GetPlayerX-GetStgFrameWidth/2;
			if(StagePlayerX>=StageRow*32-GetStgFrameWidth){StagePlayerX=StageRow*32-GetStgFrameWidth;}
			ObjMove_SetX(GetPlayerObjectID,GetStgFrameWidth/2);
	}
	else
	{
		Move_Right=0;
		Obj_SetValue(GetPlayerObjectID,"Move_Right",0);
	}
	if(GetPlayerX<GetStgFrameWidth/2 && -StagePlayerX<0)
	{
		Move_Left=GetPlayerX-GetStgFrameWidth/2;
			Obj_SetValue(GetPlayerObjectID,"Move_Left",GetPlayerX-GetStgFrameWidth/2);
			StagePlayerX+=GetPlayerX-GetStgFrameWidth/2;
			if(StagePlayerX<0){StagePlayerX=0;}
			ObjMove_SetX(GetPlayerObjectID,GetStgFrameWidth/2);
	}
	else
	{
		Move_Left=0;
		Obj_SetValue(GetPlayerObjectID,"Move_Left",0);
	}
	if(GetPlayerY>=224 && StageColumn*32-StagePlayerY>448)
	{
		Move_Down=GetPlayerY-224;
			Obj_SetValue(GetPlayerObjectID,"Move_Down",GetPlayerY-224);
			StagePlayerY+=GetPlayerY-224;
			if(StagePlayerY>=StageColumn*32-448){StagePlayerY=StageColumn*32-448;}
			ObjMove_SetY(GetPlayerObjectID,224);
	}
	else
	{
		Move_Down=0;
		Obj_SetValue(GetPlayerObjectID,"Move_Down",0);
	}
	if(GetPlayerY<224 && -StagePlayerY<0)
	{
		Move_Up=GetPlayerY-224;
			Obj_SetValue(GetPlayerObjectID,"Move_Up",GetPlayerY-224);
			StagePlayerY+=GetPlayerY-224;
			if(StagePlayerY<0){StagePlayerY=0;}
			ObjMove_SetY(GetPlayerObjectID,224);
	}
	else
	{
		Move_Up=0;
		Obj_SetValue(GetPlayerObjectID,"Move_Up",0);
	}
yield;
}

}

task VictoryConditionEffect
{
	let Letter="全ての敵を倒せ！";
	ascent(i in 0..8)
	{
	DrawLetter(Letter[i*2..i*2+2],32*i-112);
	wait(3);
	}

	task DrawLetter(text,x)
	{
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	ObjText_SetFontSize(objText, 32);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 196, 196);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 70);
	ObjRender_SetX(objText, 224+x);
	ObjRender_SetY(objText, 224-30);

	let Scale=1.5;

	ObjRender_SetScaleY(objText,0.9);
	loop(90)
	{
		if(Scale>1.0)
		{
			Scale-=0.5/5;
		}
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetX(objText, 240+x);
		ObjRender_SetY(objText, 224-64);
		yield;
	}
	let alpha=255;
	loop(5)
	{
		Scale+=0.5/5;
		alpha-=255/5;
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetAlpha(objText,alpha);
		ObjRender_SetX(objText, 240+x);
		ObjRender_SetY(objText, 224-64);
		yield;
	}
	Obj_Delete(objText);
	}
}


task BossVictoryConditionEffect(name)
{
	let Letter=name~"を倒せ！";
	ascent(i in 0..length(Letter)/2)
	{
	DrawLetter(Letter[i*2..i*2+2],32*i-length(Letter)/2*14);
	wait(3);
	}

	task DrawLetter(text,x)
	{
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	ObjText_SetFontSize(objText, 32);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 196, 196);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 70);
	ObjRender_SetX(objText, 224+x);
	ObjRender_SetY(objText, 224-30);

	let Scale=1.5;

	ObjRender_SetScaleY(objText,0.9);
	loop(90)
	{
		if(Scale>1.0)
		{
			Scale-=0.5/5;
		}
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetX(objText, 240+x);
		ObjRender_SetY(objText, 224-64);
		yield;
	}
	let alpha=255;
	loop(5)
	{
		Scale+=0.5/5;
		alpha-=255/5;
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetAlpha(objText,alpha);
		ObjRender_SetX(objText, 240+x);
		ObjRender_SetY(objText, 224-64);
		yield;
	}
	Obj_Delete(objText);
	}
}

function StageObjectElement(x,y)
{
	if((StageRow-1)+StageRow*(StageColumn-1)<x+StageRow*y)
	{
	//	fff;
	//	wait(5);
		return(-100);
	}
	else if(x+StageRow*y<0)
	{
	//	fff2;
	//	wait(5);
		return(-100);
	}
	else
	{
	return(StageObjectArray[x+StageRow*y]);
	}
}

task CreateMapTask
{
//let a=StageObjectElement(StageRow-1,StageColumn-1);
loop
{
	let mx=StagePlayerX+GetPlayerX*0;
	let my=StagePlayerY+GetPlayerY*0;
	let bx=floor((mx-16)/32);
	let by=floor((my-16)/32);
	wait(1);
	mx=StagePlayerX+GetPlayerX*0;
	my=StagePlayerY+GetPlayerY*0;


		if(bx-floor((mx-16)/32)<0)
		{
			ascent(j in by-1..by+17)
			{

				if(StageObjectElement(bx+16,j)!=-100)
				{
					CreateMap(bx+16,j,StageObjectElement(bx+16,j));
				}

			}
		}

		if(bx-floor((mx-16)/32)>0)
		{
			ascent(j in by-1..by+17)
			{

				if(StageObjectElement(bx-1,j)!=-100)
				{
					CreateMap(bx-1,j,StageObjectElement(bx-1,j));
				}

			}
		}

		if(by-floor((my-16)/32)<0)
		{
			ascent(j in bx-1..bx+17)
			{

				if(StageObjectElement(j,by+16)!=-100)
				{
					CreateMap(j,by+16,StageObjectElement(j,by+16));
				}

			}
		}

		if(by-floor((my-16)/32)>0)
		{
			ascent(j in bx-1..bx+17)
			{

				if(StageObjectElement(j,by-1)!=-100)
				{
					CreateMap(j,by-1,StageObjectElement(j,by-1));
				}

			}
		}
}


}

task fff
{
loop(60)
{
	DrawText(10,300, 60,20,255,[]);
	DrawText(10,300, 100,20,255,[]);
yield;
}
}

task fff2
{
loop(60)
{
	DrawText(-10,300, 260,20,255,[]);
	DrawText(-10,300, 300,20,255,[]);
yield;
}
}

task CreateMap(i,j,type)
{
if(type==1){return;}
loop
{
	let objEnemy;
	let imgEnemy;
	alternative(type)
	case(-1)
	{
	objEnemy=SetBlockDummyInfo(i*32+16,j*32+16,100,24,8,1,0);
	imgEnemy=csd ~ "img/Wood.png";
	}
	case(0)
	{
	objEnemy=SetBlockInfo(i*32+16,j*32+16,100,24,8,1,0);
	imgEnemy=csd ~ "img/Wood.png";
	}
	case(1)
	{
	objEnemy=SetMapInfo(i*32+16,j*32+16,100,24,8,1,0);
	imgEnemy=csd ~ "img/Plain.png";
	}
	others
	{
	objEnemy=SetBlockDummyInfo(i*32+16,j*32+16,100,24,8,1,0);
	imgEnemy=csd ~ "img/Wood.png";
	}
	EnemyRenderTask;
	Move;

	function Move
	{
		loop
		{
			ObjMove_SetPosition(objEnemy,i*32+16-StagePlayerX,j*32+16-StagePlayerY);
			if(i*32+16-StagePlayerX<-32){break;}
			if(i*32+16-StagePlayerX>GetStgFrameWidth+32){break;}
			if(j*32+16-StagePlayerY<-32+GetGapFocusY){break;}
			if(j*32+16-StagePlayerY>448+32+GetGapFocusY){break;}
			if(SceneChange==true){break;}
			if(StageObjectArray[i+StageRow*j]!=type){StageObjectArray[i+StageRow*j]=type;break;}
			yield;
		}
	}

	Obj_Delete(objEnemy);
/*
	loop
	{
		if(SceneChange==true){return;}
		if(i*32+16-StagePlayerX>=-32 && i*32+16-StagePlayerX<=GetStgFrameWidth+32 && j*32+16-StagePlayerY>=-32+GetGapFocusY && j*32+16-StagePlayerY<=448+32+GetGapFocusY){break;}
		yield;
	}
*/
	break;
	task EnemyRenderTask
	{
	while(!Obj_IsDeleted(objEnemy))
	{
	ObjPrim_SetTexture(objEnemy,imgEnemy);
	ObjSprite2D_SetSourceRect(objEnemy,0,0,32,32);
	ObjSprite2D_SetDestCenter(objEnemy);
	yield;
	}
	}

}

}

function SetMapInfo(x,y,life,IRA,IRB,FairyColor,FairyType)
{
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	ObjMove_SetPosition(obj, x, y);
	Obj_SetValue(obj, "Vanished", 0);

	ObjEnemy_SetLife(obj, life);
	Obj_SetValue(obj, "IntersectionShot", 16);
	ObjEnemy_Regist(obj);
	Obj_SetRenderPriorityI(obj,20);

	return (obj);
}

function SetBlockDummyInfo(x,y,life,IRA,IRB,FairyColor,FairyType)
{
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	ObjMove_SetPosition(obj, x, y);
	Obj_SetValue(obj, "Vanished", 0);

	ObjEnemy_SetLife(obj, life);
	Obj_SetValue(obj, "IntersectionShot", 16);
	ObjEnemy_Regist(obj);
	Obj_SetRenderPriorityI(obj,20);
//	EnemyMainTask;
	return (obj);

	task EnemyMainTask
	{
	while(!Obj_IsDeleted(obj))
	{
		if(Obj_GetValue(obj, "IntersectionShot")!=0)
		{
			ObjEnemy_SetIntersectionCircleToShot(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),Obj_GetValue(obj, "IntersectionShot"));
		}
		yield;
	}
	}
}

function SetBlockInfo(x,y,life,IRA,IRB,FairyColor,FairyType)
{
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	ObjMove_SetPosition(obj, x-StagePlayerX, y-StagePlayerY);
	Obj_SetValue(obj, "Vanished", 0);

	ObjEnemy_SetLife(obj, life);
	Obj_SetValue(obj, "IntersectionShot", 16);
	ObjEnemy_Regist(obj);
	Obj_SetRenderPriorityI(obj,20);
//if(x==240 && y==208){return(obj);}
	EnemyMainTask;
	return (obj);

	task EnemyMainTask
	{
	function GetGapLength(x1,y1,x2,y2){return((x2-x1)^2+(y2-y1)^2)^0.5;}
	while(!Obj_IsDeleted(obj))
	{

		if(Obj_GetValue(obj, "IntersectionShot")!=0)
		{
			ObjEnemy_SetIntersectionCircleToShot(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),Obj_GetValue(obj, "IntersectionShot"));
		}


			DeleteShotInCircle(TYPE_SHOT,TYPE_IMMEDIATE,ObjMove_GetX(obj),ObjMove_GetY(obj),20);
			if(GetGapLength(ObjMove_GetX(obj),ObjMove_GetY(obj),GetPlayerX,GetPlayerY)<26)
			{
			//	ddd(x,y,ObjRender_GetX(obj),ObjRender_GetY(obj));

				let ag=GetAngleToPlayer(obj)%360;
				let c=28;
				if(ag>315||ag<45)
				{
					ObjMove_SetX(GetPlayerObjectID,ObjMove_GetX(obj)+c);
				}
				if(ag>=45&&ag<=135)
				{
					ObjMove_SetY(GetPlayerObjectID,ObjMove_GetY(obj)+c);
				}
				if(ag>135&&ag<225)
				{
					ObjMove_SetX(GetPlayerObjectID,ObjMove_GetX(obj)-c);
				}
				if(ag>=225&&ag<=315)
				{
					ObjMove_SetY(GetPlayerObjectID,ObjMove_GetY(obj)-c);
				}
			}

/*
			ascent(L in 0..length(EnemyArray))
			{
			if(GetGapLength(ObjRender_GetX(obj),ObjRender_GetY(obj),ObjRender_GetX(EnemyArray[L]),ObjRender_GetY(EnemyArray[L]))<26)
			{
				let ag=atan2(ObjRender_GetY(EnemyArray[L])-ObjRender_GetY(obj),ObjRender_GetX(EnemyArray[L])-ObjRender_GetX(obj))%360;
				let c=28;
				if(ag>315||ag<45)
				{
					Obj_SetValue(EnemyArray[L],"Knock_Right",1);
				}
				if(ag>=45&&ag<=135)
				{
					Obj_SetValue(EnemyArray[L],"Knock_Down",1);
				}
				if(ag>135&&ag<225)
				{
					Obj_SetValue(EnemyArray[L],"Knock_Left",1);
				}
				if(ag>=225&&ag<=315)
				{
					Obj_SetValue(EnemyArray[L],"Knock_Up",1);
				}

			}

			}
*/
		yield;
	}
}

}

task ddd(x,y,ox,oy)
{
loop(15)
{
		DrawText(IntToString(x), 304, 170,20,255,[]);
		DrawText(IntToString(y), 304, 200,20,255,[]);
		DrawText(IntToString(ox), 354, 170,20,255,[]);
		DrawText(IntToString(oy), 354, 200,20,255,[]);
yield;
}
}

function SetEnemyInfo(x,y,life,reduce,cut,C_Resist,IRA,IRB,imgpath)
{
	#include".\lib\lib_anime_fairy.txt"

	//let imgpath = GetCurrentScriptDirectory() ~ "img/v8-fairy01.png";

	let obj = ObjEnemy_Create(OBJ_ENEMY);
//	ObjMove_SetPosition(obj, x-StagePlayerX, y-StagePlayerY);
	Obj_SetValue(obj, "Vanished", 0);
	Obj_SetValue(obj, "Life", life);
	Obj_SetValue(obj, "MaxLife", life);
	Obj_SetValue(obj, "DrawDamage", 0);
	Obj_SetValue(obj, "DrawCount", 0);
	Obj_SetValue(obj, "Defence", reduce);
	Obj_SetValue(obj, "Resist", cut);
	Obj_SetValue(obj, "C_Resist", C_Resist);

	ObjEnemy_SetLife(obj, life*10);
	Obj_SetValue(obj, "IntersectionShot", IRA);
	Obj_SetValue(obj, "IntersectionPlayer", IRB);
	Obj_SetValue(obj,"Appear",0);
	ObjEnemy_Regist(obj);

//	Initialize_Fairy(FairyType);
	EnemyLifeTask(obj);
	EnemyMainTask(obj);
//	EnemyRenderTask(obj,FairyColor);
if(imgpath!="img/takara.png")
{
	TImage;
}
else
{
	TImage2;
}
	EnemyClearTask;
	EnemySurviiveTask;
	return (obj);

task EnemySurviiveTask
{
wait(120);
while(!Obj_IsDeleted(obj))
{
	EnemySurviiveTime+=1;
	yield;
}
}

task EnemyClearTask
{
let alpha=255;
while(!GetCommonData("StageClear",false)){yield;}
loop(60)
{
ObjRender_SetAlpha(obj,alpha);
alpha-=255/60;
yield;
}
Obj_SetValue(obj, "Vanished", 1);
}


task TImage
{
	let CharaDirection=0;
	let OnMove=false;

	ObjPrim_SetTexture(obj, csd~imgpath);
	let imgFrameCount=0;
	let FrameStep=0;

	SetCharaDirection;

	loop
	{
	ObjSprite2D_SetSourceRect(obj, 0+FrameStep*32, CharaDirection*32, 32+FrameStep*32, (1+CharaDirection)*32);
	Obj_SetRenderPriorityI(obj,50);
	ObjSprite2D_SetDestCenter(obj);

	imgFrameCount+=1;
	if(imgFrameCount>=60){imgFrameCount=0;}
	FrameStep=floor(imgFrameCount/15);
	yield;
	}


	task SetCharaDirection
	{
	let Eangle=0;
	loop
	{
		Eangle=((ObjMove_GetAngle(obj)+360+6*360/16)%360);
		CharaDirection=floor((Eangle-360/16)/(360/8));
		yield;
	}
	}
}

task TImage2
{
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	ObjRender_SetScaleXYZ(obj,1.5,1.5,1.5);
	ObjPrim_SetTexture(obj, csd~imgpath);

	loop
	{
	ObjSprite2D_SetSourceRect(obj, 0, 64, 24, 96);
	Obj_SetRenderPriorityI(obj,50);
	ObjSprite2D_SetDestCenter(obj);

	yield;
	}
}

task EnemyRenderTask(obj,FairyColor)
{
while(!Obj_IsDeleted(obj))
{
DrawFairy(obj,FairyColor);
yield;
}
}

task EnemyLifeTask(obj)
{
let oldlife=ObjEnemy_GetInfo(obj, INFO_LIFE);
let lifegap=0;
while(!Obj_IsDeleted(obj))
{
	lifegap=oldlife-ObjEnemy_GetInfo(obj, INFO_LIFE);
	if(lifegap>0)
	{
		Obj_PlaySE(GetCurrentScriptDirectory~"se/tm2_shoot001.wav");
		let Defence=Obj_GetValue(obj, "Defence");
		let Resist=Obj_GetValue(obj, "Resist");
		let Luck=GetCommonData("Sum_Luck",0);
		let Critical=GetCommonData("Sum_Critical",0);
		let OnCritical=false;
		let CriticalPercent=Critical/((Obj_GetValue(obj, "C_Resist")*2)+10)/4;

		let color=[];
		if(CriticalPercent>=rand(0,100))
		{
			Obj_SetValue(GetPlayerObjectID,"CriticalHit",true);
			OnCritical=true;
			Defence*=0.9;
			color=[255,128,255];
		}
		let Damage=lifegap-Defence;

		if(Damage<=0){Damage=1;}
		else
		{
		Damage=Damage*(100-Resist)/100;
		Damage*=rand(0.9+0.1*(Luck/256),1.1);
		Damage=trunc(Damage);
		}
		if(OnCritical)
		{
			Damage=trunc(Damage*1.1)
		}

		DrawDamage(obj,Damage,color);
		//DrawText(Damage, 200, 200,20,255,[]);
		Obj_SetValue(obj, "Life", Obj_GetValue(obj, "Life")-Damage);
	}
	oldlife=ObjEnemy_GetInfo(obj, INFO_LIFE);
yield;
}
}

task EnemyMainTask(obj)
{
	while(!Obj_IsDeleted(obj))
	{
		if(Obj_GetValue(obj, "IntersectionShot")!=0 && Obj_GetValue(obj,"Appear")==0)
		{
			ObjEnemy_SetIntersectionCircleToShot(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),Obj_GetValue(obj, "IntersectionShot"));
		}
		if(Obj_GetValue(obj, "IntersectionPlayer")!=0 && Obj_GetValue(obj,"Appear")==0)
		{
			ObjEnemy_SetIntersectionCircleToPlayer(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),Obj_GetValue(obj, "IntersectionPlayer"));
		}
		if(GetCommonData("StageClear",false)){break;}
		yield;
	}
}

}

function wait(w)
{
	loop(w){yield;}
}
function e_wait(w)
{
	loop(w)
	{
		if(GetCommonData("StageClear",false)){break;}
		yield;
	}
}

function rand_int(min,max)
{
	let a=rand(min,max+1);
	return(floor(a));
}

task CreateMoney(x,y,money)
{
	let AttractFlag=false;
	let AnimeFrame=0;
	let Anime=0;
	let imgBer = GetCurrentScriptDirectory() ~ "img/jewel.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetAngleZ(obj,0);

	Obj_SetValue(obj,"Knock_Right",0);
	Obj_SetValue(obj,"Knock_Left",0);
	Obj_SetValue(obj,"Knock_Up",0);
	Obj_SetValue(obj,"Knock_Down",0);

	ObjPrim_SetVertexPosition(obj, 0, -12, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 12, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 12, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -12, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 48, 0+40*Anime);
	ObjPrim_SetVertexUVT(obj, 1, 72, 0+40*Anime);
	ObjPrim_SetVertexUVT(obj, 2, 72, 40+40*Anime);
	ObjPrim_SetVertexUVT(obj, 3, 48, 40+40*Anime);

	ObjRender_SetPosition(obj,x,y,0);

	let Scale=1;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
/*
	EnemyArray=EnemyArray~[obj];
	let ArrayID=length(EnemyArray)-1;
*/
	IniMove;
	Main;

	while(!Obj_IsDeleted(obj)){yield;}
/*
	ascent(i in 0..length(EnemyArray))
	{
		if(EnemyArray[i]==obj)
		{
			EnemyArray=erase(EnemyArray,i);
			break;
		}
	}
*/
	task IniMove
	{
	let speed=rand(1.5,4.5);
	let Bspeed=speed;
	let angle=rand(0,360);
	let height=0;
	let Hangle=0;
	let Hvalue=12;
	let BHvalue=Hvalue;
		loop(60)
		{
			if(Obj_IsDeleted(obj)){break;}
			ObjRender_SetX(obj, ObjRender_GetX(obj)+speed*cos(angle));
			ObjRender_SetY(obj, ObjRender_GetY(obj)+speed*sin(angle));
			speed-=Bspeed/60;

			ObjPrim_SetVertexPosition(obj, 0, -12, -16+height, -0);
			ObjPrim_SetVertexPosition(obj, 1, 12, -16+height, -0);
			ObjPrim_SetVertexPosition(obj, 2, 12, 16+height, 0);
			ObjPrim_SetVertexPosition(obj, 3, -12, 16+height, 0);

			height=-absolute(Hvalue*sin(Hangle));
			Hangle+=9;
			Hvalue-=BHvalue/60;
			if(Hangle%180==0)
			{
				Obj_PlaySE(GetCurrentScriptDirectory~"se/coin01.wav");
			}
			yield;
		}
	}

	task Main
	{
	while(!Obj_IsDeleted(obj))
	{
		ObjPrim_SetVertexUVT(obj, 0, 48, 0+32*floor(AnimeFrame/8));
		ObjPrim_SetVertexUVT(obj, 1, 72, 0+32*floor(AnimeFrame/8));
		ObjPrim_SetVertexUVT(obj, 2, 72, 32+32*floor(AnimeFrame/8));
		ObjPrim_SetVertexUVT(obj, 3, 48, 32+32*floor(AnimeFrame/8));

		MoveByPlayer(obj);
		AnimeFrame+=1;
		if(AnimeFrame>=8*4){AnimeFrame=0;}

			if(Obj_GetValue(obj,"Knock_Right")!=0)
			{
				ObjRender_SetX(obj, ObjRender_GetX(obj)+5);
				Obj_SetValue(obj,"Knock_Right",0);
			}
			if(Obj_GetValue(obj,"Knock_Left")!=0)
			{
				ObjRender_SetX(obj, ObjRender_GetX(obj)-5);
				Obj_SetValue(obj,"Knock_Left",0);
			}
			if(Obj_GetValue(obj,"Knock_Up")!=0)
			{
				ObjRender_SetY(obj, ObjRender_GetY(obj)-5);
				Obj_SetValue(obj,"Knock_Up",0);
			}
			if(Obj_GetValue(obj,"Knock_Down")!=0)
			{
				ObjRender_SetY(obj, ObjRender_GetY(obj)+5);
				Obj_SetValue(obj,"Knock_Down",0);
			}

		if(((ObjRender_GetY(obj)-GetPlayerY)^2+(ObjRender_GetX(obj)-GetPlayerX)^2)^0.5<=15)
		{
			SetCommonData("Yen",GetCommonData("Yen",0)+money);
			Obj_PlaySE(GetCurrentScriptDirectory~"se/coin07.wav");
			GetItemEffect(ObjRender_GetX(obj),ObjRender_GetY(obj),[255,128,128]);
			Obj_Delete(obj);
		}

		if(!AttractFlag && ((ObjRender_GetY(obj)-GetPlayerY)^2+(ObjRender_GetX(obj)-GetPlayerX)^2)^0.5<=15+GetCommonData("Equip_Collect",0))
		{
			AttractFlag=true;
			Attract(obj);
		}

		if(ObjRender_GetX(obj)<=-96 || ObjRender_GetX(obj)>=GetStgFrameWidth+96 || ObjRender_GetY(obj)<=-96 || ObjRender_GetY(obj)>=448+96)
		{
			Obj_Delete(obj);
		}
		if(SceneChange==true){Obj_Delete(obj);}
		yield;
	}

	}
}

task CreateMana(x,y,mana)
{
	let AttractFlag=false;
	let AnimeFrame=0;
	let Anime=0;
	let imgBer = GetCurrentScriptDirectory() ~ "img/jewel.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetAngleZ(obj,0);

	Obj_SetValue(obj,"Knock_Right",0);
	Obj_SetValue(obj,"Knock_Left",0);
	Obj_SetValue(obj,"Knock_Up",0);
	Obj_SetValue(obj,"Knock_Down",0);

	ObjPrim_SetVertexPosition(obj, 0, -12, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 12, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 12, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -12, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 48+120, 0+40*Anime);
	ObjPrim_SetVertexUVT(obj, 1, 72+120, 0+40*Anime);
	ObjPrim_SetVertexUVT(obj, 2, 72+120, 40+40*Anime);
	ObjPrim_SetVertexUVT(obj, 3, 48+120, 40+40*Anime);

	ObjRender_SetPosition(obj,x,y,0);

	let Scale=1;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
/*
	EnemyArray=EnemyArray~[obj];
	let ArrayID=length(EnemyArray)-1;
*/
	IniMove;
	Main;

	while(!Obj_IsDeleted(obj)){yield;}
/*
	ascent(i in 0..length(EnemyArray))
	{
		if(EnemyArray[i]==obj)
		{
			EnemyArray=erase(EnemyArray,i);
			break;
		}
	}
*/
	task IniMove
	{
	let speed=rand(1.5,4.5);
	let Bspeed=speed;
	let angle=rand(0,360);
	let height=0;
	let Hangle=0;
	let Hvalue=12;
	let BHvalue=Hvalue;
		loop(60)
		{
			if(Obj_IsDeleted(obj)){break;}
			ObjRender_SetX(obj, ObjRender_GetX(obj)+speed*cos(angle));
			ObjRender_SetY(obj, ObjRender_GetY(obj)+speed*sin(angle));
			speed-=Bspeed/60;

			ObjPrim_SetVertexPosition(obj, 0, -12, -16+height, -0);
			ObjPrim_SetVertexPosition(obj, 1, 12, -16+height, -0);
			ObjPrim_SetVertexPosition(obj, 2, 12, 16+height, 0);
			ObjPrim_SetVertexPosition(obj, 3, -12, 16+height, 0);

			height=-absolute(Hvalue*sin(Hangle));
			Hangle+=9;
			Hvalue-=BHvalue/60;
			if(Hangle%180==0)
			{
				Obj_PlaySE(GetCurrentScriptDirectory~"se/coin01.wav");
			}
			yield;
		}
	}

	task Main
	{
	while(!Obj_IsDeleted(obj))
	{
		ObjPrim_SetVertexUVT(obj, 0, 48+24*6, 0+32*floor(AnimeFrame/8));
		ObjPrim_SetVertexUVT(obj, 1, 72+24*6, 0+32*floor(AnimeFrame/8));
		ObjPrim_SetVertexUVT(obj, 2, 72+24*6, 32+32*floor(AnimeFrame/8));
		ObjPrim_SetVertexUVT(obj, 3, 48+24*6, 32+32*floor(AnimeFrame/8));

		MoveByPlayer(obj);
		AnimeFrame+=1;
		if(AnimeFrame>=8*4){AnimeFrame=0;}

			if(Obj_GetValue(obj,"Knock_Right")!=0)
			{
				ObjRender_SetX(obj, ObjRender_GetX(obj)+5);
				Obj_SetValue(obj,"Knock_Right",0);
			}
			if(Obj_GetValue(obj,"Knock_Left")!=0)
			{
				ObjRender_SetX(obj, ObjRender_GetX(obj)-5);
				Obj_SetValue(obj,"Knock_Left",0);
			}
			if(Obj_GetValue(obj,"Knock_Up")!=0)
			{
				ObjRender_SetY(obj, ObjRender_GetY(obj)-5);
				Obj_SetValue(obj,"Knock_Up",0);
			}
			if(Obj_GetValue(obj,"Knock_Down")!=0)
			{
				ObjRender_SetY(obj, ObjRender_GetY(obj)+5);
				Obj_SetValue(obj,"Knock_Down",0);
			}

		if(((ObjRender_GetY(obj)-GetPlayerY)^2+(ObjRender_GetX(obj)-GetPlayerX)^2)^0.5<=15)
		{
			SetCommonData("Mana",GetCommonData("Mana",0)+mana);
			Obj_PlaySE(GetCurrentScriptDirectory~"se/coin07.wav");
			GetItemEffect(ObjRender_GetX(obj),ObjRender_GetY(obj),[128,128,255]);
			Obj_Delete(obj);
		}

		if(!AttractFlag && ((ObjRender_GetY(obj)-GetPlayerY)^2+(ObjRender_GetX(obj)-GetPlayerX)^2)^0.5<=15+GetCommonData("Equip_Collect",0))
		{
			AttractFlag=true;
			Attract(obj);
		}

		if(ObjRender_GetX(obj)<=-96 || ObjRender_GetX(obj)>=GetStgFrameWidth+96 || ObjRender_GetY(obj)<=-96 || ObjRender_GetY(obj)>=448+96)
		{
			Obj_Delete(obj);
		}
		if(SceneChange==true){Obj_Delete(obj);}
		yield;
	}

	}

}

task CreateTreasure(x,y,Treasure)
{
	let AttractFlag=false;
	let AnimeFrame=0;
	let Anime=0;
	let imgBer = GetCurrentScriptDirectory() ~ "img/takara.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetAngleZ(obj,0);

	Obj_SetValue(obj,"Knock_Right",0);
	Obj_SetValue(obj,"Knock_Left",0);
	Obj_SetValue(obj,"Knock_Up",0);
	Obj_SetValue(obj,"Knock_Down",0);

	ObjPrim_SetVertexPosition(obj, 0, -12, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 12, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 12, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -12, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 72, 64);
	ObjPrim_SetVertexUVT(obj, 1, 96, 64);
	ObjPrim_SetVertexUVT(obj, 2, 96, 96);
	ObjPrim_SetVertexUVT(obj, 3, 72, 96);

	ObjRender_SetPosition(obj,x,y,0);

	let Scale=1;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);

	EnemyArray=EnemyArray~[obj];
	let ArrayID=length(EnemyArray)-1;

	IniMove;
	Main;

	while(!Obj_IsDeleted(obj)){yield;}

	ascent(i in 0..length(EnemyArray))
	{
		if(EnemyArray[i]==obj)
		{
			EnemyArray=erase(EnemyArray,i);
			break;
		}
	}

	task IniMove
	{
	let speed=rand(1.5,4.5);
	let Bspeed=speed;
	let angle=rand(0,360);
	let height=0;
	let Hangle=0;
	let Hvalue=12;
	let BHvalue=Hvalue;
		loop(60)
		{
			if(Obj_IsDeleted(obj)){break;}
			ObjRender_SetX(obj, ObjRender_GetX(obj)+speed*cos(angle));
			ObjRender_SetY(obj, ObjRender_GetY(obj)+speed*sin(angle));
			speed-=Bspeed/60;

			ObjPrim_SetVertexPosition(obj, 0, -12, -16+height, -0);
			ObjPrim_SetVertexPosition(obj, 1, 12, -16+height, -0);
			ObjPrim_SetVertexPosition(obj, 2, 12, 16+height, 0);
			ObjPrim_SetVertexPosition(obj, 3, -12, 16+height, 0);

			height=-absolute(Hvalue*sin(Hangle));
			Hangle+=9;
			Hvalue-=BHvalue/60;
			if(Hangle%180==0)
			{
				Obj_PlaySE(GetCurrentScriptDirectory~"se/coin01.wav");
			}
			yield;
		}
	}

	task Main
	{
	while(!Obj_IsDeleted(obj))
	{
		MoveByPlayer(obj);
		AnimeFrame+=1;
		if(AnimeFrame>=8*4){AnimeFrame=0;}

			if(Obj_GetValue(obj,"Knock_Right")!=0)
			{
				ObjRender_SetX(obj, ObjRender_GetX(obj)+5);
				Obj_SetValue(obj,"Knock_Right",0);
			}
			if(Obj_GetValue(obj,"Knock_Left")!=0)
			{
				ObjRender_SetX(obj, ObjRender_GetX(obj)-5);
				Obj_SetValue(obj,"Knock_Left",0);
			}
			if(Obj_GetValue(obj,"Knock_Up")!=0)
			{
				ObjRender_SetY(obj, ObjRender_GetY(obj)-5);
				Obj_SetValue(obj,"Knock_Up",0);
			}
			if(Obj_GetValue(obj,"Knock_Down")!=0)
			{
				ObjRender_SetY(obj, ObjRender_GetY(obj)+5);
				Obj_SetValue(obj,"Knock_Down",0);
			}

		if(((ObjRender_GetY(obj)-GetPlayerY)^2+(ObjRender_GetX(obj)-GetPlayerX)^2)^0.5<=15)
		{	
			DrawGetItem;
			StageTreasure=StageTreasure~[[Treasure]];
			Obj_PlaySE(GetCurrentScriptDirectory~"se/coin07.wav");
			GetItemEffect(ObjRender_GetX(obj),ObjRender_GetY(obj),[255,255,128]);
			Obj_Delete(obj);
		}

		if(!AttractFlag && ((ObjRender_GetY(obj)-GetPlayerY)^2+(ObjRender_GetX(obj)-GetPlayerX)^2)^0.5<=15+GetCommonData("Equip_Collect",0))
		{
			AttractFlag=true;
			Attract(obj);
		}

		if(ObjRender_GetX(obj)<=-96 || ObjRender_GetX(obj)>=GetStgFrameWidth+96 || ObjRender_GetY(obj)<=-96 || ObjRender_GetY(obj)>=448+96)
		{
			Obj_Delete(obj);
		}
		if(SceneChange==true){Obj_Delete(obj);}
		yield;
	}

	}

}

task GetItemEffect(x,y,color)
{
	let AnimeFrame=0;
	let Anime=0;
	let imgBer = GetCurrentScriptDirectory() ~ "img/Light.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,21);
	ObjRender_SetAngleZ(obj,0);

	Obj_SetValue(obj,"Knock_Right",0);
	Obj_SetValue(obj,"Knock_Left",0);
	Obj_SetValue(obj,"Knock_Up",0);
	Obj_SetValue(obj,"Knock_Down",0);

	ObjPrim_SetVertexPosition(obj, 0, -16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 16, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -16, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 32, 0);
	ObjPrim_SetVertexUVT(obj, 2, 32, 32);
	ObjPrim_SetVertexUVT(obj, 3, 0, 32);

	ObjRender_SetPosition(obj,x,y+4,0);

	ObjRender_SetColor(obj,color[0],color[1],color[2]);
	let Scale=1;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);

	loop(15)
	{
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);

		Scale-=1/15;
			MoveByPlayer(obj);

			if(Obj_GetValue(obj,"Knock_Right")!=0)
			{
				ObjRender_SetX(obj, ObjRender_GetX(obj)+5);
				Obj_SetValue(obj,"Knock_Right",0);
			}
			if(Obj_GetValue(obj,"Knock_Left")!=0)
			{
				ObjRender_SetX(obj, ObjRender_GetX(obj)-5);
				Obj_SetValue(obj,"Knock_Left",0);
			}
			if(Obj_GetValue(obj,"Knock_Up")!=0)
			{
				ObjRender_SetY(obj, ObjRender_GetY(obj)-5);
				Obj_SetValue(obj,"Knock_Up",0);
			}
			if(Obj_GetValue(obj,"Knock_Down")!=0)
			{
				ObjRender_SetY(obj, ObjRender_GetY(obj)+5);
				Obj_SetValue(obj,"Knock_Down",0);
			}
		yield;
	}
	Obj_Delete(obj);
}

function MoveByPlayer(obj)
{

			ObjRender_SetX(obj, ObjRender_GetX(obj)-Move_Right);

			ObjRender_SetX(obj, ObjRender_GetX(obj)-Move_Left);

			ObjRender_SetY(obj, ObjRender_GetY(obj)-Move_Up);

			ObjRender_SetY(obj, ObjRender_GetY(obj)-Move_Down);

/*
		let sr=Obj_GetValue(GetPlayerObjectID,"Move_Right");
		let sl=Obj_GetValue(GetPlayerObjectID,"Move_Left");
		let su=Obj_GetValue(GetPlayerObjectID,"Move_Up");
		let sd=Obj_GetValue(GetPlayerObjectID,"Move_Down");
		if(sr!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sr);
		}
		if(sl!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sl);
		}
		if(su!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-su);
		}
		if(sd!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-sd);
		}
*/
}

task Obj_PlaySE(path)
{
	let obj = ObjSound_Create;
	ObjSound_Load(obj,path);
	ObjSound_SetSoundDivision(obj,SOUND_SE);
	ObjSound_SetLoopEnable(obj,false);
	ObjSound_Play(obj);

	ObjSound_SetVolumeRate(obj,GetCommonData("SEVolume",100));
/*
	while(ObjSound_IsPlaying(obj))
	{
		yield;
	}
	Obj_Delete(obj);
*/
}


task Obj_PlayBGM(path)
{
	let obj = ObjSound_Create;
	ObjSound_Load(obj,path);
	ObjSound_SetSoundDivision(obj,SOUND_BGM);
	ObjSound_SetLoopEnable(obj,true);
	ObjSound_Play(obj);

	ObjSound_SetVolumeRate(obj,GetCommonData("BGMVolume",100)/1.5);
	wait(2);

	ObjSound_SetFade(obj,GetCommonData("BGMVolume",100)/5);

	while(ObjSound_IsPlaying(obj))
	{
		//DrawText(ObjSound_IsPlaying(obj), 264, 330,20,255,[]);
		//ObjSound_SetVolumeRate(obj,GetCommonData("BGMVolume",100));
		if(ObjSound_GetVolumeRate(obj)>=GetCommonData("BGMVolume",100))
		{
			ObjSound_SetFade(obj,0);
		}
		if(BGMStop){break;}
		yield;
	}
	ObjSound_SetFade(obj,-15);
	wait(300);
	Obj_Delete(obj);
}

function SetDrop(obj,Exp,Money,Mana)
{
	if(Exp>0)
	{
	EnemyKill+=1;
	SetCommonData("Exp",GetCommonData("Exp",0)+Exp);
	}
	if(Money>0)
	{
	CreateMoney(ObjMove_GetX(obj),ObjMove_GetY(obj),Money);
	}
	if(Mana>0)
	{
	CreateMana(ObjMove_GetX(obj),ObjMove_GetY(obj),Mana);
	}
	StageBonusExp+=Exp/16;
	StageBonusMoney+=Money/8;
	StageBonusMana+=Mana/8;
}

task DrawDamage(objEnemy,damage,color)
{
		Obj_SetValue(objEnemy, "DrawCount", Obj_GetValue(objEnemy, "DrawCount")+1);
		let count=Obj_GetValue(objEnemy, "DrawCount");
		if(Obj_GetValue(objEnemy, "DrawDamage")!=0)
		{
		Obj_SetValue(objEnemy, "DrawDamage", Obj_GetValue(objEnemy, "DrawDamage")+damage);
		EnemyCombo+=1;
		}
		else
		{
		Obj_SetValue(objEnemy, "DrawDamage", damage);
		}
		if(Obj_GetValue(objEnemy, "DrawDamage")>=Obj_GetValue(objEnemy, "MaxLife"))
		{
			EnemyInstantKill+=1;
		}
		let size=7;
		let obj = ObjText_Create();
		ObjText_SetText(obj, IntToString(Obj_GetValue(objEnemy, "DrawDamage")));
		ObjText_SetFontSize(obj, size);
		ObjText_SetFontBold(obj, true);
		ObjText_SetFontColorTop(obj, 255, 196, 196);
		ObjText_SetFontColorBottom(obj, 196, 128, 128);
		ObjText_SetFontBorderType(obj, BORDER_NONE);
		ObjText_SetFontBorderColor(obj,255, 255, 255);
		ObjText_SetFontBorderWidth(obj, 0);
		Obj_SetRenderPriorityI(obj, 80);
//		ObjRender_SetX(obj, ObjRender_GetX(objEnemy)-5);
//		ObjRender_SetY(obj, ObjRender_GetY(objEnemy)-GetGapFocusY);
		ObjText_SetFontType(obj,"ＭＳ 明朝");

	//	ObjText_SetMaxWidth(obj,200);

		if(length(color)!=0)
		{
		ObjText_SetFontColorTop(obj, color[0], color[1], color[2]);
		ObjText_SetFontColorBottom(obj, color[0]-60, color[1]-60 ,color[2]-60);
		}

	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	//	ObjRender_SetAlpha(obj,alpha);

	//	ObjText_SetHorizontalAlignment(obj,ALIGNMENT_CENTER);

		let Y=-20;
		let ey=ObjRender_GetY(objEnemy);
		let el=Obj_GetValue(objEnemy, "DrawDamage");
		ObjRender_SetAlpha(obj,0);
		ObjRender_SetY(obj, ey+Y);
		loop(3)
		{
			if(!Obj_IsDeleted(objEnemy))
			{
			ObjRender_SetX(obj, ObjRender_GetX(objEnemy)-5);
		//	ObjRender_SetY(obj, ObjRender_GetY(objEnemy)-GetGapFocusY);
			ey=ObjRender_GetY(objEnemy)-GetGapFocusY;
			el=Obj_GetValue(objEnemy, "DrawDamage");
			if(count!=Obj_GetValue(objEnemy, "DrawCount")){break;}
			}
			ObjRender_SetY(obj, ey+Y);
			ObjText_SetFontSize(obj, size);
			size+=6/3;
			Y-=5/3;
			yield;
		}

		ObjRender_SetAlpha(obj,255);
		ObjText_SetFontSize(obj, size);

		loop(30)
		{
			if(!Obj_IsDeleted(objEnemy))
			{
			ObjRender_SetX(obj, ObjRender_GetX(objEnemy)-5);
			ObjRender_SetY(obj, ObjRender_GetY(objEnemy)-GetGapFocusY);
			ey=ObjRender_GetY(objEnemy);
			el=Obj_GetValue(objEnemy, "DrawDamage");
			if(count!=Obj_GetValue(objEnemy, "DrawCount")){break;}
			ObjRender_SetY(obj, ey+Y-GetGapFocusY);
			}
			else
			{
				MoveByPlayer(obj);
			}
			yield;
		}
		if(!Obj_IsDeleted(objEnemy))
		{
		if(Obj_GetValue(objEnemy, "DrawDamage")==damage || count==Obj_GetValue(objEnemy, "DrawCount"))
		{
		Obj_SetValue(objEnemy, "DrawDamage", 0);
		}
		}
		loop(1)
		{
			if(!Obj_IsDeleted(objEnemy))
			{
			ObjRender_SetX(obj, ObjRender_GetX(objEnemy)-5);
			ObjRender_SetY(obj, ObjRender_GetY(objEnemy)-GetGapFocusY);
			ey=ObjRender_GetY(objEnemy);
			el=Obj_GetValue(objEnemy, "DrawDamage");
			ObjRender_SetY(obj, ey+Y-GetGapFocusY);
			}
			else
			{
				MoveByPlayer(obj);
			}
			yield;
		}
		Obj_Delete(obj);
}

task AppearEffect(Cobj,color)
{
	let imgBer = GetCurrentScriptDirectory() ~ "img/circle.png";

	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,21);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 16, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -16, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 256, 0);
	ObjPrim_SetVertexUVT(obj, 2, 256, 256);
	ObjPrim_SetVertexUVT(obj, 3, 0, 256);

	let Scale=2;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
	let Zangle=0;
	let Alpha=0;
	loop(30)
	{
		ObjRender_SetPosition(obj,ObjRender_GetX(Cobj)-1,ObjRender_GetY(Cobj)+5,0);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetColor(obj,color[0]*Alpha,color[1]*Alpha,color[2]*Alpha);
		ObjRender_SetAngleXYZ(obj,0,0,Zangle);
		Zangle+=3;
		Scale-=1/30;
		if(Alpha<1){
		Alpha+=1/15;}
		yield;
	}
	loop(30)
	{
		ObjRender_SetPosition(obj,ObjRender_GetX(Cobj)-1,ObjRender_GetY(Cobj)+5,0);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetColor(obj,color[0]*Alpha,color[1]*Alpha,color[2]*Alpha);
		ObjRender_SetAngleXYZ(obj,0,0,Zangle);
		Zangle+=3;
	//	Scale-=1/30;
		Alpha-=1/30;
		yield;
	}
	Obj_SetValue(Cobj,"Appear",0);
	Obj_Delete(obj);
}

task TreasureAppearEffect(Cobj)
{
	ascent(i in 0..60)
	{
		LightEffect(i);
		LightEffect(i);
	}
	CircleEffect(60);
	wait(120);
	Obj_SetValue(Cobj,"Appear",0);

	task LightEffect(time)
	{
	let color=[128,rand(128,256),rand(128,256)];
	let imgBer = GetCurrentScriptDirectory() ~ "img/Light.png";

	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,21);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 16, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -16, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 32, 0);
	ObjPrim_SetVertexUVT(obj, 2, 32, 32);
	ObjPrim_SetVertexUVT(obj, 3, 0, 32);

	let Scale=rand(1,1.5);
	let BScale=Scale;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
	let Alpha=1;
	let Radius=rand(100,200);
	let BRadius=Radius;
	let Angle=rand(0,360);

	loop(time)
	{
		ObjRender_SetColor(obj,0,0,0);
		MoveByPlayer(obj);
		yield;
	}

	loop(30)
	{
		ObjRender_SetPosition(obj,ObjRender_GetX(Cobj)+Radius*cos(Angle),ObjRender_GetY(Cobj)+Radius*sin(Angle),0);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetColor(obj,color[0]*Alpha,color[1]*Alpha,color[2]*Alpha);
		Radius-=BRadius/30;
		Scale-=BScale/30;
		if(Alpha>0){
		Alpha-=1/45;}
		yield;
	}
	Obj_Delete(obj);
	}

	task CircleEffect(time)
	{
	let color=[128,128,255];
	let imgBer = GetCurrentScriptDirectory() ~ "img/Marisa_shots.png";

	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,21);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 16, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -16, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 128, 0);
	ObjPrim_SetVertexUVT(obj, 2, 128, 128);
	ObjPrim_SetVertexUVT(obj, 3, 0, 128);

	let Scale=0;
	let BScale=Scale;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
	let Alpha=1;

	loop(time)
	{
		ObjRender_SetColor(obj,0,0,0);
		MoveByPlayer(obj);
		yield;
	}

	loop(60)
	{
		ObjRender_SetPosition(obj,ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),0);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetColor(obj,color[0]*Alpha,color[1]*Alpha,color[2]*Alpha);
		Scale+=4/60;
		if(Alpha>0){
		Alpha-=1/60;}
		yield;
	}
	Obj_Delete(obj);
	}

}

task DefeatEffect(x,y)
{
	Obj_PlaySE(GetCurrentScriptDirectory~"se/se_maoudamashii_element_water08.wav");
	loop(15)
	{
	LightEffect(0);
	}
	ascent(i in 1..15)
	{
	LightEffect(i);
	}

	task LightEffect(time)
	{
	let color=[128,rand(128,256),rand(128,256)];
	let imgBer = GetCurrentScriptDirectory() ~ "img/Light.png";

	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,21);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 16, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -16, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 32, 0);
	ObjPrim_SetVertexUVT(obj, 2, 32, 32);
	ObjPrim_SetVertexUVT(obj, 3, 0, 32);

	let Scale=rand(1,1.5);
	let BScale=Scale;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
	let Alpha=0.75;
	let Radius=rand(100,200);
	let BRadius=Radius;
	let Angle=rand(0,360);
	ObjRender_SetPosition(obj,x,y,0);
	let Speed=rand(1.5,4.5);
	loop(time)
	{
		ObjRender_SetColor(obj,0,0,0);
		MoveByPlayer(obj);
		yield;
	}
	loop(20)
	{
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+Speed*cos(Angle),ObjRender_GetY(obj)+Speed*sin(Angle),0);
		MoveByPlayer(obj);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetColor(obj,color[0]*Alpha,color[1]*Alpha,color[2]*Alpha);
		Scale-=BScale/20;
		if(Alpha>0){
		Alpha-=1/45;}
		yield;
	}
	Obj_Delete(obj);
	}
}

task DrawGetItem
{
	let Letter="Get Item";
	ascent(i in 0..8)
	{
	DrawLetter(Letter[i],7*i+3);
	wait(1);
	}

	task DrawLetter(text,x)
	{
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 196);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 70);
	ObjRender_SetX(objText, GetPlayerX+x);
	ObjRender_SetY(objText, GetPlayerY-10);

	let Scale=1.5;

	ObjRender_SetScaleY(objText,0.9);
	loop(30)
	{
		if(Scale>1.0)
		{
			Scale-=0.5/5;
		}
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetX(objText, GetPlayerX+x);
		ObjRender_SetY(objText, GetPlayerY-10);
		yield;
	}
	let alpha=255;
	loop(5)
	{
		Scale+=0.5/5;
		alpha-=255/5;
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetAlpha(objText,alpha);
		ObjRender_SetX(objText, GetPlayerX+x);
		ObjRender_SetY(objText, GetPlayerY-10);
		yield;
	}
	Obj_Delete(objText);
	}
}

function GetStageFlag(locate)
{
let SceneFlag=GetCommonData(locate,[[0],[0],[0]]);
let StageFlag=SceneFlag[0][0];
alternative(locate)
case("魔法の森"){return(StageFlag);}
case("紅魔館"){return(StageFlag);}
case("博麗神社"){return(StageFlag);}
}

function GetStageFlagArray(locate)
{
	return(GetCommonData(locate,[[1,0,0],[0],[0],[0]]));
}


task SP_CreateShotA1(x,y,speed,angle,type,delay)
{
let obj=ObjShot_Create(OBJ_SHOT);
ObjMove_SetPosition(obj,x,y);
ObjMove_SetSpeed(obj,speed);
ObjMove_SetAngle(obj,angle);
ObjShot_SetGraphic(obj,type);
ObjShot_SetDelay(obj,delay);
ObjShot_Regist(obj);
while(!Obj_IsDeleted(obj))
{
MoveByPlayer(obj);
yield;
}
}


	task Attract(obj)
	{
	let angle=atan2(GetPlayerY-ObjRender_GetY(obj),GetPlayerX-ObjRender_GetX(obj));
	let speed=0;
	while(!Obj_IsDeleted(obj))
	{
		angle=atan2(GetPlayerY-ObjRender_GetY(obj),GetPlayerX-ObjRender_GetX(obj));
		ObjRender_SetX(obj,ObjRender_GetX(obj)+speed*cos(angle));
		ObjRender_SetY(obj,ObjRender_GetY(obj)+speed*sin(angle));
		speed+=0.015;	
		yield;
	}
	}

function UniqueItemJudg(name)
{
let judg=false;
alternative(name)
case("プロテクトリング"){return(true);}
case("コレクトリング"){return(true);}
case("初等魔法書"){return(true);}
others
{
return(false);
}
}

function TreasureDropProbability(P)
{
	P=floor(P/(1+GetCommonData("Sum_Luck",0)/512));
	let num=rand_int(0,P-1);
	if(num==0)
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function UniqueCarryCheck(name)
{

let EquipArray=["Equip1","Equip2","Equip3","Equip4"];
ascent(i in 0..4)
{
if(GetCommonData(EquipArray[i],["0","0","0"])[0]==name)
{
return(true);
}
}


ascent(i in 0..length(GetCommonData("Equip_All",[["0"]])))
{
	if(GetCommonData("Equip_All",[["0"]])[i][0]==name)
	{
		return(true);
	}
}

return(false);
}

task SpellCardEffect(Cobj,Text)
{
	let TextEndFlag=false;
	MagicCircle(1);
	MagicCircle(-1);

	let Letter=Text;
	ascent(i in 0..floor(length(Text)/2))
	{
	DrawLetter(Letter[i*2..i*2+2],20*i+(480-20*floor(length(Text)/2)),i);
	wait(2);
	}
	SetCommonData("SpellEndFlag",false);
	TextEndFlag=true;

	task DrawLetter(text,x,order)
	{
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	ObjText_SetFontSize(objText, 20);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 196);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 70);

	ObjRender_SetX(objText,0+x);
	ObjRender_SetY(objText, 20);

	//ObjText_SetHorizontalAlignment(objText,ALIGNMENT_RIGHT);

	let Scale=1.5;

	ObjRender_SetScaleY(objText,0.9);
	loop(120)
	{
		if(Scale>1.0)
		{
			Scale-=0.5/5;
		}
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		yield;
	}
	let alpha=255;
	while(!GetCommonData("SpellEndFlag",false)){yield;}
	wait(order*2);
	loop(5)
	{
		Scale+=0.5/5;
		alpha-=255/5;
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetAlpha(objText,alpha);
		yield;
	}
	Obj_Delete(objText);
	}

	task MagicCircle(dir)
	{
		let imgWhite = GetCurrentScriptDirectory() ~ "img/circle.png";
		let obje = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obje, imgWhite);
		ObjPrim_SetPrimitiveType(obje, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obje, 4);
		ObjRender_SetBlendType(obje, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obje,20);
		ObjRender_SetAngleZ(obje,0);

		ObjPrim_SetVertexPosition(obje, 0, -64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 1, 64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obje, 3,-64, 64, 0);

		ObjPrim_SetVertexUVT(obje, 0, 0, 0);
		ObjPrim_SetVertexUVT(obje, 1, 256, 0);
		ObjPrim_SetVertexUVT(obje, 2, 256, 256);
		ObjPrim_SetVertexUVT(obje, 3, 0, 256);

		let Alpha=0;
		ObjRender_SetColor(obje,255*Alpha,128*Alpha,128*Alpha);
		let Scale=0;
		let ZAngle=0;
		loop(30)
		{
		ObjRender_SetPosition(obje,ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),0);
		ObjRender_SetColor(obje,255*Alpha,128*Alpha,128*Alpha);
		ObjRender_SetScaleXYZ(obje,Scale,Scale,1);
		ObjRender_SetAngleZ(obje,ZAngle);
		Scale+=1/30;
		Alpha+=0.5/30;
		ZAngle+=3*dir;
		yield;
		}
		loop(90)
		{
		ObjRender_SetPosition(obje,ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),0);
		ObjRender_SetAngleZ(obje,ZAngle);
		ZAngle+=3*dir;
		yield;
		}
		loop(30)
		{
		ObjRender_SetPosition(obje,ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),0);
		ObjRender_SetColor(obje,255*Alpha,128*Alpha,128*Alpha);
		ObjRender_SetScaleXYZ(obje,Scale,Scale,1);
		ObjRender_SetAngleZ(obje,ZAngle);
		Scale+=4/30;
		Alpha-=0.5/30;
		ZAngle+=3*dir;
		yield;
		}
		Obj_Delete(obje);
	}
}

task BossDefeatEffect(Cobj)
{
	let ex=0;
	let time=2;
	loop(30)
	{
	ExCircle(ex);
	ex+=1/30;
	wait(time);
	}
	wait(15);
	loop(60)
	{
		FragEffect([rand(100,150),rand(100,150),rand(200,255)]);
	}
	ex=1.5;
	loop(45)
	{
		ExCircle2(ex);
		ex-=1.5/45;
		yield;
	}

	task ExCircle(BScale)
	{
		let imgWhite = GetCurrentScriptDirectory() ~ "img/effects.png";
		let obje = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obje, imgWhite);
		ObjPrim_SetPrimitiveType(obje, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obje, 4);
		ObjRender_SetBlendType(obje, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obje,20);
		ObjRender_SetAngleZ(obje,0);

		ObjPrim_SetVertexPosition(obje, 0, -64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 1, 64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obje, 3,-64, 64, 0);

		ObjPrim_SetVertexUVT(obje, 0, 0, 0);
		ObjPrim_SetVertexUVT(obje, 1, 128, 0);
		ObjPrim_SetVertexUVT(obje, 2, 128, 128);
		ObjPrim_SetVertexUVT(obje, 3, 0, 128);

		let Alpha=1;
		ObjRender_SetColor(obje,255*Alpha,128*Alpha,128*Alpha);
		let Scale=BScale;
		BScale=Scale;
		let XAngle=rand(0,360)*0;
		let YAngle=rand(0,360)*0;
		let ZAngle=rand(0,360)*0;
		let XAnglePlus=rand(2,10)*(rand_int(0,1)*2-1);
		let YAnglePlus=rand(2,10)*(rand_int(0,1)*2-1);
		let ZAnglePlus=rand(2,10)*(rand_int(0,1)*2-1);
		loop(30)
		{
		ObjRender_SetPosition(obje,ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),0);
		ObjRender_SetColor(obje,255*Alpha,128*Alpha,128*Alpha);
		ObjRender_SetScaleXYZ(obje,Scale,Scale,1);
		ObjRender_SetAngleXYZ(obje,XAngle,YAngle,ZAngle);
		Scale-=BScale/30;
		Alpha-=1.0/30;
/*
		XAngle+=XAnglePlus;
		YAngle+=YAnglePlus;
		ZAngle+=ZAnglePlus;
*/
		yield;
		}
		Obj_Delete(obje);
	}

	task ExCircle2(BScale)
	{
		let imgWhite = GetCurrentScriptDirectory() ~ "img/effects.png";
		let obje = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obje, imgWhite);
		ObjPrim_SetPrimitiveType(obje, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obje, 4);
		ObjRender_SetBlendType(obje, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obje,20);
		ObjRender_SetAngleZ(obje,0);

		ObjPrim_SetVertexPosition(obje, 0, -64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 1, 64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obje, 3,-64, 64, 0);

		ObjPrim_SetVertexUVT(obje, 0, 0, 0);
		ObjPrim_SetVertexUVT(obje, 1, 128, 0);
		ObjPrim_SetVertexUVT(obje, 2, 128, 128);
		ObjPrim_SetVertexUVT(obje, 3, 0, 128);
		ObjRender_SetPosition(obje,ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),0);

		let Alpha=1;
		ObjRender_SetColor(obje,255*Alpha,128*Alpha,128*Alpha);
		let Scale=0;
		let XAngle=0;
		let YAngle=0;
		let ZAngle=rand(0,360);
		loop(30)
		{
		ObjRender_SetPosition(obje,ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),0);
		ObjRender_SetColor(obje,255*Alpha,128*Alpha,128*Alpha);
		ObjRender_SetScaleXYZ(obje,Scale,Scale,1);
		ObjRender_SetAngleXYZ(obje,XAngle,YAngle,ZAngle);
		Scale+=BScale/30;
		Alpha-=1.0/30;
		yield;
		}
		Obj_Delete(obje);
	}

	task FragEffect(color)
	{
	let AnimeFrame=0;
	let Anime=0;
	let imgBer = GetCurrentScriptDirectory() ~ "img/Light.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,21);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 16, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -16, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 32, 0);
	ObjPrim_SetVertexUVT(obj, 2, 32, 32);
	ObjPrim_SetVertexUVT(obj, 3, 0, 32);

	ObjRender_SetPosition(obj,ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),0);

	ObjRender_SetColor(obj,color[0],color[1],color[2]);
	let Scale=1;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
	let speed=rand(1,10);
	let angle=rand(0,360);
	loop(60)
	{
		MoveByPlayer(obj);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
		Scale-=1/60;
		yield;
	}
	Obj_Delete(obj);
	}

}
