#include_function ".\..\txt/EnemyAchievement.txt"
let NsScore = "SAVE_SCORE";	//スコア
let NsHi = "HI_SCORE";	//ハイスコア(NsScore)

let NsAchievement=[];
ascent(i in 0..100)
{
NsAchievement=NsAchievement~["Achievement_"~NumToStringNoComplete(i)];
}

	function NumToStringNoComplete(let num)
	{
		if(num==0)
		{
			num=0.1;
		}
		let leng = trunc(log10(num))+1;//整数部分の桁数を求める
		let string = ToString(num);//数字を文字列に変える
		return string[0..leng];//文字列をスライシングして返す
	}

let DamageRate=100;
let BombDamageRate=100;

let imgBoss;
let imgBoss2;
alternative(GetCommonDataDefault("STAGEPROGRESS",0))
case(1)
{
imgBoss=csd ~ "..\lib/dot_daiyousei.png";
imgBoss2=csd ~ "..\lib/dot_daiyousei2.png";
}
case(2)
{
if(GetCommonDataDefault("STAGE2MIDBOSS",false))
{
imgBoss=csd ~ "..\lib/dot_lunachild.png";
imgBoss2=csd ~ "..\lib/dot_lunachild2.png";
}
else
{
imgBoss=csd ~ "..\lib/dot_mokou.png";
imgBoss2=csd ~ "..\lib/dot_mokou2.png";
}
}
case(3)
{
if(GetCommonDataDefault("STAGE3MIDBOSS",false))
{
imgBoss=csd ~ "..\lib/dot_starsapphire.png";
imgBoss2=csd ~ "..\lib/dot_starsapphire2.png";
}
else
{
imgBoss=csd ~ "..\lib/dot_nue.png";
imgBoss2=csd ~ "..\lib/dot_nue2.png";
}
}
case(4)
{
if(GetCommonDataDefault("STAGE4MIDBOSS",false))
{
imgBoss=csd ~ "..\lib/dot_sunnymilk.png";
imgBoss2=csd ~ "..\lib/dot_sunnymilk2.png";
}
else
{
imgBoss=csd ~ "..\lib/dot_aya.png";
imgBoss2=csd ~ "..\lib/dot_aya2.png";
}
}
case(5)
{
if(GetCommonDataDefault("STAGE5MIDBOSS",false))
{
imgBoss=csd ~ "..\lib/dot_yuka.png";
imgBoss2=csd ~ "..\lib/dot_yuka2.png";
}
else
{
imgBoss=csd ~ "..\lib/dot_alice.png";
imgBoss2=csd ~ "..\lib/dot_alice2.png";
}
}
// w フレームだけ待つ
function wait(w) 
{
    loop(w) { yield; }
}

function WaitForZeroEnemy()//敵数が0になるまで待機する関数
{
	while(GetEnemyNum() != 0){yield;}
}


function RandDir
{
return(rand_int(0,1)*2-1);
}

function SetDummySkyCollision(x,y,Radius)
{
	if(GetCommonDataDefault("MSDPlayer",false)==false)
	{
	MSDSetCollisionA(x,y,Radius);
        MSDSetCollisionB(x,y,Radius/3);
	}
}

function SetDummyGroundCollision(x,y,Radius)
{
	if(GetCommonDataDefault("MSDPlayer",false)==false)
	{
	MSDSetCollisionA(x,y,Radius);
	}
}

function MSDSetCollisionA(x,y,Radius)
{
	SetCollisionA(x,y,Radius);
}

function MSDSetCollisionB(x,y,Radius)
{
	if(GetCommonDataDefault("BURSTLEVEL",0)==0)
	{
		if(GetDistanceToPlayer<=Radius && GetTimeOfPlayerInvincibility==0)
		{
			ItemSet(GetX,GetY,-1);
		}
	}
}

function GetDistanceToPlayer
{
	let dis=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	return(dis);
}

task OutDamageRateZero
{
let DamegeCoefficient=0;
let ArrangeDamageRate=0;
let ArrangeBombDamageRate=0;
if(GetCommonDataDefault("StrongPlayer",false)==true)
{
	ArrangeDamageRate=0.4;
	ArrangeBombDamageRate=0.1;
}
else if(GetCommonDataDefault("MSDPlayer",false)==true)
{
	ArrangeDamageRate=1.0;
	ArrangeBombDamageRate=1.0;
}
else if(GetPlayerType!=USER_PLAYER)
{
	ArrangeDamageRate=0.90;
	ArrangeBombDamageRate=0.2;
}
else
{
	ArrangeDamageRate=0.8;
	ArrangeBombDamageRate=0.2;
}
//let SRange=GetCommonData("MagicAbsorbShortRange");
//let LRange=GetCommonData("MagicAbsorbLongRange");
let SRange=60;
let LRange=150;
let BaseSRange=60;
let BaseLRange=150;
alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
case("Apocalypse")
{
	SRange*=1.2;
	LRange*=1.2;
}
let PastLife=GetLife;
let LifeCheckCount=0;
loop
{
	SRange=BaseSRange*(1+0.2*GetCommonDataDefault("RUSHGAUGE",0)/1000);
	LRange=BaseLRange*(1+0.2*GetCommonDataDefault("RUSHGAUGE",0)/1000);

	if(GetX<GetClipMinX-16 || GetClipMaxX+16<GetX || GetY<GetClipMinY-16 || GetClipMaxY+16<GetY)
	{
		SetDamageRate(0,0);
	}
	else
	{
		if(GetDistanceToPlayer<=SRange)
		{
			DamegeCoefficient=1.2;
		}
		else if(GetDistanceToPlayer<=LRange)
		{
			DamegeCoefficient=1+0.2*(GetDistanceToPlayer-LRange)/(SRange-LRange);
		}
		else
		{
			DamegeCoefficient=1.0;
		}
		SetDamageRate(DamageRate*DamegeCoefficient*ArrangeDamageRate,BombDamageRate*ArrangeBombDamageRate);
	}
	if(LifeCheckCount%30==0)
	{
	if(GetLife<=PastLife-500 && !OnBomb)
	{
		SetCommonData("BalanceBreak",true);
	}
	PastLife=GetLife;
	}

	LifeCheckCount+=1;
yield;
}

}

task GetDamege
{
MagicCircle(false);
GetDamegeItem;
loop
{
	if(GetHitCount!=0)
	{
		ZakoColor=[150,150,255];
		SetColor(150,150,255);
		wait(10);
	}
	else
	{
		ZakoColor=[255,255,255];
		SetColor(255,255,255);
	}
yield;
}
}

task GetDamegeItem
{
//let SRange=GetCommonData("MagicAbsorbShortRange");
let SRange=60;
let BaseSRange=60;
alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
case("Apocalypse")
{
	SRange*=1.2;
}
loop
{
		SRange=BaseSRange*(1+0.2*GetCommonDataDefault("RUSHGAUGE",0)/1000);
		if(GetHitCount!=0 && GetDistanceToPlayer<=SRange)
		{
		if(GetCommonDataDefault("MSDPlayer",false)==false && GetCommonDataDefault("SELECTEDDIFFICULT","None")!="Arrange")
		{
			AddScore(10000);
			AddPoint(1);
			if(GetTimeOfSuperNaturalBorder>0)
			{
				let SpiritItemRate=trunc(0.5+2.5*GetCommonData("SpiritRank")/10000);
				AddScore(10000*SpiritItemRate);
				AddPoint(1*SpiritItemRate);
			}
			SpiritSet(1.0);
		}
		else
		{
			if(GetCommonData("BURSTLEVEL")==0)
			{
				loop(2)
				{
				ItemSet(GetX,GetY,2);
				}
			}
			if(GetCommonData("BURSTLEVEL")==3)
			{
				loop(2)
				{
				ItemSet(GetX,GetY,8);
				}
			}
		}
		}
		else if(GetHitCount!=0)
		{
			SpiritSet(0.05);
		}
yield;
}
}

function FinalizeItemSet(num)
{
let type;
alternative(GetCommonDataDefault("BURSTLEVEL",0))
case(0)
{
	type=3;
}
case(3)
{
	type=5;
}
		if(!BeVanished)
		{
		loop(num)
		{
			ItemSet(GetX,GetY,type);
			if(GetCommonDataDefault("MAGICCOUNTER",0)>=10000)
			{
				ItemSet(GetX,GetY,type);
			}
			if(GetDistanceToPlayer<=GetCommonDataDefault("MagicAbsorbShortRange",0))
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetDistanceToPlayer<=GetCommonDataDefault("MagicAbsorbLongRange",0))
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetCommonDataDefault("MAGICPOWER",0)>=1000)
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Apocalypse")
			{
				ItemSet(GetX,GetY,9);
			}
		}
		}
}

function ItemSet(x,y,type)//アイテム生成関数
{
	let XY=GetCommonDataDefault("ItemXY",[]);//共通データ内容を変数に渡す
	XY=XY~[x,y,type];//
	SetCommonData("ItemXY",XY);//共通データに変更後の配列を渡す
}

function ExtendItemSet(x,y,type)//アイテム生成関数
{
	let XY=GetCommonDataDefault("ExtendItem",[]);//共通データ内容を変数に渡す
	XY=XY~[x,y,type];//
	SetCommonData("ExtendItem",XY);//共通データに変更後の配列を渡す
}

function SpiritSet(num)//アイテム生成関数
{
	let XY=GetCommonDataDefault("SpiritGain",[]);//共通データ内容を変数に渡す
	XY=XY~[num];//
	SetCommonData("SpiritGain",XY);//共通データに変更後の配列を渡す
}

function SpellDraw(num,time)//アイテム生成関数
{
	if(IsReplay)
	{
	let XY=GetCommonDataDefault("SpellDraw",[]);//共通データ内容を変数に渡す
	XY=XY~[num,time];//
	SetCommonData("SpellDraw",XY);//共通データに変更後の配列を渡す
	}
}

sub SpellDrawStop
{
	SetCommonData("SpellDrawStop",true);
}

function MagicCircleBreak(x,y,type,scale)//アイテム生成関数
{
	if(!BeVanished)
	{
	let XY=GetCommonDataDefault("MagicCircleBreak",[]);//共通データ内容を変数に渡す
	XY=XY~[x,y,type,scale];//
	SetCommonData("MagicCircleBreak",XY);//共通データに変更後の配列を渡す
	}
}

function MoveToPlayer02(xMove, yAdd, frame, left, top, right, bottom)
{
	let x;
	let y;

	if(GetPlayerX < GetX)
	{
		x = GetX - xMove;
		if(x < left)
		{
		x = GetX + xMove;
		}
	}
	else
	{
		x = GetX + xMove;
		if(right < x)
		{
			x = GetX - xMove;
		}
	}

	y = GetY + yAdd;
	if(y < top)
	{
		y = top;
	}
	else if(bottom < y)
	{
		y = bottom;
        }

        SetMovePosition02(x, y, frame);
	SetAction(ACT_MOVE,60);
}

function MoveToPlayer03(xMove, yAdd, weight,maxspeed, left, top, right, bottom)
{
	let x;
	let y;

	if(GetPlayerX < GetX)
	{
		x = GetX - xMove;
		if(x < left)
		{
		x = GetX + xMove;
		}
	}
	else
	{
		x = GetX + xMove;
		if(right < x)
		{
			x = GetX - xMove;
		}
	}

	y = GetY + yAdd;
	if(y < top)
	{
		y = top;
	}
	else if(bottom < y)
	{
		y = bottom;
        }

        SetMovePosition03(x, y, weight,maxspeed);
	SetAction(ACT_MOVE,60);
}


///////////////////////////////////////////////////////////////////////////////////////////
	let csd = GetCurrentScriptDirectory;
	let imgLetter =csd ~ "img/border.png"; 
	let BulletNum;
	let ZakoColor=[255,255,255];
	let ZakoMagicColor=[255,255,255];
////////////////////////////////////////////////////////////////////////////////////////////
task Concentration03(x,y,frame,R,G,B)
{
//Concentration03CircleEffect(frame,R,G,B);

if(frame<31){return;}
loop(frame-30)
{
	Concentration03Effect(x,y,R,G,B);
	Concentration03Effect(x,y,R,G,B);
	yield;
}

}

task Concentration03Effect(x,y,R,G,B)
{
		let Rudius=rand(100,250);
		let StandardRudius=Rudius;
		let Angle=rand(0,360);
		let RotateAngle=rand(2,10);
		let Zangle=rand(0,360);
		let dir=rand_int(0,1)*2-1;
		let MinScale=0.5;
		let Scale=rand(0.5,2.0);
		let StandardScale=Scale;
		let Alpha=40;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, GetCurrentScriptDirectory~"..\img/effect_tiny.png");
		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,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  32, 0);
		ObjEffect_SetVertexUV(obj, 2, 32,  32);
		ObjEffect_SetVertexUV(obj, 3, 0, 32);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		Obj_SetPosition(obj,GetX+Rudius*cos(Angle),GetY+Rudius*sin(Angle));
		Obj_SetAngle(obj,Angle);

		ascent(let i in 0..30)
		{
			ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);
			Obj_SetPosition(obj,x+Rudius*cos(Angle),y+Rudius*sin(Angle));
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ObjEffect_SetScale(obj, Scale+MinScale,Scale+MinScale);
			Rudius-=StandardRudius/35;
			Zangle+=RotateAngle*dir;
			Scale-=StandardScale/35;
			if(i>20)
			{
			Alpha-=4;
			}
			yield;
		}
		Obj_Delete(obj);
}

task Concentration03CircleEffect(let frame,R,G,B)
{
		let Scale=0.8;
		let StandardScale=Scale;
		let Alpha=80;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd~"..\img\CircleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -256, -256);
		ObjEffect_SetVertexXY(obj, 1, 256,  -256);
		ObjEffect_SetVertexXY(obj, 2, 256, 256);
		ObjEffect_SetVertexXY(obj, 3,  -256,  256);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  48, 0);
		ObjEffect_SetVertexUV(obj, 2, 48,  48);
		ObjEffect_SetVertexUV(obj, 3, 0, 48);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		Obj_SetPosition(obj,GetX,GetY);

		ascent(let i in 0..frame)
		{
			ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);
			ObjEffect_SetScale(obj, Scale,Scale);
			Scale-=StandardScale/frame;
			yield;
		}
		Obj_Delete(obj);
}

task Obj_SetMovePosition03(obj,EndX,EndY,Weight,MaxSpeed)
{
	let Angle=atan2(EndY-Obj_GetY(obj),EndX-Obj_GetX(obj));
	let MoveDistance=((EndY-Obj_GetY(obj))^2+(EndX-Obj_GetX(obj))^2)^0.5;
	let Distance=0;
	let Cspeed=MaxSpeed;
	let e=2.71828;
	let count=0;
 	while(Cspeed>MaxSpeed/20)
	{
		Distance=((EndY-Obj_GetY(obj))^2+(EndX-Obj_GetX(obj))^2)^0.5;
		if(MoveDistance>MaxSpeed*Weight)
		{
			if(Distance>MaxSpeed*Weight)
			{
				Cspeed=MaxSpeed;
			}
			else
			{
				Cspeed=MaxSpeed*e^(-count/Weight);
				count+=1;
			}
		}
		else
		{
			Cspeed=Distance/Weight*e^(-count/Weight);
			count+=1;
		}
		Obj_SetX(obj,Obj_GetX(obj)+Cspeed*cos(Angle));
		Obj_SetY(obj,Obj_GetY(obj)+Cspeed*sin(Angle));
               	yield;
	}
}

task BossTimer(time)
{
let scale=0.5;
let R=255;let G=255;let B=255;
loop(time)
{
	TimeNumDisplay(413,19,time*100/60,255,R,G,B,scale);
	time-=1;
	if(time<=600 && time%60==0)
	{
		scale=0.65;
	}
	if(scale>0.5){scale-=0.01;}
	if(time<=300){R=255;G=0;B=0;}
	else if(time<=600){R=255;G=80;B=80;}
	yield;
}
//SetCommonData("VanishSignal",true);
yield;
//VanishEnemy;

SetCommonDataEx(NsScore,NsAchievement[70],1);
AddLife(-GetLife);
}

task TimeNumDisplay(let x,let y,let number,Alpha,R,G,B,sc)
{
let num=[];
ascent(let k in 0..5)
{
num = num ~ [k];
}
	num[0]=trunc(number%10);
	num[1]=trunc(number%100/10);
	num[2]=trunc(number%1000/100);
	num[3]=trunc(number%10000/1000);
	num[4]=trunc(number%100000/10000);

if(num[4]!=0)
{
	ascent(i in 0..4)
	{
		num[i]=9;
	}
}
	ascent(let i in 0..2)
	{
			TimeDisplayNumLetter(x-(i)*9-2.5,y+6,num[i],0.35,Alpha,R,G,B);
	}
	ascent(let i in 2..4)
	{
			TimeDisplayNumLetter(x-(i)*10-7,y+3.5,num[i],sc,Alpha,R,G,B);
	}
	TimeDisplayNumLetter(x-(3-1)*12+8,y+2,10,0.6,Alpha,R,G,B);
}

task TimeDisplayNumLetter(let x,let y,let num,scale,Alpha,R,G,B)
{
		let scx=scale;
		let scy=scale;
		let obj0 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj0,csd~"..\img\Number.png");
		ObjEffect_SetPrimitiveType(obj0, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj0, ADD); 
		ObjEffect_CreateVertex(obj0, 4);
		ObjEffect_SetVertexXY(obj0, 0, -13, -16);
		ObjEffect_SetVertexXY(obj0, 1, 13,  -16);
		ObjEffect_SetVertexXY(obj0, 2, 13, 16);
		ObjEffect_SetVertexXY(obj0, 3,  -13,  16);
		
		ObjEffect_SetVertexUV(obj0, 0,  0+40*num,  6);
		ObjEffect_SetVertexUV(obj0, 1,  26+40*num, 6);
		ObjEffect_SetVertexUV(obj0, 2, 26+40*num,  38);
		ObjEffect_SetVertexUV(obj0, 3, 0+40*num, 38);

		ObjEffect_SetVertexColor(obj0,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj0,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj0,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj0,3,Alpha,R,G,B);
	
		ObjEffect_SetScale(obj0, scx,scy);
		Obj_SetPosition(obj0,x,y+5);
		ObjEffect_SetLayer(obj0,3);
		wait(1);
		Obj_Delete(obj0);
}

let imgEnemy=csd~"..\img\minion.png";
LoadGraphic(imgEnemy);

/*
task NewCharge(time,size,frequency,r,g,b)
{
let count=0;
loop(time-20)
{
	if(count>=1)
	{
	ChargeEffect2(GetX,GetY,size,r,g,b);
	count-=1;
	}
	count+=frequency;
	yield;
}
}

task NewChargeShrink(time,size,frequency,r,g,b)
{
let count=0;
let sizeadd=size/time;
loop(time)
{
	if(count>=1)
	{
	ChargeEffect2(GetX,GetY,size,r,g,b);
	count-=1;
	}
	count+=frequency;
	yield;
	size-=sizeadd;
}
}

task ChargeEffect2(x,y,size,r,g,b)
{
	let obj = Obj_Create(OBJ_EFFECT);
	Obj_SetAngle(obj, 0);ObjEffect_SetTexture(obj,imgEnemy);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetLayer(obj,3);
	ObjEffect_SetRenderState(obj,ADD);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetVertexXY(obj,0,-16,0);
	ObjEffect_SetVertexXY(obj,1,16,0);
	ObjEffect_SetVertexXY(obj,2,16,32);
	ObjEffect_SetVertexXY(obj,3,-16,32);
	ObjEffect_SetVertexUV(obj, 0, 1, 97);
	ObjEffect_SetVertexUV(obj, 1, 31, 97);
	ObjEffect_SetVertexUV(obj, 2, 31, 127);
	ObjEffect_SetVertexUV(obj, 3, 1, 127);
	Obj_SetAutoDelete(obj,false);

	let alpha=0;
	let rotation=rand(-1,1);
	let angle=rand(0,360);

	let scx=0.3;
	let scy=size;

	let Bsize=size;

	Obj_SetPosition(obj,x,y);

	ObjEffect_SetScale(obj,scx,scy);

	Obj_SetPosition(obj,x+32*size*cos(angle),y+32*size*sin(angle));

	size=0;
	let time=10*2;

	loop(time)
	{
		Obj_SetPosition(obj,x+32*Bsize*cos(angle),y+32*Bsize*sin(angle));
		ObjEffect_SetAngle(obj,0,0,angle+90);
		ObjEffect_SetScale(obj,scx,size);
	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(obj, i, alpha, r,g,b);
	}

	//	angle+=rotation;
		size+=Bsize/time;
		alpha+=200/time;
		yield;
	}

alpha=200;
size=Bsize;
	loop(time)
	{
		Obj_SetPosition(obj,x+32*size*cos(angle),y+32*size*sin(angle));
		ObjEffect_SetAngle(obj,0,0,angle+90);
		ObjEffect_SetScale(obj,scx,size);
	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(obj, i, alpha, r,g,b);
	}
	//	angle+=rotation;
		size-=Bsize/time;
		alpha-=200/time;
		yield;
	}
    Obj_Delete(obj);
}
*/

task NewCharge(time,size,frequency,r,g,b){
let frame=0;
let Bsize=size;
loop(time){
	if(frame>=1){
		ChargeEffect2(GetX,GetY,size,r,g,b,false);
		frame-=1;
	}
	frame+=frequency;
	//size-=Bsize/time;
	yield;
}
}

task NewCharge_XY(x,y,time,size,frequency,r,g,b){
let frame=0;
loop(time){
	if(frame>=1){
		ChargeEffect2(x,y,size,r,g,b,true);
		frame-=1;
	}
	frame+=frequency;
	yield;
}
}


task ChargeEffect2(x,y,size,r,g,b,remote)
{
	size*=rand(0.8,1.2);
	let obj = Obj_Create(OBJ_EFFECT);

	Obj_SetAngle(obj, 0);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, 1, 97);
	ObjEffect_SetVertexUV(obj, 1, 31, 97);
	ObjEffect_SetVertexUV(obj, 2, 31, 127);
	ObjEffect_SetVertexUV(obj, 3, 1, 127);
	Obj_SetAutoDelete(obj,false);

	ObjEffect_SetLayer(obj,2);

	Obj_SetPosition(obj,x,y);

	let rot=rand(-3,3);
	let count=0;
	let Alpha=0;
	let AlphaMax=rand(50,200);
	let angle=rand(0,360);

	let scx=rand(0.3,0.3);
	let scy=size;
	let Bscy=scy;

	let time=30;
	loop(time)
	{
	//ChargeEffectBlur(x,y,scx,scy,angle,r,g,b,remote);
	if(!remote)
	{
		Obj_SetPosition(obj,GetX,GetY);
	}

	ObjEffect_SetAngle(obj,0,0,angle+90);

	ObjEffect_SetScale(obj,scx,scy*4);

	scy-=Bscy/time;

	angle+=rot;

	if(count<=time/2){Alpha+=AlphaMax/time;}
	else{Alpha-=AlphaMax/time;}
	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(obj, i, Alpha, r,g,b);
	}

	count+=1;
        yield;

    }
    Obj_Delete(obj);
}

task ChargeEffectBlur(x,y,scx,scy,angle,r,g,b,remote)
{
	let obj = Obj_Create(OBJ_EFFECT);

	Obj_SetAngle(obj, 0);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, 1, 97);
	ObjEffect_SetVertexUV(obj, 1, 31, 97);
	ObjEffect_SetVertexUV(obj, 2, 31, 127);
	ObjEffect_SetVertexUV(obj, 3, 1, 127);
	Obj_SetAutoDelete(obj,false);

	ObjEffect_SetLayer(obj,2);

	Obj_SetPosition(obj,x,y);

	ObjEffect_SetAngle(obj,0,0,angle+90);
	ObjEffect_SetScale(obj,scx*1.5,scy*4);

	let Alpha=100;
	let time=10;
	loop(time)
	{
	if(!remote)
	{
		Obj_SetPosition(obj,GetX,GetY);
	}
	Alpha-=100/time;
	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(obj, i, Alpha, r,g,b);
	}
        yield;

    }
    Obj_Delete(obj);
}