
task SpellBG(tobj, graphic, XSource, YSource){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, graphic);
	Obj_SetRenderPriorityI(obj,22);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj,230);
	ObjSprite2D_SetSourceRect(obj,0,0,453, 279);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	ObjRender_SetScaleXYZ(obj, 2.2, 2.2, NULL);
	ObjRender_SetColor(obj, 104, 104, 250);
	
	SpinBG;
	
	task SpinBG {
		let spin = 5;
		let spin1 = 130;
		let allow=0;
	
			
		while(!Obj_IsDeleted(tobj)){
		
			ObjRender_SetAngleXYZ(obj, 0, 0, 45);
		
			ObjSprite2D_SetSourceRect(obj,spin,0,XSource+spin,YSource);
			
			spin-=1.2;
			
			yield;
			}
			
		Obj_Delete(obj);
		}
	}
	
task KonnBG(tobj, graphic, graphic1, scrollspeedX, scrollspeedY, sourceX, sourceY, sourceX1, sourceY1, scale, scale1){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, graphic);
	Obj_SetRenderPriorityI(obj,21);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj,120);
	ObjSprite2D_SetSourceRect(obj,0,0,sourceX, sourceY);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	ObjRender_SetScaleXYZ(obj, scale, scale, NULL);
	ObjRender_SetColor(obj, 104, 104, 200);
	
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj1, graphic1);
	Obj_SetRenderPriorityI(obj1,23);
	ObjRender_SetBlendType(obj1,BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj1,250);
	ObjSprite2D_SetSourceRect(obj1,0,0,sourceX1, sourceY1);
	ObjSprite2D_SetDestCenter(obj1);
	ObjRender_SetPosition(obj1,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	ObjRender_SetScaleXYZ(obj1, scale1, scale1, NULL);
	//ObjRender_SetColor(obj1, 104, 104, 250);
	
	SpinBG;
	
	task SpinBG {
		let spin = 0;
		let spin1 = 0;
		let allow=0;
		let ALPHA = 200;
	
			
		while(!Obj_IsDeleted(tobj)){
		
			ObjRender_SetAngleXYZ(obj1, 0, 0, 90);
		
			//ObjSprite2D_SetSourceRect(obj,spin,0,sourceX*4+spin,sourceY*3+spin1);
			ObjSprite2D_SetSourceRect(obj1,spin,0,sourceX1*4+spin,sourceY1*3+spin1);
			
			spin+=scrollspeedX;
			spin1+=scrollspeedY;
			
			ObjRender_SetAlpha(obj, ALPHA);
			
			if(ALPHA >=255){
				allow=0;
				}
				
			if(ALPHA<=120){
				allow=1;
				}
				
			if(allow==0){
				ALPHA-=0.2;
				}
			if(allow==1){
				ALPHA+=10.5;
				}
				
			yield;
			}
			
		Obj_Delete(obj);
		Obj_Delete(obj1);
		}
	}
	
task SetSpecialDelete(tobj, graphic){
	let endX = ObjMove_GetX(tobj);
	let endY = ObjMove_GetY(tobj);
	while(!Obj_IsDeleted(tobj)){
		endY = ObjMove_GetY(tobj);
		endX = ObjMove_GetX(tobj);
		yield;
		}
	let obj = CreateShotA1(endX, endY, 0, 0, graphic, 20);
	ObjShot_SetDeleteFrame(obj, 0);
	}
	
task death(tobj) {

	Obj_Delete(tobj);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	
	loop(100){	
		DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
		
		yield;
		}
		
	Obj_Delete(tobj);
		
	CloseScript(GetOwnScriptID());
	
	return;
	
	}
	
task MCircle(tobj, type){

	let NORM = "NORMAl";
	let SPELL = "SPELL";
	let graphic = GetCurrentScriptDirectory ~ "circle.png";


	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, graphic);
	Obj_SetRenderPriorityI(obj,40);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,130);
	ObjSprite2D_SetSourceRect(obj,0,0,256, 256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,ObjMove_GetX(tobj),ObjMove_GetY(tobj),0);
	ObjRender_SetScaleXYZ(obj, 1, 1, NULL);
	ObjRender_SetColor(obj, 255, 0, 0);
	let rotate=0;
	let scale = 1;
	let allow=0;
	
	let Y = 0;
	
	while(!Obj_IsDeleted(tobj)){
		ObjRender_SetPosition(obj,ObjMove_GetX(tobj),ObjMove_GetY(tobj),0);
		ObjRender_SetAngleXYZ(obj, -0, 0, rotate);
		ObjRender_SetScaleXYZ(obj, scale, scale, 1.5);
		
		if(allow==1){
			scale-=0.006;
			}
		if(allow==0){
			scale+=0.006;
			}
		if(scale>=1){
			allow=1;
			}
		if(scale<0.6){
			allow=0;
			}
			
		rotate+=5;
		Y+=sin(rotate)*1.7;
		
		
			
		yield;
		}
		
	Obj_Delete(obj);
	}
		
	
task CreateShotJ1(X, Y, Speed, Angle, Graphic, Delay){

	let delay = CreateShotA1(X, Y, 0, Angle, Graphic, 0);
	ObjShot_SetIntersectionEnable(delay, false);
	ObjShot_SetSpellResist(delay, true);
	ObjShot_SetAutoDelete(delay, false);
	
	let alpha = 0;
	ObjRender_SetAlpha(delay, alpha);
	
	let DELAY = Delay/10;
	
	ObjRender_SetScaleXYZ(delay, 1+DELAY, 1+DELAY, NULL);
	
	loop(Delay){
		ObjRender_SetScaleXYZ(delay, 1+DELAY, 1+DELAY, NULL);
		DELAY-= (Delay/10)/Delay;
		ObjRender_SetAlpha(delay, alpha);
		alpha+= 255/Delay;
		yield;
		}
		
	Obj_Delete(delay);
		
	let obj = CreateShotA1(X, Y, Speed, Angle, Graphic, 0);
	
	//return obj;
	}
	
task ExplosionType1(X, Y, min, max, RB, RM, GB, GM, BB, BM){
	
	loop(3){
		let angle = rand(0, 360);
		
		loop(6){
			Sakura(X, Y, angle, rand(RB, RM), rand(GB, GM), rand(BB, BM), rand(min, max));
			angle+=360/6;
			}
		
		yield;
		}
	
	}
	
task ExplosionType2(tobj, min, max){
	let X = ObjMove_GetX(tobj);
	let Y = ObjMove_GetY(tobj);
	loop(20){
		let angle = rand(0, 360);
		
		loop(14){
			Sakura2(X, Y, angle, rand(min, max));
			angle+=360/6;
			}
		
		loop(8){
			yield;
			}
		}
	
	}
	
task Sakura(X, Y, angle, R, G, B, dist){
		let graphic = GetCurrentScriptDirectory ~ "sakura.png";
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, graphic);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		ObjRender_SetAlpha(obj,200);
		ObjSprite2D_SetSourceRect(obj,0,0,64, 64);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj,X,Y,0);
		ObjRender_SetScaleXYZ(obj, rand(0.2, 1), rand(0.2, 1), NULL);
		ObjRender_SetColor(obj, R, G, B);
		
		let angleX = rand(0, 360);
		let angleY = rand(0, 360);
		let angleZ = rand(0, 360);
		
		let DIST = 0;
		let alpha = 255;
		while(!Obj_IsDeleted(obj)){
			ObjRender_SetPosition(obj, X+DIST*cos(angle), Y+DIST*sin(angle), 0);
			
			ObjRender_SetAngleXYZ(obj, angleX, angleY, angleZ);
			DIST+=dist/20;
			
			angleX++;
			angleY++;
			angleZ++;
			
			ObjRender_SetAlpha(obj, alpha);
			
			alpha-=255/40;
			
			if(alpha<=0){
				Obj_Delete(obj);
				}
			yield;
			}
		}
		
task Sakura2(X, Y, angle, dist){
		let graphic = GetCurrentScriptDirectory ~ "sakura.png";
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, graphic);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		ObjRender_SetAlpha(obj,200);
		ObjSprite2D_SetSourceRect(obj,0,0,64, 64);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj,X,Y,0);
		ObjRender_SetScaleXYZ(obj, rand(0.2, 1), rand(0.2, 1), NULL);
		ObjRender_SetColorHSV(obj, rand(0, 239), 240, 250);
		
		let angleX = rand(0, 360);
		let angleY = rand(0, 360);
		let angleZ = rand(0, 360);
		
		let DIST = 0;
		let alpha = 255;
		while(!Obj_IsDeleted(obj)){
			ObjRender_SetPosition(obj, X+DIST*cos(angle), Y+DIST*sin(angle), 0);
			
			ObjRender_SetAngleXYZ(obj, angleX, angleY, angleZ);
			DIST+=dist/20;
			
			angleX++;
			angleY++;
			angleZ++;
			
			ObjRender_SetAlpha(obj, alpha);
			
			alpha-=255/40;
			
			if(alpha<=0){
				Obj_Delete(obj);
				}
			yield;
			}
		}
		
task Flash(obj)
{
    let count = 0;
    while(!Obj_IsDeleted(obj))
    {
         let value = 192+64*sin(count*6);
         ObjRender_SetColor(obj,value,value,value);
         count++;
         yield;
    }
}

function CreateShotAdd1(X, Y, Speed, Angle, Graphic, Delay){
	let obj = CreateShotA1(X, Y, Speed, Angle, Graphic, Delay);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	
	return obj;
	}
	
task Logo(number, r, g, b){
	let graphic;
	
	if(number==1){
		graphic = GetCurrentScriptDirectory ~ "stg1logo.png";
		}
		
	if(number==2){
		graphic = GetCurrentScriptDirectory ~ "stg2logo.png";
		}
		
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, graphic);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(obj,0,0,512, 128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2+10,140,0);
	ObjRender_SetScaleXYZ(obj, 0.76, 0.78, NULL);
	
	let graphic1 = GetCurrentScriptDirectory ~ "logo.png";
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj1, graphic1);
	Obj_SetRenderPriorityI(obj1,29);
	ObjRender_SetBlendType(obj1,BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(obj1,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj1);
	ObjRender_SetPosition(obj1,0,140,0);
	ObjRender_SetScaleXYZ(obj1, -0.4, 0.4, NULL);
	ObjRender_SetColor(obj1, r, g, b);
	let X = 0;
	let alpha = 0;
	let spin = 0;
	let time = 0;
	loop(300){
		if(X<GetStgFrameWidth/2+80){
			X+=(GetStgFrameWidth/2+80)/100;
			ObjRender_SetPosition(obj1,X,140,0);
			ObjRender_SetAlpha(obj1, alpha);
			ObjRender_SetAlpha(obj, alpha);
			alpha+=255/100;
			ObjRender_SetAngleXYZ(obj1, 0, 0, spin);
			spin+=360/100;
			}
			
		time++;
		
		if(time>=200){
			ObjRender_SetAlpha(obj1, alpha);
			ObjRender_SetAlpha(obj, alpha);
			X+=(GetStgFrameWidth/2+80)/100;
			ObjRender_SetPosition(obj1,X,140,0);
			alpha-=255/100;
			ObjRender_SetAngleXYZ(obj1, 0, 0, spin);
			spin+=360/100;
			}
		yield;
		}
		
	Obj_Delete(obj);
	Obj_Delete(obj1);
	}
	
	
task Concentration_True(X, Y, Angle, Num, Dist, Type1, Type2, Dir, Time, tobj){
	
	loop(20){
		loop(Num){
			Conc_Eff(X, Y, Angle+180, Dist, Dir, Type1, true, Time, tobj);
			Conc_Eff(X, Y, Angle, Dist, Dir, Type2, false, Time, tobj);
			Angle+=360/Num;
			}
			
		Angle-=Dir*2;
		
		Dist+=8;
		
		loop(3){
			yield;
			}
		}
		
	}
	
task ConcentrationReverse(X, Y, Angle, Num, Dist, Type, Dir, Time, tobj){
	//let Angle = 90;
	loop(20){
		loop(Num){
			Conc_Eff(X, Y, Angle, Dist, Dir, Type, true, Time, tobj);
			Angle+=360/Num;
			}
			
		Angle-=Dir*2;
		
		Dist+=8;
		loop(3){
			yield;
			}
			
		}
	
	}
	
task ConcentrationStandard(X, Y, Angle, Num, Dist, Type, Dir, Time, tobj){
	//let Angle = 90;
	loop(20){
		loop(Num){
			Conc_Eff(X, Y, Angle, Dist, Dir, Type, false, Time, tobj);
			Angle+=360/Num;
			}
			
		Angle-=Dir*2;
		Dist+=8;
		loop(3){
			yield;
			}
			
			
			
		}
	
	}
	
task Conc_Eff(X, Y, Angle, Dist, Dir, Type, RCheck, Time, tobj){
	let dist = Dist;
	let time = Time;
	let graphic = GetCurrentScriptDirectory ~ "power_effect.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, graphic);
	Obj_SetRenderPriorityI(obj,28);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(obj,256/8*(Type-1),0,256/8*Type, 32);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, X+dist*cos(Angle), Y+dist*sin(Angle), 0);
	ObjRender_SetScaleXYZ(obj, 2.2, 2.2, NULL);
	
	let Alpha = 0;
	let Angle1 = rand(0, 360);
	
	if(RCheck==true){
		ObjRender_SetBlendType(obj,BLEND_SUBTRACT);
		}
		
	while(!Obj_IsDeleted(tobj)){
		if(time>0){
			ObjRender_SetPosition(obj, X+dist*cos(Angle), Y+dist*sin(Angle), 0);
			dist-=Dist/Time;
			Angle+=Dir;
			time--;
			}
			
		else{
			Obj_Delete(obj);
			return;
			}
			
		ObjRender_SetAlpha(obj, Alpha);
		ObjRender_SetAngleZ(obj, Angle1);
		
		Alpha+=255/(Time/2);
		Angle1+=3;
			
		yield;
		}
	
	Obj_Delete(obj);
	}