#include "./img/kirbo/Attacks.txt"
let path = GetCurrentScriptDirectory() ~ "img/kirbo/sel_attack.png";

let win = SoundSFX(GetCurrentScriptDirectory ~ "./../SFX/XenoWin.wav");
let xeno = SoundSFX(GetCurrentScriptDirectory ~ "./../SFX/Xeno.wav");

task LoadKart{LoadTexture(path);}
function spawner(x, y, scale){
	let k = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjPrim_SetTexture(k, path);
	ObjSprite2D_SetSourceRect(k, 20, 16, 179, 75);
	ObjSprite2D_SetDestCenter(k);
	ObjRender_SetScaleXYZ(k, scale, scale, 0);
	ObjRender_SetAlpha(k, 160);
	ObjRender_SetPosition(k, x, y, 0);
	Obj_SetRenderPriorityI(k, 60);
	ObjRender_SetBlendType(k, BLEND_ALPHA);
	
	return k;
}

task randomer(k, frame){
	PlaySFX_V(xeno, 42);
	loop(frame){
		let so = rand_int(1, 11);
		
		alternative(so)
		case(01){ObjSprite2D_SetSourceRect(k, 20, 16, 179, 75);}
		case(02){ObjSprite2D_SetSourceRect(k, 20, 84, 179, 143);}
		case(03){ObjSprite2D_SetSourceRect(k, 20, 152, 179, 211);}
		case(04){ObjSprite2D_SetSourceRect(k, 20, 220, 179, 279);}
		case(05){ObjSprite2D_SetSourceRect(k, 20, 288, 179, 347);}
		case(06){ObjSprite2D_SetSourceRect(k, 20, 356, 179, 415);}
		case(07){ObjSprite2D_SetSourceRect(k, 344, 16, 503, 75);}
		case(08){ObjSprite2D_SetSourceRect(k, 344, 84, 503, 143);}
		case(09){ObjSprite2D_SetSourceRect(k, 344, 152, 503, 211);}
		case(10){ObjSprite2D_SetSourceRect(k, 344, 220, 503, 279);}
		case(11){ObjSprite2D_SetSourceRect(k, 344, 288, 503, 347);}
		others{ObjSprite2D_SetSourceRect(k, 20, 356, 179, 415); so = 6;}
		
		Obj_SetValue(k, "attack", so);
		yield;
	}
	
	PlaySFX_V(win, 36);
}

task selector(ne){
	if(GetCommonData("alive", true) == false){return;}
	
	let at = Obj_GetValue(ne, "attack");
	alternative(at)
	case(01){AT01();}//Balloon
	case(02){AT02(ne);}//Beam
	case(03){AT03(ne);}//Burning
	case(04){AT04(ne);}//Crash
	case(05){AT05(ne);}//Freeze
	case(06){AT06(ne);}//Missile
	case(07){AT07();}//Needle
	case(08){AT08(ne);}//Spark
	case(09){AT09(ne);}//Stone
	case(10){AT10(ne);}//Tornado
	case(11){AT11();}//Wheel
}

task ObjRenderMove_SetDestAtFrameWeight(obj, fin_x, fin_y, flame){
	let x = ObjRender_GetX(obj);
	let y = ObjRender_GetY(obj);
	let rx = fin_x - x;
	let ry = fin_y - y;
	let t_rate = 90/flame;

	ascent(time in 1..flame+1){
		ObjRender_SetX(obj, x + rx * sin(t_rate * time));
		ObjRender_SetY(obj, y + ry * sin(t_rate * time));
		yield;
	}
}