#include "./MS_ShotFunctions.txt"
#include "./MS_DefaultFunctions.txt"

task MamiSmoke(x, y, spd, ang, scale, anglesprite, negate, del){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);

let tex = GetCurrentScriptDirectory ~ "img/Ingame/smoke.png";

let alpha = 255;
let count = 0;
let sprite = truncate(rand(0, 4));
let rec = 124;

	ObjPrim_SetTexture(obj, tex);
	Obj_SetRenderPriorityI(obj, 50);
	if(sprite == 0){ObjSprite2D_SetSourceRect(obj,0,0,rec,rec);}
	if(sprite == 1){ObjSprite2D_SetSourceRect(obj,rec,0,rec*2,rec);}
	if(sprite == 2){ObjSprite2D_SetSourceRect(obj,0,rec,rec,rec*2);}
	if(sprite == 3){ObjSprite2D_SetSourceRect(obj,rec,rec,rec*2,rec*2);}
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,scale,scale,0);
	ObjRender_SetAngleXYZ(obj,0,0,rand(0,360));
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj, x, y, 0);
	
	let delcounter = 0;
	loop{
	ObjRender_SetPosition(obj, x+count*cos(ang), y+count*sin(ang), 0);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetAngleZ(obj, anglesprite);
	count+=spd;
	delcounter++;
	if(delcounter>del){
	alpha-=negate;
	}
	if(alpha<1){Obj_Delete(obj); break;}
	yield;
	}

}

function Leaf(x, y, spd, ang, scale, objBoss, del){
let shot = CreateShotA1(x, y, spd, ang, 1, del);
Obj_SetVisible(shot, 0);
Render(shot);
return shot;
	task Render(shot){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 255;
	let count = 0;
	let rec = 64;
	let random = rand(0,360);

		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/leafstar.png");
		Obj_SetRenderPriorityI(obj, 50);
		ObjSprite2D_SetSourceRect(obj,0,0,rec,rec);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		ObjRender_SetAngleXYZ(obj,0,0,random);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, x, y, 0);
	
	
		while(!Obj_IsDeleted(shot)){
		ObjEnemy_SetIntersectionCircleToPlayer(objBoss,GetX(shot), GetY(shot),5);
		ObjRender_SetPosition(obj, GetX(shot), GetY(shot), 0);
		ObjRender_SetAngleZ(obj, random+count);
		count++;
		yield;
		}
		Obj_Delete(obj);
	}
}

function Packet(x, y){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjMove_SetPosition(obj, x, y);
Render(obj);
return obj;
	task Render(tar){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 255;
	let count = 0;
	let random = rand(0,360);

		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Effects/packet.png");
		Obj_SetRenderPriorityI(obj, 50);
		ObjSprite2D_SetSourceRect(obj,0,0,128,128);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetScaleXYZ(obj,0.5, 0.5,0);
		ObjRender_SetAngleXYZ(obj,0,0,random);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, x, y, 0);
	
	
		while(!Obj_IsDeleted(tar)){
		ObjRender_SetPosition(obj, GetX(tar), GetY(tar), 0);
		ObjRender_SetAngleZ(obj, random+count);
		count+=5;
		yield;
		}
		Obj_Delete(obj);
	}
}

function Enemee(x, y){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
return obj;
}

task PacketExplode(x, y, level){
if(level == 0){}
if(level == 1){firework;}
if(level == 2){firework; fire;}
if(level == 3){firework; fire; star;}

task firework{
let obj = ObjPrim_Create(OBJ_SPRITE_2D);

let alpha = 255;
let count = 0;

	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Effects/ecksplosion.png");
	Obj_SetRenderPriorityI(obj, 50);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetAngleXYZ(obj,0,0,rand(0,360));
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj, x, y, 0);
	
	loop{
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetScaleXYZ(obj,0.15+count/75,0.15+count/75,0);
	count++;
	if(count > 20){alpha-=5;}
	if(alpha < 0){Obj_Delete(obj);}
	yield;
	}
}

task fire{
let obj = ObjPrim_Create(OBJ_SPRITE_2D);

let alpha = 255;
let count = 0;
let count2 = 0;

	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Effects/ecksplosion2.png");
	Obj_SetRenderPriorityI(obj, 50);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetAngleXYZ(obj,0,0,rand(0,360));
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj, x, y, 0);
	
	loop{
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetScaleXYZ(obj,0.15+count/count2,0.15+count/count2,0);
	count++;
	count2+=2;
	if(count > 20){alpha-=5;}
	if(alpha < 0){Obj_Delete(obj);}
	yield;
	}
}

task star{
let obj = ObjPrim_Create(OBJ_SPRITE_2D);

let alpha = 255;
let count = 0;

	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Effects/ecksplosion3.png");
	Obj_SetRenderPriorityI(obj, 50);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetAngleXYZ(obj,0,0,rand(0,360));
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjRender_SetColor(obj, 15, 15, 255);
	
	loop{
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetScaleXYZ(obj,0.15+count/100,0.15+count/100,0);
	ObjRender_SetAngleZ(obj, count);
	count++;
	if(count > 120){alpha-=5;}
	if(alpha < 0){Obj_Delete(obj);}
	yield;
	}
}

}

task Girl(x, y, level){
if(level == 0){vgood;}
if(level == 1){good;}
if(level == 2){bad;}
if(level == 3){vbad;}

task vgood{
let obj = ObjText_Create;
let alpha = 255;
	Obj_SetRenderPriorityI(obj, 55);
	ObjText_SetFontType(obj, "Modern No. 20");
	ObjText_SetFontSize(obj, 20);
	ObjText_SetFontBold(obj, false);
	ObjText_SetText(obj, "    Very[r]Good Girl");
	ObjText_SetFontColorTop(obj, 255, 255, 255);
	ObjText_SetFontColorBottom(obj, 255, 255, 255);
	ObjText_SetFontBorderType(obj, BORDER_FULL);
	ObjText_SetFontBorderColor(obj,0, 0, 0);
	ObjText_SetFontBorderWidth(obj, 1);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetX(obj, x-45);
	ObjRender_SetY(obj, y-30);
	ObjText_SetHorizontalAlignment(obj, ALIGNMENT_LEFT);
	wait(60);
	loop{
	ObjRender_SetAlpha(obj, alpha);
	alpha-=3;
	if(alpha < 0){Obj_Delete(obj);}
	yield;
	}
}

task good{
let obj = ObjText_Create;
let alpha = 255;
	Obj_SetRenderPriorityI(obj, 55);
	ObjText_SetFontType(obj, "Modern No. 20");
	ObjText_SetFontSize(obj, 20);
	ObjText_SetFontBold(obj, false);
	ObjText_SetText(obj, "Good Girl");
	ObjText_SetFontColorTop(obj, 233, 233, 233);
	ObjText_SetFontColorBottom(obj, 233, 233, 233);
	ObjText_SetFontBorderType(obj, BORDER_FULL);
	ObjText_SetFontBorderColor(obj,0, 0, 0);
	ObjText_SetFontBorderWidth(obj, 2);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetX(obj, x-45);
	ObjRender_SetY(obj, y);
	ObjText_SetHorizontalAlignment(obj, ALIGNMENT_LEFT);
	wait(60);
	loop{
	ObjRender_SetAlpha(obj, alpha);
	alpha-=3;
	if(alpha < 0){Obj_Delete(obj);}
	yield;
	}
}
task bad{
let obj = ObjText_Create;
let alpha = 255;
	Obj_SetRenderPriorityI(obj, 55);
	ObjText_SetFontType(obj, "Modern No. 20");
	ObjText_SetFontSize(obj, 20);
	ObjText_SetFontBold(obj, false);
	ObjText_SetText(obj, "Bad Girl");
	ObjText_SetFontColorTop(obj, 122, 122, 122);
	ObjText_SetFontColorBottom(obj, 122, 122, 122);
	ObjText_SetFontBorderType(obj, BORDER_FULL);
	ObjText_SetFontBorderColor(obj,0, 0, 0);
	ObjText_SetFontBorderWidth(obj, 3);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetX(obj, x-45);
	ObjRender_SetY(obj, y);
	ObjText_SetHorizontalAlignment(obj, ALIGNMENT_LEFT);
	loop(60){
	ObjRender_SetX(obj, x-45+rand(-1, 1));
	ObjRender_SetY(obj, y-30+rand(-1, 1));	
	yield;
	}
	loop{
	ObjRender_SetX(obj, x-45+rand(-1, 1));
	ObjRender_SetY(obj, y-30+rand(-1, 1));	
	ObjRender_SetAlpha(obj, alpha);
	alpha-=3;
	if(alpha < 0){Obj_Delete(obj);}
	yield;
	}
}
task vbad{
let obj = ObjText_Create;
let alpha = 255;
	Obj_SetRenderPriorityI(obj, 55);
	ObjText_SetFontType(obj, "Modern No. 20");
	ObjText_SetFontSize(obj, 20);
	ObjText_SetFontBold(obj, false);
	ObjText_SetText(obj, "Very[r]Bad Girl");
	ObjText_SetFontColorTop(obj, 0, 0, 0);
	ObjText_SetFontColorBottom(obj, 0, 0, 0);
	ObjText_SetFontBorderType(obj, BORDER_FULL);
	ObjText_SetFontBorderColor(obj,255, 255, 255);
	ObjText_SetFontBorderWidth(obj, 2);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetX(obj, x-45);
	ObjRender_SetY(obj, y-30);
	ObjText_SetHorizontalAlignment(obj, ALIGNMENT_LEFT);
	loop(60){
	ObjRender_SetX(obj, x-45+rand(-4, 4));
	ObjRender_SetY(obj, y+rand(-4, 4));	
	yield;
	}
	loop{
	ObjRender_SetX(obj, x-45+rand(-4, 4));
	ObjRender_SetY(obj, y+rand(-4, 4));	
	ObjRender_SetAlpha(obj, alpha);
	alpha-=3;
	if(alpha < 0){Obj_Delete(obj);}
	yield;
	}
}
}

function Newlaser(x, y, ang, len, wid, del, graph, delay){
let obj = CreateStraightLaserA1(x, y, ang, 0, wid, del, graph, delay);
Grow(obj);
return obj;
	task Grow(obj){
	let lengrowth = 0;
		while(ObjLaser_GetLength(obj) < len){
		lengrowth+=7;
		ObjLaser_SetLength(obj, lengrowth);
		yield;
		}
	}
}

task Charge(x, y, time, del, color){
PlaySound(GetCurrentScriptDirectory ~ "/se/charge.wav", 60, 0);
	ascent(i in 0..time/del){
	Concentrate(x, y, rand(0, 360), 3, 1+i/5, 0.25, "Cherry", 25+i*12, rand(-2, 2), color);
	wait(del);
	}
}

task Sax(tar){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 255;
	let count = 0;

		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/sax.png");
		Obj_SetRenderPriorityI(obj, 50);
		ObjSprite2D_SetSourceRect(obj,0,0,237,750);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetScaleXYZ(obj,0.07,0.07,0);
		ObjRender_SetAngleXYZ(obj,0,0,0);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, GetX(tar), GetY(tar), 0);
	
		
	
		while(!Obj_IsDeleted(tar)){
		let bob = GetCommonData("DisguiseBob", 5);
		ObjRender_SetPosition(obj, GetX(tar)+5, GetY(tar)+3*sin(bob*3)+2, 0);
		count++;
		yield;
		}
		Obj_Delete(obj);
}

task Drum(tar){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 255;
	let count = 0;
	let tex = GetCurrentScriptDirectory ~ "img/Ingame/drum.png";

		ObjPrim_SetTexture(obj,tex);
		Obj_SetRenderPriorityI(obj, 50);
		ObjSprite2D_SetSourceRect(obj,0,0,GetTextureWidth(tex),GetTextureHeight(tex));
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetScaleXYZ(obj,0.07,0.07,0);
		ObjRender_SetAngleXYZ(obj,0,0,0);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, GetX(tar), GetY(tar), 0);
	
		
	
		while(!Obj_IsDeleted(tar)){
		let bob = GetCommonData("DisguiseBob", 5);
		ObjRender_SetPosition(obj, GetX(tar), GetY(tar)+3*sin(bob*3)+3, 0);
		count++;
		yield;
		}
		Obj_Delete(obj);
}

task Cello(tar){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 255;
	let count = 0;
	let tex = GetCurrentScriptDirectory ~ "img/Ingame/cello.png";

		ObjPrim_SetTexture(obj,tex);
		Obj_SetRenderPriorityI(obj, 50);
		ObjSprite2D_SetSourceRect(obj,0,0,GetTextureWidth(tex),GetTextureHeight(tex));
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetScaleXYZ(obj,0.2,0.2,0);
		ObjRender_SetAngleXYZ(obj,0,0,0);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, GetX(tar), GetY(tar), 0);
	
		
	
		while(!Obj_IsDeleted(tar)){
		let bob = GetCommonData("DisguiseBob", 5);
		ObjRender_SetPosition(obj, GetX(tar), GetY(tar)+3*sin(bob*3), 0);
		count++;
		yield;
		}
		Obj_Delete(obj);
}

task Trumpet(tar){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 255;
	let count = 0;
	let tex = GetCurrentScriptDirectory ~ "img/Ingame/trumpet.png";

		ObjPrim_SetTexture(obj,tex);
		Obj_SetRenderPriorityI(obj, 50);
		ObjSprite2D_SetSourceRect(obj,0,0,GetTextureWidth(tex),GetTextureHeight(tex));
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetScaleXYZ(obj,0.07,0.07,0);
		ObjRender_SetAngleXYZ(obj,0,0,0);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, GetX(tar), GetY(tar), 0);
	
		
	
		while(!Obj_IsDeleted(tar)){
		let bob = GetCommonData("DisguiseBob", 5);
		ObjRender_SetPosition(obj, GetX(tar)+12, GetY(tar)+3*sin(bob*3)-12, 0);
		count++;
		yield;
		}
		Obj_Delete(obj);
}