#include "./Index.txt"
function angleToObject(obj,obj2) {
 let dir = atan2(ObjMove_GetY(obj2)-ObjMove_GetY(obj),ObjMove_GetX(obj2)-ObjMove_GetX(obj));
 return dir;
}

let revolve = false;
task KanakoAura(tar, intro){
	let frame = 0;
	let Xscale = 1;
	let Yscale = 1;
	
	let radius = 0;
	if(intro==true){radius=300;}
	
	let counter = 138;
	
	ascent(i in 0..3){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/circle.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 256, 256);
	Obj_SetRenderPriorityI(obj,25);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetAlpha(obj,255/2);
	
	if(i==0){ObjRender_SetColor(obj, 255, 25, 25);}
	if(i==1){ObjRender_SetColor(obj, 25, 255, 25);}
	if(i==2){ObjRender_SetColor(obj, 25, 25, 255);}
	
	Rotation(obj, tar, i*360/3);
	}
	
	while(!Obj_IsDeleted(tar)){
	if(radius<1){counter++;}
	if(radius>1.1){counter=139;}
	if(counter==140){
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);	
	ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory~"./img/circle.png");
	ObjSprite2D_SetSourceRect(obj2,0, 0, 256, 256);
	Obj_SetRenderPriorityI(obj2,25);
	ObjSprite2D_SetDestCenter(obj2);
	ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj2,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
	ObjRender_SetAngleXYZ(obj2,0,0,0);
	ObjRender_SetAlpha(obj2,255);
	ObjRender_SetColor(obj2, 255, 255, 255);
	
	Scale(obj2);
	
	counter=0;
	}
	yield;
	}
	
	task Scale(obj){
	let alpha = 122;
	let scale = 1;
		loop(122){
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		ObjRender_SetPosition(obj,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
		ObjRender_SetAlpha(obj, alpha);
		alpha-=2;
		scale+=0.004;
		yield;
		}
	Obj_Delete(obj);
	}
	
	task Rotation(obj, tar, off){
	let counter = 0;
	let check = revolve;
	let check2 = 0;
		while(!Obj_IsDeleted(obj)){
		if(revolve != check && check2 == 0){radius = GetObjectDistance(obj, tar); check = revolve; check2++;}
		ObjRender_SetPosition(obj, ObjMove_GetX(tar)+radius*cos(off), ObjMove_GetY(tar)+radius*sin(off), 0);
		if(revolve==true){radius+=3*sin(counter*2); counter++;}
		if(revolve==false && radius > 0){radius--;}
		off++;
		check2 = 0;
		yield;
		}
	}
}

task Sticks(tar, intro){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/onbashira.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 90, 64);
	Obj_SetRenderPriorityI(obj,26);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetAlpha(obj,255);

	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory~"./img/onbashira.png");
	ObjSprite2D_SetSourceRect(obj2,0, 0, 90, 64);
	Obj_SetRenderPriorityI(obj2,26);
	ObjSprite2D_SetDestCenter(obj2);
	ObjRender_SetBlendType(obj2,BLEND_ALPHA);
	ObjRender_SetPosition(obj2,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
	ObjRender_SetAngleXYZ(obj2,0,0,0);
	ObjRender_SetAlpha(obj2,255);
	ObjRender_SetAngleY(obj2, 180);
	
	let getin = 0;
	if(intro==true){getin = 45+(10*30)}
	else{getin = 45;}
	while(!Obj_IsDeleted(tar)){
	ObjRender_SetPosition(obj, ObjMove_GetX(tar)-getin, ObjMove_GetY(tar)-10, 0);
	ObjRender_SetPosition(obj2, ObjMove_GetX(tar)+getin, ObjMove_GetY(tar)-10, 0);
	if(getin>45){getin-=10;}
	yield;
	}
}

function KillyStick(X, Y, ang){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjMove_SetAngle(obj, ang);
Render(obj, X, Y, ang);
Kill(obj);
return(obj);
	task Render(obj, X, Y, ang){
	let frame = 0;
	let x = 64;
	let y = 170;
	let scale = 0;
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Pillars.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 64, 170);
	Obj_SetRenderPriorityI(obj,46);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,X ,Y ,0);
	ObjRender_SetAlpha(obj,255);
		while(!Obj_IsDeleted(obj)){
		let ObjX = ObjMove_GetX(obj);
		let ObjY = ObjMove_GetY(obj);
		ObjRender_SetAngleXYZ(obj,0,0,ObjMove_GetAngle(obj)-90);
		if(frame<8){ObjSprite2D_SetSourceRect(obj,0,0,x,y);}
		if(frame>8){ObjSprite2D_SetSourceRect(obj,x,0,x*2,y);}
		if(frame==16){frame=0;}
		frame++;
		ObjRender_SetScaleXYZ(obj, scale, 1, 1);
		if(scale<1){scale+=0.1;}
		yield;
		}
	}
	task Kill(obj){
		let ObjX = ObjMove_GetX(obj);
		let ObjY = ObjMove_GetY(obj);
		let ObjAng = ObjMove_GetAngle(obj);
		let las = CreateStraightLaserA1(ObjX, ObjY, ObjMove_GetAngle(obj), 180, 70, 99999999, ST_LASER_GRAY, 10);
		ObjShot_SetAutoDelete(las, 0);
		Obj_SetVisible(las, 0);
		while(!Obj_IsDeleted(obj)){
		ObjX = ObjMove_GetX(obj);
		ObjY = ObjMove_GetY(obj);
		ObjAng = ObjMove_GetAngle(obj);	
		ObjStLaser_SetAngle(las, angleToObject(las,obj));
		ObjMove_SetPosition(las, ObjX-85*cos(ObjAng), ObjY-85*sin(ObjAng));
		yield;
		}
	}
}

function RegularStick(X, Y, ang){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjMove_SetAngle(obj, ang);
Render(obj, X, Y, ang);
return(obj);
	task Render(obj, X, Y, ang){
	let frame = 0;
	let x = 64;
	let y = 170;
	let scale = 0;
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Pillars.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 64, 170);
	Obj_SetRenderPriorityI(obj,46);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,X ,Y ,0);
	ObjRender_SetAlpha(obj,255);
		while(!Obj_IsDeleted(obj)){
		let ObjX = ObjMove_GetX(obj);
		let ObjY = ObjMove_GetY(obj);
		ObjRender_SetAngleXYZ(obj,0,0,ObjMove_GetAngle(obj)-90);
		if(frame<8){ObjSprite2D_SetSourceRect(obj,0,0,x,y);}
		if(frame>8){ObjSprite2D_SetSourceRect(obj,x,0,x*2,y);}
		if(frame==16){frame=0;}
		frame++;
		ObjRender_SetScaleXYZ(obj, scale, 1, 1);
		if(scale<1){scale+=0.1;}
		yield;
		}
	}
}
	
function WooshyWind(angle){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjMove_SetAngle(obj, angle);
Render(obj, angle);
return(obj);
	task Render(obj, angle){
		let count = 256/2;
		let alpha = 0;
		Obj_SetRenderPriorityI(obj,21);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./img/AirLine.png");
		ObjSprite2D_SetSourceRect(obj,0,0,256,256);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetScaleXYZ(obj,3,3,1.5);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetPosition(obj,384/2,448/2,0);
		ObjRender_SetAlpha(obj, 0);
		ObjRender_SetColor(obj, 255,255,255);
		while( !Obj_IsDeleted(obj) && bspell == true){
		ObjSprite2D_SetSourceRect(obj,-count,25*sin(count/8),-count+256*3,256*3+25*sin(count/8));
		ObjRender_SetAngleZ(obj, ObjMove_GetAngle(obj));
		ObjRender_SetAlpha(obj, alpha);
		if(alpha<210){alpha+=5;}
		count+=8;
		yield;
		}
		descent(i in 0..30){
		ObjRender_SetAlpha(obj,i);
		yield;
		}
		Obj_Delete(obj);
	}
}

function WooshyTempest(X, Y, ang, frame, delay){
		let count = 0;
		
		let tube = ObjEnemy_Create(OBJ_ENEMY);
		ObjEnemy_Regist(tube);
		
		Obj_SetRenderPriorityI(tube,35);
		ObjPrim_SetTexture(tube,GetCurrentScriptDirectory~"./img/WooshyTube2.png");
		ObjSprite2D_SetSourceRect(tube, 0, 0, 128*12, 128);
		ObjSprite2D_SetDestCenter(tube);
		ObjRender_SetScaleXYZ(tube,1,1,1);
		ObjRender_SetBlendType(tube,BLEND_ADD_ARGB);
		ObjRender_SetPosition(tube,X,Y,0);
		ObjRender_SetAngleZ(tube, ang);
		ObjRender_SetAlpha(tube, 255);
		
		let w1 = ObjEnemy_Create(OBJ_ENEMY);
		let w2 = ObjEnemy_Create(OBJ_ENEMY);
		let w3 = ObjEnemy_Create(OBJ_ENEMY);
		let w4 = ObjEnemy_Create(OBJ_ENEMY);
		ObjEnemy_Regist(w1);
		ObjEnemy_Regist(w2);
		ObjEnemy_Regist(w3);
		ObjEnemy_Regist(w4);
		let Wind = [w1, w2, w3, w4];
		
		ascent(i in 0..length(Wind)){
		Obj_SetRenderPriorityI(Wind[i],35);
		ObjPrim_SetTexture(Wind[i],GetCurrentScriptDirectory~"./img/WooshyTube1.png");
		ObjRender_SetScaleXYZ(Wind[i],0,0,1);
		ObjRender_SetBlendType(Wind[i],BLEND_ADD_ARGB);
		ObjRender_SetPosition(Wind[i],X,Y,0);
		ObjRender_SetAngleZ(Wind[i], ang);
		ObjRender_SetAlpha(Wind[i], 255/4);
		Looping(Wind[i], i);
		}
		return tube;
		task Looping(obj, off){
		
			ascent(i in 0..delay){
			ObjRender_SetScaleXYZ(obj, 1, 0.02, 1);
			ObjRender_SetScaleXYZ(tube, 1, 0.02, 1);
			ObjSprite2D_SetSourceRect(obj,-count,0,-count+256*3,128);
			ObjSprite2D_SetDestCenter(obj);
			yield;
			}
		
			ascent(i in 0..32){
			ObjRender_SetScaleXYZ(obj, 1, i/32, 1);
			ObjRender_SetScaleXYZ(tube, 1, i/32, 1);
			ObjSprite2D_SetSourceRect(obj,-count,0,-count+256*3,128);
			ObjSprite2D_SetDestCenter(obj);
			count+=1+(off*5);
			yield;
			}
		
			loop(frame){
			ObjSprite2D_SetSourceRect(obj,-count,0,-count+256*3,128);
			ObjSprite2D_SetDestCenter(obj);
			count+=1+(off*5);
			yield;
			}
			
			ascent(i in 0..32){
			ObjRender_SetScaleXYZ(obj, 1, 1-i/32, 1);
			ObjRender_SetScaleXYZ(tube, 1, 1-i/32, 1);
			ObjSprite2D_SetSourceRect(obj,-count,0,-count+256*3,128);
			ObjSprite2D_SetDestCenter(obj);
			count+=1+(off*5);
			yield;
			}
			Obj_Delete(obj);
			Obj_Delete(tube);
		}
}