
let state="STATE_IDLE";
let angle=0;
let obj=ObjPrim_Create(OBJ_SPRITE_2D);

task renderEXJunkoLoLK(obj){

	let wi = 96;
	let he = 132;
	
	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/JunkoEXSprite.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);}
			
			
			
			if(idleframe < 50){idleframe++;}
			else if(idleframe == 50){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,	he*3,wi*2,	he*4);}
			if(castframe >= 60 && castframe < 70){ObjSprite2D_SetSourceRect(obj,wi*2,he*3,wi*3,	he*4);}
			if(castframe >= 70 && castframe < 80){ObjSprite2D_SetSourceRect(obj,wi*3,he*3,wi*4,	he*4);}
			if(castframe >= 80 && castframe < 90){ObjSprite2D_SetSourceRect(obj,wi*4,he*3,wi*5,	he*4);}
			
			
			
			if(castframe < 90){castframe++;}
			if(castframe == 90){castframe=10;}
		}

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

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

task renderJunko(obj){

	let wi = 96;
	let he = 132;
	
	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/JunkoLoLK.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);}
			
			
			
			if(idleframe < 50){idleframe++;}
			else if(idleframe == 50){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++;}
			if(castframe == 50){castframe=10;}
		}

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

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

task renderOkinaHSiFS(obj){

	let wi = 96;
	let he = 110;
	
	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/OkinaHSiFS.png");
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,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,0,he,wi,he*2);}
			else if(idleframe >= 60 && idleframe < 70){ObjSprite2D_SetSourceRect(obj,wi,he,wi*2,he*2);}
			
			if(idleframe < 70){idleframe++;}
			else if(idleframe == 70){idleframe=0;}
			
		}
		
		else if(Obj_GetValueD(obj,"cast",0) == 1 && speed == 0 && frame == 0){
			
			idleframe=0;
			frame=0;
			if(castframe >= 0 && castframe < 7){ObjSprite2D_SetSourceRect(obj,0,he*2,wi,he*3);}
			if(castframe >= 7 && castframe < 14){ObjSprite2D_SetSourceRect(obj,wi,he*2,wi*2,he*3);}
			if(castframe >= 14 && castframe < 21){ObjSprite2D_SetSourceRect(obj,wi*2,he*2,wi*3,he*3);}
			if(castframe >= 21 && castframe < 28){ObjSprite2D_SetSourceRect(obj,wi*3,he*2,wi*4,he*3);}
			if(castframe < 28){castframe++;}
			if(castframe == 28){castframe=14;}
		}

		else if(speed != 0 || frame != 0){
		
			if(frame < 0 && frame >= -5){ObjSprite2D_SetSourceRect(obj,0,he*3,wi,he*4); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -5 && frame >= -10){ObjSprite2D_SetSourceRect(obj,wi,he*3,wi*2,he*4); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -10 && frame >= -20){ObjSprite2D_SetSourceRect(obj,wi*2,he*3,wi*3,he*4); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -20 && frame >= -30){ObjSprite2D_SetSourceRect(obj,wi*3,he*3,wi*4,he*4); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame < -30 && frame >= -31){ObjSprite2D_SetSourceRect(obj,wi*4,he*3,wi*5,he*4); ObjRender_SetAngleXYZ(obj,0,0,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 <= 20){ObjSprite2D_SetSourceRect(obj,wi*2,he*2,wi*3,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 20 && frame <= 30){ObjSprite2D_SetSourceRect(obj,wi*3,he*2,wi*4,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 30 && frame <= 31){ObjSprite2D_SetSourceRect(obj,wi*4,he*2,wi*5,he*3); ObjRender_SetAngleXYZ(obj,0,0,0);}
			idleframe=0;
			castframe=0;
			
		}
		
		frame=frame+whichway;
		if(frame > 25){frame=25;}
		if(frame < -25){frame=-25;}
		yield;
		
	}
	
}

task renderOkinaExHSiFS(obj){

	let wi = 80;
	let he = 96;
	
	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/MataraExHSiFS.png");
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,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*2,0,wi*3,he);}
			else if(idleframe >= 50 && idleframe < 60){ObjSprite2D_SetSourceRect(obj,wi,0,wi*2,he);}
			else if(idleframe >= 60 && idleframe < 70){ObjSprite2D_SetSourceRect(obj,0,0,wi,he);}
			
			if(idleframe < 70){idleframe++;}
			else if(idleframe == 70){idleframe=10;}
			
		}
		
		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++;}
			if(castframe == 40){castframe=10;}
		}

		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 >= -20){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -20 && frame >= -30){ObjSprite2D_SetSourceRect(obj,wi*3,he,wi*4,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -30 && frame >= -31){ObjSprite2D_SetSourceRect(obj,wi*4,he,wi*5,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 <= 20){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 20 && frame <= 30){ObjSprite2D_SetSourceRect(obj,wi*3,he,wi*4,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 30 && frame <= 31){ObjSprite2D_SetSourceRect(obj,wi*4,he,wi*5,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			idleframe=0;
			castframe=0;
			
		}
		
		frame=frame+whichway;
		if(frame > 25){frame=25;}
		if(frame < -25){frame=-25;}
		yield;
		
	}
	
}

task renderShinya(obj){

	let wi = 120;
	let he = 120;
	
	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/shinya.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);}
			
			
			
			if(idleframe < 50){idleframe++;}
			else if(idleframe == 50){idleframe=0;}
			
		}
		
		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++;}
			if(castframe == 40){castframe=15;}
		}

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

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



task renderMoritaka(obj){

	let wi = 82;
	let he = 80;

	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/MoritakaSprite.png");
	
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.3,1.3,0);
	AI(GetCurrentScriptDirectory ~ "./img/MoritakaSprite.png",wi,he);
	
	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);}
			
			if(idleframe < 40){idleframe++;}
			else if(idleframe == 40){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++;}
			if(castframe == 30){castframe=10;}
		}

		else if(speed != 0 || frame != 0){
		
			if(frame < 0 && frame >= -8){ObjSprite2D_SetSourceRect(obj,0,he,wi,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -8 && frame >= -16){ObjSprite2D_SetSourceRect(obj,wi,he,wi*2,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -16 && frame >= -24){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame < -24 && frame >= -25){ObjSprite2D_SetSourceRect(obj,wi*3,he,wi*4,he*2); ObjRender_SetAngleXYZ(obj,0,180,0);}
			if(frame > 0 && frame <= 8){ObjSprite2D_SetSourceRect(obj,0,he,wi,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 8 && frame <= 16){ObjSprite2D_SetSourceRect(obj,wi,he,wi*2,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 16 && frame <= 24){ObjSprite2D_SetSourceRect(obj,wi*2,he,wi*3,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			if(frame > 24 && frame <= 25){ObjSprite2D_SetSourceRect(obj,wi*3,he,wi*4,he*2); ObjRender_SetAngleXYZ(obj,0,0,0);}
			idleframe=0;
			castframe=0;
			
		}
		
		frame=frame+whichway;
		if(frame > 25){frame=25;}
		if(frame < -25){frame=-25;}
		yield;
		
	}
	
	task AI(graphic,wi,he){
		wait(10);

	while(!Obj_IsDeleted(obj)){
	
	AfterImage(obj,graphic,[0,255,255],1.5,1.5,0.2,40,0,0,wi,he,0,0);

		wait(5);
		}
		

}
	
	
		task AfterImage(tobj,texture,color,startscaleX,startscaleY,scaleinc,time,x1,y1,x2,y2,Yangle,Zangle){     ////// From AJS
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let alpha = 100;
	let Red = color[0];
	let Green = color[1];
	let Blue = color[2];
	
	ObjPrim_SetTexture(obj, texture);
	ObjSprite2D_SetSourceRect(obj, x1, y1, x2, y2);
	ObjRender_SetScaleXYZ(obj,startscaleX,startscaleY,0);
	Obj_SetRenderPriorityI(obj,26);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,ObjRender_GetX(tobj),ObjRender_GetY(tobj),0);
	ObjRender_SetAlpha(obj,alpha);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetColor(obj,Red,Green,Blue);
	ObjRender_SetAngleXYZ(obj,0,Yangle,Zangle);
	
	loop(time){
	startscaleX+=scaleinc/time;
	startscaleY+=scaleinc/time;
	ObjRender_SetScaleXYZ(obj,startscaleX,startscaleY,0);
	
	alpha-=100/time;
	ObjRender_SetAlpha(obj,alpha);
	yield;}
	
	Obj_Delete(obj);
}

	
}

task renderShino(obj){

	let wi = 96;
	let he = 132;
	
	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/ShinoSprite.png");
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,0.8,0.8,0);
	ObjRender_SetAngleXYZ(obj,0,180,0);
	AI(GetCurrentScriptDirectory ~ "./img/ShinoSprite.png",wi,he);
	
	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);}
			
			
			
			if(idleframe < 50){idleframe++;}
			else if(idleframe == 50){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,410,185, 540);}
			if(castframe >= 10 && castframe < 20){ObjSprite2D_SetSourceRect(obj,195,410,388,540);}
			if(castframe >= 20 && castframe < 30){ObjSprite2D_SetSourceRect(obj,0,560,185,	685);}
			if(castframe >= 30 && castframe < 40){ObjSprite2D_SetSourceRect(obj,195,560,388,685);}
			
			
			
			if(castframe < 40){castframe++;}
			if(castframe == 40){castframe=10;}
		}

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

			idleframe=0;
			castframe=0;
			
		}
		ObjSprite2D_SetDestCenter(obj);
		frame=frame+whichway;
		if(frame > 20){frame=20;}
		if(frame < -20){frame=-20;}
		yield;
		
	}
	
	task AI(graphic,wi,he){
		wait(10);

	while(!Obj_IsDeleted(obj)){
	
	AfterImage(obj,graphic,[255,0,0],1,1,0.2,40,0,0,wi,he,0,0);

		wait(5);
		}
		

}

	task AfterImage(tobj,texture,color,startscaleX,startscaleY,scaleinc,time,x1,y1,x2,y2,Yangle,Zangle){     ////// From AJS
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let alpha = 100;
	let Red = color[0];
	let Green = color[1];
	let Blue = color[2];
	
	ObjPrim_SetTexture(obj, texture);
	ObjSprite2D_SetSourceRect(obj, x1, y1, x2, y2);
	ObjRender_SetScaleXYZ(obj,startscaleX,startscaleY,0);
	Obj_SetRenderPriorityI(obj,26);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,ObjRender_GetX(tobj),ObjRender_GetY(tobj),0);
	ObjRender_SetAlpha(obj,alpha);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetColor(obj,Red,Green,Blue);
	ObjRender_SetAngleXYZ(obj,0,Yangle,Zangle);
	
	loop(time){
	startscaleX+=scaleinc/time;
	startscaleY+=scaleinc/time;
	ObjRender_SetScaleXYZ(obj,startscaleX,startscaleY,0);
	
	alpha-=100/time;
	ObjRender_SetAlpha(obj,alpha);
	yield;}
	
	Obj_Delete(obj);
}

	
}



task renderShion(obj){

	let wi = 96;
	let he = 132;
	
	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/ShionSprite.png");
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,0.85,0.85,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);}
			
			
			
			if(idleframe < 50){idleframe++;}
			else if(idleframe == 50){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++;}
			if(castframe == 50){castframe=10;}
		}

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

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

task renderJoon(obj){

	let wi = 96;
	let he = 132;
	
	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/JoonSprite.png");
	ObjSprite2D_SetSourceRect(obj,0,0,wi,he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,0.9,0.9,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);}
			
			
			
			if(idleframe < 50){idleframe++;}
			else if(idleframe == 50){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++;}
			if(castframe == 50){castframe=10;}
		}

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

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