#TouhouDanmakufu[Single]
#ScriptVersion[3]
#System["./system/Default_System.txt"]

#include"./Effects_Main.txt"

let current = GetCurrentScriptDirectory;
let enm = ID_INVALID;
let GetX = 0;
let GetY = 0;
let EnemyX = 0;
let EnemyY = 0;

let s=1;
let angle2=0;
let c=6; let c2=15; let c3=7;



@Event{
	alternative(GetEventType)
	//1;500;2500
	case(EV_REQUEST_LIFE){SetScriptResult(5200);}
	case(EV_REQUEST_TIMER){SetScriptResult(38);}
	

}

// your best friend, forever.
function wait(w) { loop(w) { yield; } } 

@Initialize{

		ObjEnemy_SetDamageRate(enm, 100, 100);


	SetAutoDeleteObject(true);
	enm = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(enm);
	CreateLifeBar(enm, 50, 54, 41, 0, [255,255,255], "Normal" , [false,false] );
	
AnimeKutakaWBaWC(enm);
//AnimeUrumiWBaWC(enm);
	TAura(enm, 0);
//BossIndicator(enm);

//ChargeUp(enm, [GetStgFrameWidth/2,  GetStgFrameHeight/2-80], -9,3, angle, 50, 20, [255, 0, 0], "DARK");	
	ObjMove_SetDestAtWeight(enm, GetStgFrameWidth/2, GetStgFrameHeight/2-80, 12, 6);
	Invincible(200);
	BossActions;
}


@MainLoop{
	GetX = ObjMove_GetX(enm);
	GetY = ObjMove_GetY(enm);
EnemyX = ObjMove_GetX(enm);
	EnemyY = ObjMove_GetY(enm);
	ObjEnemy_SetIntersectionCircleToShot(enm, GetX, GetY, 32);
	ObjEnemy_SetIntersectionCircleToPlayer(enm, GetX, GetY, 24);
	yield;
}

task BossActions{

	
	wait(30);
	PerformActions;
	while(ObjEnemy_GetInfo(enm, INFO_LIFE) > 0){
		yield;
	}
	
	Obj_Delete(enm);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	yield;
	CloseScript(GetOwnScriptID);
	
	task PerformActions{
	
	loop(30){yield;}
let angle = -90;
let angle2 = 0;
let s=1;
let time=0; let i=0; 
let sprite=[LARGE_GREEN, LARGE_YELLOW];
let t=-0.05;
if (GetCommonData("rank", "Normal")=="Normal"){c=6; c2=15; c3=3;}
else{c=8; c2=18; c3=5;}
	let dir = -90;
	let dir2 = -90;
	let dir3= 90;
	let D=45;
	wait(60);
	CallGhost;
	slowbullet;
	
	while(!Obj_IsDeleted(enm)){
	let ang1=rand(0,360);
	let ang2=rand(0,360);
	
		ChargeUp(enm, [ObjMove_GetX(enm), ObjMove_GetY(enm)], -12,2, angle, 10, 15, [229, 18, 18], "DARK");
		ChargeUp(enm, [ObjMove_GetX(enm), ObjMove_GetY(enm)], 12,2, angle, 10, 15, [18, 218, 229], "DARK");
		wait(60);
		Action1(ang1);
			
		DupeAction1(ang1);
		wait(105);
		TMovement(35,5,4);
		Action2(ang2);
		DupeAction2(ang2);
		wait(65);
		
		ang1*=-1;
		ang2*=-1;
		TMovement(35,5,2);
		wait(70);
		
	}
		//Obj_SetValue(enm,"cast",1);
		//Action2;

		
		
function angleToPlayer {
	let dir = atan2(GetPlayerY-GetY,GetPlayerX-GetX);
	return dir;
}


}}

task Action1(ang){
	let aBullet=1;
	//let ang=-10;
	let posX=65;
	ascent(j in 0..60){
		PlaySoundEffect("se_tan01");
	ascent(i in 0..aBullet){
		CreateShotA4(EnemyX+posX*sin(ang),EnemyY-45*cos(ang),1.75-0.05*i,ang,PELLET_ORANGE,15,1.25-0.05*i);
		ang+=0.75;
		
	}
	posX+=-1;
	if(aBullet>=4){aBullet+=-1;}
	aBullet+=1;
	ang+=7.5;
	wait(2);
	}
}

task DupeAction1(ang){
	let aBullet=1;
	//let ang=-10;
	let posX=65;
	ascent(j in 0..60){
		PlaySoundEffect("se_tan01");
	ascent(i in 0..aBullet){
		CreateShotA4(EnemyX+posX*sin(ang),EnemyY-45*cos(ang),2-0.05*i,ang,PELLET_ORANGE,15,1.25-0.05*i);
		ang+=-0.75;
		
	}
	posX+=-2;
	if(aBullet>=4){aBullet+=-1;}
	aBullet+=1;
	ang+=-7.5	;
	wait(2);
	}
}

task Action2(ang){
	let aBullet=1;
	//let ang=180;
	let posX=125;
	let posY=65;
	ascent(j in 0..70){
		PlaySoundEffect("se_tan01");
		
	ascent(i in 0..aBullet){
		CreateShotA4(EnemyX+posX*cos(ang),EnemyY+posY*sin(ang),1.75-0.05*i,ang,PELLET_RED,15,1.25-0.01*i);
		ang+=0.5;
		
	}
	posX+=-2;
	posY+=-1;
	if(aBullet>=6){aBullet+=-1;}
	aBullet+=1;
	ang+=8;
	wait(2);
	}
}

task DupeAction2(ang){
	let aBullet=1;
	//let ang=180;
	let posX=125;
	let posY=65;
	ascent(j in 0..70){
		PlaySoundEffect("se_tan01");
		
	ascent(i in 0..aBullet){
		CreateShotA4(EnemyX+posX*cos(ang),EnemyY+posY*sin(ang),1.75-0.05*i,ang,PELLET_RED,15,1.25-0.01*i);
		ang+=-0.5;
		
	}
	posX+=-2;
	posY+=-1;
	if(aBullet>=6){aBullet+=-1;}
	aBullet+=1;
	ang+=-8;
	wait(2);
	}
}

task CallGhost{
	wait(40);
	while(!Obj_IsDeleted(enm)){
	PlaySoundEffect("se_boon00");
	
	let GhostA1=CreateGhost(EnemyX+rand(-90,-40),EnemyY+rand(-120,40),260,0,true);
	
	ObjMove_SetSpeed(GhostA1,0);
	ObjMove_SetAngle(GhostA1,90+rand(-5,5));
	ObjMove_SetAcceleration(GhostA1,0.01);
	ObjMove_SetMaxSpeed(GhostA1,1.25);
	ShotAdding(GhostA1);
	
	let GhostA2=CreateGhost(EnemyX+rand(40,90),EnemyY+rand(-120,40),260,0,true);
	ObjMove_SetSpeed(GhostA2,0);
	ObjMove_SetAngle(GhostA2,90+rand(-5,5));
	ObjMove_SetAcceleration(GhostA2,0.01);
	ObjMove_SetMaxSpeed(GhostA2,1.25);
	ShotAdding(GhostA2);
	wait(150);
	}

	
	task ShotAdding(obj){
		let ang=270;
		while(!Obj_IsDeleted(obj)){
			
			CreateShotAB1(ObjMove_GetX(obj),ObjMove_GetY(obj),0,ang+rand(-10,10),SMALL_PURPLE+500,25);
			
			wait(10);
		}
		
	}
	
	task CreateShotAB1(x, y, speed, angle, graphic, delay){

DelayShot(x, y, graphic, angle, speed, BLEND_ADD_ARGB, 3, delay);
wait(delay);

let shota1=CreateShotA1(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle, graphic, 0);
ObjMove_AddPatternA2(shota1,80,NO_CHANGE,NO_CHANGE,0.03,0,2.75);
wait(80);
PlaySoundEffect("se_kira00");

}

}

task slowbullet{
	wait(220);

	while(!Obj_IsDeleted(enm)){
		ascent(j in 0..5){
			let ang=rand(0,360);
		PlaySoundEffect("se_kira00");
	ascent(i in 0..40){
		CreateShotA5(EnemyX+15*cos(ang),EnemyY+15*sin(ang),4,ang,rand(-0.15,-0.12),0.75,BL_SMALL_WHITE,10);
		
		ang+=360/40;
	}
	wait(30);
	}
	wait(45);
	}
}
task CreateShotA4(x, y, speed, angle, graphic, delay,maxspd){

DelayShot(x, y, graphic, angle, speed, BLEND_ADD_ARGB, 3, delay);
wait(delay);

let shota1=CreateShotA1(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle, graphic, 0);
ObjMove_AddPatternA2(shota1,30, NO_CHANGE,NO_CHANGE,-1,0,0);
ObjMove_AddPatternA2(shota1,32, NO_CHANGE,NO_CHANGE,0.03,0,maxspd);


}

task CreateShotA5(x, y, speed, angle,accel,maxspd, graphic, delay){

DelayShot(x, y, graphic, angle, speed, BLEND_ADD_ARGB, 3, delay);
wait(delay);
let shota1=CreateShotA2(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,accel,maxspd, graphic, 0);
ObjMove_AddPatternA2(shota1,60, NO_CHANGE,NO_CHANGE,0.05,0,1.5);

}

function CreateGhost(x,y,life,type,collision){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	let shot;
	let c = 0;
	let wi=65;
	let he=49;
	let a= SMALL_RED;
	
	ObjEnemy_Regist(obj);
	ObjMove_SetPosition(obj,x,y);
	ObjEnemy_SetLife(obj,life);
	TCharge01(x,y,2,30,255,255,255);
	ObjEnemy_SetDamageRate(obj,100,100);
	Control;
	DrawFam;
	//deletecorner(obj);
	//Fire;
	return obj;

		task Control{	
			//PlaySound("fam",100,0);
			while(!Obj_IsDeleted(obj)){
			c++;
			
			if(ObjEnemy_GetInfo(obj,INFO_LIFE) <=0){
			//PlaySound("famdie",90,0);
			//TExplosionA(ObjMove_GetX(obj),ObjMove_GetY(obj),10,0.3);
			Obj_Delete(obj);
			}
		
			if(collision==true){ObjEnemy_SetIntersectionCircleToShot(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),24);
			ObjEnemy_SetIntersectionCircleToPlayer(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),30);}
			yield;
			if(Obj_IsDeleted(enm)){Obj_Delete(obj);}
			}
		}
		task DrawFam{
			let fam=ObjPrim_Create(OBJ_SPRITE_2D);
			let px = 92;
			let py = 0;
			let c=0;
			let wi=32;
			let he=32;
			let img=GetCurrentScriptDirectory~"./img/ghost.png";
			ObjPrim_SetTexture(fam,img);
			
			Animate(fam);
			ObjRender_SetAngleXYZ(fam,0,0,c*2);
			ObjRender_SetPosition(fam,x,y,0);
			ObjRender_SetScaleXYZ(fam,1,1,0);
			ObjSprite2D_SetDestCenter(fam);
			ObjRender_SetBlendType(fam,BLEND_ALPHA);
			renderdrum(fam);
			renderalphafam(fam);
				
				while(!Obj_IsDeleted(obj)){
				
				ObjRender_SetAlpha(fam,255);
				ObjRender_SetPosition(fam,ObjMove_GetX(obj),ObjMove_GetY(obj),0);
				ObjRender_SetAngleXYZ(fam,0,0,c*2);
				c++;
				
				yield;
				
				}

					PlaySoundEffect("se_enep00");
					let rand1=rand(0,360);
					
					let obj2= CreateShotOA1(fam,0,0,ORB_RED,0);  // Create fake shot to create delay effect
					let posX=ObjMove_GetX(obj2);
					let posY=ObjMove_GetY(obj2);
					ObjRender_SetAlpha(obj2,0);
					ObjShot_SetIntersectionEnable(obj2,false);
					CallShot(obj2);
					addershot(obj2);
				Obj_Delete(fam);
				yield;
				Obj_Delete(obj2);
				task addershot(obj2){
				let angleshot=atan2(GetPlayerY-posY,GetPlayerX-posX);
				ascent(i in 0..6){
					PlaySoundEffect("se_tan00");
					
				let objadder=CreateShotA1(posX,posY,2,angleshot,FIRE_PURPLE+500,15);
					
				wait(10);
				}
					
				}
				
				task renderalphafam(obj){
					
					let c=0;
					let a=0;
					ascent(i in 0..30){
						ObjRender_SetScaleXYZ(obj, i/30,i/30,0);
						ObjRender_SetAlpha(obj, 100+a);
						
						a+=10;
						c+=0.05;
						yield;
					}
					
				}
				task Animate(graphic){
	let wave=0;
	let spdwave=0;
	while(!Obj_IsDeleted(graphic)){

		if(a<=5){

			ObjSprite2D_SetSourceRect(graphic,0,0,wi,he);
		}
		if((a>5)&&a<=10){

			ObjSprite2D_SetSourceRect(graphic,wi,0,wi*2,he);
		}

		if((a>10)&&a<=15){
			ObjSprite2D_SetSourceRect(graphic,wi*2,0,wi*3,he);
		}
		if((a>15)&&a<=20){
			ObjSprite2D_SetSourceRect(graphic,wi*3,0,wi*4,he);
		}
		if((a>20)&&a<=25){
			ObjSprite2D_SetSourceRect(graphic,wi*4,0,wi*5,he);
		}
		if((a>25)&&a<=30){
			ObjSprite2D_SetSourceRect(graphic,wi*5,0,wi*6,he);
		}
		if((a>30)&&a<=35){
			ObjSprite2D_SetSourceRect(graphic,wi*6,0,wi*7,he);
		}
		if((a>35)&&a<=40){
			ObjSprite2D_SetSourceRect(graphic,wi*7,0,wi*8,he);
		}
		a++;

		if(a>=40){
			a = 1;
		}
		
		
		yield;

}}

				
			
		}

task renderdrum(obj){
let a=1;
let sca=1;
let ang=0;
wait(100);
while(!Obj_IsDeleted(enm)){
//if (a<90){a+=3;}
//sca=1*sin(a);

ang+=4;
ObjRender_SetScaleXYZ(obj, sca+(sca/20)*sin(ang), sca+(sca/20)*sin(ang), 1);
//ObjRender_SetAngleXYZ(obj, 0, 0, c*2);
//c++;
yield;}
			
		}
		
		
		task rendermoving{
			
			
		}
	}



task AnimeKutakaWBaWC(obj){

	let wi = 64;
	let he = 95;
	
	let dir;
	let speed;
	let whichway = 0;
	let frame = 0;
	let idleframe = 0;
	let castframe = 0;
	Obj_SetValue(obj,"cast",0);

	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "./img/KutakaSprite.png");
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	
	while(!Obj_IsDeleted(obj)){
		
		dir = ObjMove_GetAngle(obj);
		speed = ObjMove_GetSpeed(obj);

		if(speed == 0 && frame > 0){whichway = -1;}
		else if(speed == 0 && frame < 0){whichway = 1;}
		else if(speed == 0 && frame == 0){whichway = 0;}

		else if(cos(dir) < 0){whichway=-1;}
		else if(cos(dir) > 0){whichway=1;}
		
		if(Obj_GetValueD(obj,"cast",0) == 0 && speed == 0 && frame == 0){

			castframe = 0;
			if(idleframe >= 0 && idleframe < 5){ObjSprite2D_SetSourceRect(obj,0,0,wi,he);}
			else if(idleframe >= 5 && idleframe < 10){ObjSprite2D_SetSourceRect(obj,wi,0,wi*2,he);}
			else if(idleframe >= 10 && idleframe < 15){ObjSprite2D_SetSourceRect(obj,wi*2,0,wi*3,he);}
			else if(idleframe >= 15 && idleframe < 20){ObjSprite2D_SetSourceRect(obj,wi*3,0,wi*4,he);}
			else if(idleframe >= 20 && idleframe < 25){ObjSprite2D_SetSourceRect(obj,wi*4,0,wi*5,he);}
			else if(idleframe >= 25 && idleframe < 30){ObjSprite2D_SetSourceRect(obj,wi*3,0,wi*4,he);}
			else if(idleframe >= 30 && idleframe < 35){ObjSprite2D_SetSourceRect(obj,wi*2,0,wi*3,he);}
			else if(idleframe >= 35 && idleframe < 40){ObjSprite2D_SetSourceRect(obj,wi,0,wi*2,he);}
			if(idleframe < 40){idleframe++;}
			else if(idleframe == 40){idleframe=5;}
			
		}
		
		else if(Obj_GetValueD(obj,"cast",0) == 1 && speed == 0 && frame == 0){
			
			idleframe=0;
			frame=0;
			if(castframe >= 0 && castframe < 5){ObjSprite2D_SetSourceRect(obj,0, he*3,wi, he*4);}
			if(castframe >= 5 && castframe < 10){ObjSprite2D_SetSourceRect(obj,wi,he*3,wi*2,	he*4);}
			if(castframe >= 10 && castframe < 15){ObjSprite2D_SetSourceRect(obj,wi*2,he*3,wi*3,	he*4);}
			if(castframe >= 15 && castframe < 20){ObjSprite2D_SetSourceRect(obj,wi*3,he*3,wi*4,	he*4);}
			
			if(castframe < 20){castframe++;}
			else if(castframe == 20){castframe=5;}
		}

		else if(speed != 0 || frame != 0){
		
			if(frame < 0 && frame >= -5){ObjSprite2D_SetSourceRect(obj,0,he*2,wi,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -5 && frame >= -10){ObjSprite2D_SetSourceRect(obj,wi,he*2,wi*2,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -10 && frame >= -15){ObjSprite2D_SetSourceRect(obj,wi*2,he*2,wi*3,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -15 && frame >= -20){ObjSprite2D_SetSourceRect(obj,wi*3,he*2,wi*4,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -20 && frame >= -25){ObjSprite2D_SetSourceRect(obj,wi*4,he*2,wi*5,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}

			if(frame > 0 && frame <= 5){ObjSprite2D_SetSourceRect(obj,0,he,wi,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 5 && frame <= 10){ObjSprite2D_SetSourceRect(obj,wi,he,wi*2,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 10 && frame <= 15){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 15 && frame <= 20){ObjSprite2D_SetSourceRect(obj,wi*3,he,wi*4,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 20 && frame <= 25){ObjSprite2D_SetSourceRect(obj,wi*4,he,wi*5,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}

			idleframe=0;
			castframe=0;

			
		}
		ObjSprite2D_SetDestCenter(obj);
		frame=frame+whichway;
		if(frame > 16){frame=16;}
		if(frame < -16){frame=-16;}
		yield;
		
	}
	
}

task AnimeUrumiWBaWC(obj){

	let wi = 64;
	let he = 95;
	
	let dir;
	let speed;
	let whichway = 0;
	let frame = 0;
	let idleframe = 0;
	let castframe = 0;
	Obj_SetValue(obj,"cast",0);

	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "./img/UrumiSprite.png");
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	
	while(!Obj_IsDeleted(obj)){
		
		dir = ObjMove_GetAngle(obj);
		speed = ObjMove_GetSpeed(obj);

		if(speed == 0 && frame > 0){whichway = -1;}
		else if(speed == 0 && frame < 0){whichway = 1;}
		else if(speed == 0 && frame == 0){whichway = 0;}

		else if(cos(dir) < 0){whichway=-1;}
		else if(cos(dir) > 0){whichway=1;}
		
		if(Obj_GetValueD(obj,"cast",0) == 0 && speed == 0 && frame == 0){

			castframe = 0;
			if(idleframe >= 0 && idleframe < 5){ObjSprite2D_SetSourceRect(obj,0,0,wi,he);}
			else if(idleframe >= 5 && idleframe < 10){ObjSprite2D_SetSourceRect(obj,wi,0,wi*2,he);}
			else if(idleframe >= 10 && idleframe < 15){ObjSprite2D_SetSourceRect(obj,wi*2,0,wi*3,he);}
			else if(idleframe >= 15 && idleframe < 20){ObjSprite2D_SetSourceRect(obj,wi*3,0,wi*4,he);}
			else if(idleframe >= 20 && idleframe < 25){ObjSprite2D_SetSourceRect(obj,wi*4,0,wi*5,he);}
			else if(idleframe >= 25 && idleframe < 30){ObjSprite2D_SetSourceRect(obj,wi*5,0,wi*6,he);}
			else if(idleframe >= 30 && idleframe < 35){ObjSprite2D_SetSourceRect(obj,wi*6,0,wi*7,he);}
			else if(idleframe >= 35 && idleframe < 40){ObjSprite2D_SetSourceRect(obj,wi*7,0,wi*8,he);}
			if(idleframe < 40){idleframe++;}
			else if(idleframe == 40){idleframe=5;}
			
		}
		
		else if(Obj_GetValueD(obj,"cast",0) == 1 && speed == 0 && frame == 0){
			
			idleframe=0;
			frame=0;
			if(castframe >= 0 && castframe < 5){ObjSprite2D_SetSourceRect(obj,0, he*3,wi, he*4);}
			if(castframe >= 5 && castframe < 10){ObjSprite2D_SetSourceRect(obj,wi,he*3,wi*2,	he*4);}
			if(castframe >= 10 && castframe < 15){ObjSprite2D_SetSourceRect(obj,wi*2,he*3,wi*3,	he*4);}
			if(castframe >= 15 && castframe < 20){ObjSprite2D_SetSourceRect(obj,wi*3,he*3,wi*4,	he*4);}
			if(castframe >= 20 && castframe < 25){ObjSprite2D_SetSourceRect(obj,wi*4,he*3,wi*5,	he*4);}
			if(castframe >= 25 && castframe < 30){ObjSprite2D_SetSourceRect(obj,wi*5,he*3,wi*6,	he*4);}
			if(castframe >= 30 && castframe < 35){ObjSprite2D_SetSourceRect(obj,wi*6,he*3,wi*7,	he*4);}
			if(castframe >= 35 && castframe < 40){ObjSprite2D_SetSourceRect(obj,wi*7,he*3,wi*8,	he*4);}
			
			
			if(castframe < 40){castframe++;}
			else if(castframe == 40){castframe=5;}
		}

		else if(speed != 0 || frame != 0){
		
			if(frame < 0 && frame >= -5){ObjSprite2D_SetSourceRect(obj,0,he*2,wi,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -5 && frame >= -10){ObjSprite2D_SetSourceRect(obj,wi,he*2,wi*2,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -10 && frame >= -15){ObjSprite2D_SetSourceRect(obj,wi*2,he*2,wi*3,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -15 && frame >= -20){ObjSprite2D_SetSourceRect(obj,wi*3,he*2,wi*4,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -20 && frame >= -25){ObjSprite2D_SetSourceRect(obj,wi*4,he*2,wi*5,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -25 && frame >= -30){ObjSprite2D_SetSourceRect(obj,wi*5,he*2,wi*6,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}

			if(frame > 0 && frame <= 5){ObjSprite2D_SetSourceRect(obj,0,he,wi,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 5 && frame <= 10){ObjSprite2D_SetSourceRect(obj,wi,he,wi*2,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 10 && frame <= 15){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 15 && frame <= 20){ObjSprite2D_SetSourceRect(obj,wi*3,he,wi*4,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 20 && frame <= 25){ObjSprite2D_SetSourceRect(obj,wi*4,he,wi*5,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 25 && frame <= 30){ObjSprite2D_SetSourceRect(obj,wi*5,he,wi*6,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}

			idleframe=0;
			castframe=0;

			
		}
		ObjSprite2D_SetDestCenter(obj);
		frame=frame+whichway;
		if(frame > 16){frame=16;}
		if(frame < -16){frame=-16;}
		yield;
		
	}
	
}


task AnimeEternity(obj){

	let wi = 80;
	let he = 100;
	
	let dir;
	let speed;
	let whichway = 0;
	let frame = 0;
	let idleframe = 0;
	let castframe = 0;
	Obj_SetValue(obj,"cast",0);

	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "./img/EternityHSiFS.png");
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetAngleXYZ(obj,0,180,0);
	
	while(!Obj_IsDeleted(obj)){
		
		dir = ObjMove_GetAngle(obj);
		speed = ObjMove_GetSpeed(obj);

		if(speed == 0 && frame > 0){whichway = -1;}
		else if(speed == 0 && frame < 0){whichway = 1;}
		else if(speed == 0 && frame == 0){whichway = 0;}

		else if(cos(dir) < 0){whichway=-1;}
		else if(cos(dir) > 0){whichway=1;}
		
		if(Obj_GetValueD(obj,"cast",0) == 0 && speed == 0 && frame == 0){

			castframe = 0;
			if(idleframe >= 0 && idleframe < 10){ObjSprite2D_SetSourceRect(obj,0,0,wi,he);}
			else if(idleframe >= 10 && idleframe < 20){ObjSprite2D_SetSourceRect(obj,wi,0,wi*2,he);}
			else if(idleframe >= 20 && idleframe < 30){ObjSprite2D_SetSourceRect(obj,wi*2,0,wi*3,he);}
			else if(idleframe >= 30 && idleframe < 40){ObjSprite2D_SetSourceRect(obj,wi*3,0,wi*4,he);}
			else if(idleframe >= 40 && idleframe < 50){ObjSprite2D_SetSourceRect(obj,wi*4,0,wi*5,he);}
			else if(idleframe >= 50 && idleframe < 60){ObjSprite2D_SetSourceRect(obj,wi*5,0,wi*6,he);}
			
			if(idleframe < 60){idleframe++;}
			else if(idleframe == 60){idleframe=0;}
			
		}
		
		else if(Obj_GetValueD(obj,"cast",0) == 1 && speed == 0 && frame == 0){
			
			idleframe=0;
			frame=0;
			if(castframe >= 0 && castframe < 10){ObjSprite2D_SetSourceRect(obj,0, he*2,wi, he*3);}
			if(castframe >= 10 && castframe < 20){ObjSprite2D_SetSourceRect(obj,wi,he*2,wi*2,	he*3);}
			if(castframe >= 20 && castframe < 30){ObjSprite2D_SetSourceRect(obj,wi*2,he*2,wi*3,	he*3);}
			if(castframe >= 30 && castframe < 40){ObjSprite2D_SetSourceRect(obj,wi*3,he*2,wi*4,	he*3);}
			if(castframe >= 40 && castframe < 50){ObjSprite2D_SetSourceRect(obj,wi*4,he*2,wi*5,	he*3);}
			if(castframe >= 50 && castframe < 60){ObjSprite2D_SetSourceRect(obj,wi*5,he*2,wi*6,	he*3);}
			
			if(castframe < 60){castframe++;}
			if(castframe == 60){castframe=0;}
		}

		else if(speed != 0 || frame != 0){
		
			if(frame < 0 && frame >= -5){ObjSprite2D_SetSourceRect(obj,0,he,wi,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -5 && frame >= -10){ObjSprite2D_SetSourceRect(obj,wi,he,wi*2,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -10 && frame >= -15){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -15 && frame >= -20){ObjSprite2D_SetSourceRect(obj,wi*3,he,wi*4,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -20 && frame >= -25){ObjSprite2D_SetSourceRect(obj,wi*4,he,wi*5,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -25 && frame >= 30){ObjSprite2D_SetSourceRect(obj,wi*5,he,wi*6,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			
			if(frame > 0 && frame <= 5){ObjSprite2D_SetSourceRect(obj,0,he,wi,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 5 && frame <= 10){ObjSprite2D_SetSourceRect(obj,wi,he,wi*2,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 10 && frame <= 15){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 15 && frame <= 20){ObjSprite2D_SetSourceRect(obj,wi*3,he,wi*4,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 20 && frame <= 25){ObjSprite2D_SetSourceRect(obj,wi*4,he,wi*5,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 25 && frame <= 30){ObjSprite2D_SetSourceRect(obj,wi*5,he,wi*6,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			idleframe=0;
			castframe=0;
			
		}
		ObjSprite2D_SetDestCenter(obj);
		frame=frame+whichway;
		if(frame > 16){frame=16;}
		if(frame < -16){frame=-16;}
		yield;
		
	}
	
}


task AnimeEternity2(obj){

	let wi = 129;
	let he = 128;
	
	let dir;
	let speed;
	let whichway = 0;
	let frame = 0;
	let idleframe = 0;
	let castframe = 0;
	Obj_SetValue(obj,"cast",0);

	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "./img/Eternity2.png");
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,0.8,0.8,0);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	
	while(!Obj_IsDeleted(obj)){
		
		dir = ObjMove_GetAngle(obj);
		speed = ObjMove_GetSpeed(obj);

		if(speed == 0 && frame > 0){whichway = -1;}
		else if(speed == 0 && frame < 0){whichway = 1;}
		else if(speed == 0 && frame == 0){whichway = 0;}

		else if(cos(dir) < 0){whichway=-1;}
		else if(cos(dir) > 0){whichway=1;}
		
		if(Obj_GetValueD(obj,"cast",0) == 0 && speed == 0 && frame == 0){

			castframe = 0;
			if(idleframe >= 0 && idleframe < 10){ObjSprite2D_SetSourceRect(obj,0,0,wi,he);}
			else if(idleframe >= 10 && idleframe < 20){ObjSprite2D_SetSourceRect(obj,wi,0,wi*2,he);}
			else if(idleframe >= 20 && idleframe < 30){ObjSprite2D_SetSourceRect(obj,wi*2,0,wi*3,he);}
			else if(idleframe >= 30 && idleframe < 40){ObjSprite2D_SetSourceRect(obj,wi*3,0,wi*4,he);}
			else if(idleframe >= 40 && idleframe < 50){ObjSprite2D_SetSourceRect(obj,wi*4,0,wi*5,he);}
			else if(idleframe >= 50 && idleframe < 60){ObjSprite2D_SetSourceRect(obj,wi*5,0,wi*6,he);}
			
			if(idleframe < 60){idleframe++;}
			else if(idleframe == 60){idleframe=0;}
			
		}
		
		else if(Obj_GetValueD(obj,"cast",0) == 1 && speed == 0 && frame == 0){
			
			idleframe=0;
			frame=0;
			if(castframe >= 0 && castframe < 10){ObjSprite2D_SetSourceRect(obj,0, he*2,wi, he*3);}
			if(castframe >= 10 && castframe < 20){ObjSprite2D_SetSourceRect(obj,wi,he*2,wi*2,	he*3);}
			if(castframe >= 20 && castframe < 30){ObjSprite2D_SetSourceRect(obj,wi*2,he*2,wi*3,	he*3);}
			if(castframe >= 30 && castframe < 40){ObjSprite2D_SetSourceRect(obj,wi*3,he*2,wi*4,	he*3);}
			if(castframe >= 40 && castframe < 50){ObjSprite2D_SetSourceRect(obj,wi*4,he*2,wi*5,	he*3);}
			if(castframe >= 50 && castframe < 60){ObjSprite2D_SetSourceRect(obj,wi*5,he*2,wi*6,	he*3);}
			
			if(castframe < 60){castframe++;}
			if(castframe == 60){castframe=0;}
		}

		else if(speed != 0 || frame != 0){
		
			if(frame < 0 && frame >= -5){ObjSprite2D_SetSourceRect(obj,0,he,wi,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -5 && frame >= -10){ObjSprite2D_SetSourceRect(obj,wi,he,wi*2,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -10 && frame >= -15){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			
			
			if(frame > 0 && frame <= 5){ObjSprite2D_SetSourceRect(obj,0,he,wi,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 5 && frame <= 10){ObjSprite2D_SetSourceRect(obj,wi,he,wi*2,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 10 && frame <= 15){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}

			idleframe=0;
			castframe=0;
			
		}
		ObjSprite2D_SetDestCenter(obj);
		frame=frame+whichway;
		if(frame > 16){frame=16;}
		if(frame < -16){frame=-16;}
		yield;
		
	}
	
}

function ObjRender_SetScale(obj,scale)
{
	return ObjRender_SetScaleXYZ(obj,scale,scale,scale);
}

function getDotAngle(x1,y1,x2,y2){
	let angle=atan2(y1-y2,x1-x2);
	return angle;
}


function CreateEffectObject(px,py,img,blendtype,left,top,right,bottom){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	LoadTexture(img);
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,left,top,right,bottom);
	ObjSprite2D_SetDestCenter(obj);
	if(blendtype=="ALPHA"){
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	}
	if(blendtype=="RGB"){
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	}
	if(blendtype=="ARGB"){
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	}
	if(blendtype=="INVERT"){
	ObjRender_SetBlendType(obj,BLEND_INV_DESTRGB);
	}
	ObjRender_SetPosition(obj,px,py,0);
	ObjMove_SetPosition(obj,px,py,);
	SetAutoDeleteObject(true);
	return obj;
}


	task Invincible(frame){
		SetInvincibility(enm, frame);
		
	}