#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] );
	
renderHombretigre(enm);
//AnimeUrumiWBaWC(enm);
	//TAura(enm, 3);
//BossIndicator(enm);

ChargeUp(enm, [GetStgFrameWidth/2,  GetStgFrameHeight/2-80], -9,3, angle, 50, 20, [255, 0, 0], "DARK");	

	
	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(70);
	
	ObjRender_SetPosition(enm, GetStgFrameWidth/2,  GetStgFrameHeight/2-80,0);

	wait(10);
	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);
	/*
	slowbullet;
	
	while(!Obj_IsDeleted(enm)){
	let ang1=rand(-20,20);
	let ang2=rand(160,200);
	
		ChargeUp(enm, [ObjMove_GetX(enm), ObjMove_GetY(enm)], -12,2, angle, 10, 25, [229, 18, 18], "DARK");
		ChargeUp(enm, [ObjMove_GetX(enm), ObjMove_GetY(enm)], 12,2, angle, 10, 25, [18, 218, 229], "DARK");
		wait(60);
		Action1(ang1);
			
		DupeAction1(ang1);
		wait(55);
		TMovement(95,15,4);
		Action2(ang2);
	
		wait(45);
		Action3(ang1);
		ang1*=-1;
		ang2*=-1;
		TMovement(35,15,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;
	
	ascent(j in 0..36){
		PlaySoundEffect("se_tan01");
	ascent(i in 0..aBullet){
		CreateShotA4(EnemyX+25*sin(ang),EnemyY-45*cos(ang),1.25-0.125*i,ang,PELLET_YELLOW,15,2.75-0.15*i);
		ang+=1;
		
	}
	if(aBullet>=6){aBullet+=-1;}
	aBullet+=1;
	ang+=2.5;
	wait(1);
	}
}

task DupeAction1(ang){
	let aBullet=1;
	//let ang=-10;
	
	ascent(j in 0..15){
		PlaySoundEffect("se_tan01");
	ascent(i in 0..aBullet){
		CreateShotA4(EnemyX+25*sin(ang),EnemyY-45*cos(ang),1.25-0.125*i,ang,PELLET_YELLOW,15,2.75-0.15*i);
		ang+=-1;
		
	}
	if(aBullet>=6){aBullet+=-1;}
	aBullet+=1;
	ang+=-2.5;
	wait(1);
	}
}

task Action2(ang){
	let aBullet=1;
	//let ang=180;
	
	ascent(j in 0..48){
		PlaySoundEffect("se_tan01");
		
	ascent(i in 0..aBullet){
		CreateShotA4(EnemyX+85*cos(ang),EnemyY+25*sin(ang),1.25-0.125*i,ang,PELLET_RED,15,2.25-0.05*i);
		ang+=-0.75;
		
	}
		
	if(aBullet>=8){aBullet+=-1;}
	aBullet+=1;
	ang+=-2.25;
	wait(1);
	}
}


task Action3(ang){
	let aBullet=1;
	let dist=55;
	//let ang=180;
	
	ascent(j in 0..30){
		PlaySoundEffect("se_tan01");
		
	ascent(i in 0..aBullet){
		CreateShotA4(EnemyX-dist*sin(ang),EnemyY+dist*cos(ang),1.25-0.1*i,ang,PELLET_MAGENTA,15,2.25-0.05*i);
		ang+=0.75;
		
	}
	dist+=-1.75;
	if(aBullet>=6){aBullet+=-1;}
	aBullet+=1;
	ang+=-46;
	wait(1);
	}
}


task slowbullet{
	wait(220);

	while(!Obj_IsDeleted(enm)){
		ascent(j in 0..4){
			let ang=rand(0,360);
		PlaySoundEffect("se_kira00");
	ascent(i in 0..45){
		CreateShotA5(EnemyX+15*cos(ang),EnemyY+15*sin(ang),5,ang,rand(-0.15,-0.12),0.75,SMALL_WHITE,5);
		
		ang+=360/45;
	}
	wait(30);
	}
	wait(50);
	}
}
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);

}


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;
		
	}
	
}
