let point = 0;

function poison(x,y,spd,dir,acc,maxspd,maxscale,frame){
	let shot = CreateShotA2(x,y,spd,dir,acc,maxspd,SMALL_RED,0); // Invisible Bullet
	let dis = 0;
	ObjShot_SetIntersectionEnable(shot,false);
	ObjRender_SetAlpha(shot,0);
	poisonshot(x,y,1);
	poisonshot(x,y,-1);
	return shot;
	task poisonshot(x,y,way){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/poison2.png";
	let c = 0;
	let scale = 0;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	ObjRender_SetColor(obj,192,192,192);
		while(!Obj_IsDeleted(shot)){
		if(scale<maxscale){scale += maxscale/frame;}
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		dis = GetDistance(ObjMove_GetX(shot),ObjMove_GetY(shot),GetPlayerX,GetPlayerY);
		if(dis<scale*95){
		SetPlayerSpeed(1.5,0.75);
		}
		ObjRender_SetPosition(obj,ObjMove_GetX(shot),ObjMove_GetY(shot),0); // stick poison to the bullet
		ObjRender_SetAngleXYZ(obj,0,0,c*1*way);
		c++;
		yield;
		}
		Obj_Delete(obj);
	}
}

function spoison(x,y,spd,dir,acc,maxspd,maxscale,frame){
	let shot = CreateShotA2(x,y,spd,dir,acc,maxspd,SMALL_RED,0); // Invisible Bullet
	let dis = 0;
	ObjShot_SetIntersectionEnable(shot,false);
	ObjRender_SetAlpha(shot,0);
	poisonshot(x,y,1);
	poisonshot(x,y,-1);
	return shot;
	task poisonshot(x,y,way){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/poison2.png";
	let c = 0;
	let scale = 0;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	ObjRender_SetColor(obj,64,256,192);
		while(!Obj_IsDeleted(shot)){
		if(scale<maxscale){scale += maxscale/frame;}
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		dis = GetDistance(ObjMove_GetX(shot),ObjMove_GetY(shot),GetPlayerX,GetPlayerY);
		if(dis<scale*95){
		SetPlayerSpeed(7,3.5);
		}
		ObjRender_SetPosition(obj,ObjMove_GetX(shot),ObjMove_GetY(shot),0); // stick poison to the bullet
		ObjRender_SetAngleXYZ(obj,0,0,c*1*way);
		c++;
		yield;
		}
		Obj_Delete(obj);
	}
}


task maple(type){
	if(type==2){
		PlaySound("Charge2",95,0);
		TCharge02(GetEnemyX,GetEnemyY,3,60,255,128,128);
		ascent(i in 0..20){
		loop(3){
		etama(50+i*8,i);
		}
		yield;
		}
	}
	if(type==1){
		PlaySound("Charge1",95,0);
		TCharge02(GetEnemyX,GetEnemyY,3,120,255,128,128);
		ascent(i in 0..40){
		loop(2){
		etama(i*8,i);
		}
		yield;
		}
	}
	if(type==3){
		PlaySound("Charge3",95,0);
		TCharge01(GetEnemyX,GetEnemyY,3,90,255,128,128);
		ascent(i in 0..40){
		loop(3){
		etama(i*8,i);
		}
		yield;
		}
	}
	}

task etama(r,a){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/eff2.png";
	let dir = rand(0,359);
	let angle = rand(0,359);
	let size = 1.75+a/30;
	let s = size;
	let ra = r;
	let c = 0;
	let cp = rand(-7,7);
	let alpha = 0;
	let alphaplus = 255/ra;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,32,226,64,254);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,0);
	while(r>0){
	ObjRender_SetPosition(obj,GetEnemyX+r*cos(dir),GetEnemyY+r*sin(dir),0);
	ObjRender_SetAngleXYZ(obj,0,0,angle+c);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetAlpha(obj,alpha*5);
	alpha += alphaplus;
	c+= cp;
	r-=4.5;
	size -= s/ra*2;
	yield;
	}
	Obj_Delete(obj);
	
}

task manageSprite{
		let f2 = 0;
		while(f2<=24){
		if(f2<8){ObjSprite2D_SetSourceRect(objBoss, 0, 64, 64, 128);}
		if(f2>=8 && f2<16){ObjSprite2D_SetSourceRect(objBoss, 64, 64, 128, 128);}
		if(f2>=16 && f2<24){ObjSprite2D_SetSourceRect(objBoss, 128, 64, 192, 128);}
		if(f2>=24){ObjSprite2D_SetSourceRect(objBoss, 192, 64, 256, 128);}
		f2++;
		yield;
		}
		while(ObjMove_GetSpeed(objBoss) > 3){
		yield;
		}
		while(f2>=0){
		if(f2<8){ObjSprite2D_SetSourceRect(objBoss, 0, 64, 64, 128);}
		if(f2>=8 && f2<16){ObjSprite2D_SetSourceRect(objBoss, 64, 64, 128, 128);}
		if(f2>=16 && f2<24){ObjSprite2D_SetSourceRect(objBoss, 128, 64, 192, 128);}
		if(f2>=24){ObjSprite2D_SetSourceRect(objBoss, 192, 64, 256, 128);}
		f2-= 2;
		yield;
		}

	}


task magiccircle(boss,size,type){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/eff.png";
	let spin = 0;
	let s = 0;
	LoadTexture(img);
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,128,80,256,208);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetAlpha(obj,192);
	while(!Obj_IsDeleted(boss)){
	spin += 3;
	ObjRender_SetAngleXYZ(obj,0,0,-spin*2);
	ObjRender_SetPosition(obj,ObjMove_GetX(boss),ObjMove_GetY(boss),0);
	if(type==true){
	ObjRender_SetScaleXYZ(obj,size+0.2*sin(spin),size+0.2*sin(spin),0);
	}
	ObjMove_SetPosition(obj,GetEnemyX,GetEnemyY);
	yield;
	}
	Obj_Delete(obj);
	}

task Cutin(name,text,textwidth){
	let alpha=0;
	let scale=4;
	let yscale=1;
	let py = 0;
	let acc = 0;
	let acc2 = 0;
	let objTxt=ObjText_Create;
	ObjText_SetText(objTxt,text);
	ObjText_SetFontSize(objTxt,textwidth);
	ObjText_SetFontColorTop(objTxt,255,255,255);
	ObjText_SetFontColorBottom(objTxt,255,0,128);
	ObjText_SetFontBorderType(objTxt,BORDER_FULL);
	ObjText_SetFontBorderColor(objTxt,0,0,200);
	ObjText_SetFontBorderWidth(objTxt,1);
	ObjText_SetHorizontalAlignment(objTxt,ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objTxt,380);
	Obj_SetRenderPriority(objTxt,0.8);
	ObjRender_SetPosition(objTxt,-300,300,0);
	ObjText_SetAutoTransCenter(objTxt,true);
	
	/*let scoreTxt=ObjText_Create;
	ObjText_SetText(scoreTxt,Bonus:);
	ObjText_SetFontSize(scoreTxt,100);
	ObjText_SetFontColorTop(scoreTxt,255,255,255);
	ObjText_SetFontColorBottom(scoreTxt,128,128,255);
	ObjText_SetFontBorderType(scoreTxt,BORDER_FULL);
	ObjText_SetFontBorderColor(scoreTxt,0,0,200);
	ObjText_SetFontBorderWidth(scoreTxt,1);
	ObjText_SetHorizontalAlignment(scoreTxt,ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(scoreTxt,380);
	Obj_SetRenderPriority(scoreTxt,0.8);
	ObjRender_SetPosition(scoreTxt,-10,300,0);
	ObjText_SetAutoTransCenter(scoreTxt,true);*/

	let path;
	if(name=="Medi"){path=GCSD~"img/Medi.png";}
	let cut=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(cut,path);
  	if(name=="Medi"){ObjSprite2D_SetSourceRect(cut,0,0,205,410);}
	ObjRender_SetScaleXYZ(cut,1,1,1);
  	ObjSprite2D_SetDestCenter(cut);
	ObjRender_SetPosition(cut,416,120,0);
	Obj_SetRenderPriority(cut,0.50);

	TScale;
	TCut;
	TScore;
	task TScore{
	}
		
	task TScale{
	ascent(i in 0..30){
	ObjRender_SetAlpha(objTxt,i*12);
	ObjRender_SetScaleXYZ(objTxt,scale,scale,1);
	ObjRender_SetPosition(objTxt,-310+i*10,350,0);
	scale -= 0.1;
	yield;
	}
	loop(57){
	ObjRender_SetPosition(objTxt,-20,350-py,0);
	py += acc;
	acc += 0.1;
	yield;
	}
	loop(57){
	ObjRender_SetPosition(objTxt,-20,350-py,0);
	py += acc;
	acc -= 0.1;
	yield;
	}
	while(!Obj_IsDeleted(objBoss)){yield;}
		loop(20){
			alpha-=12.75;
			yscale+=0.05;
			ObjRender_SetAlpha(objTxt,alpha);
			ObjRender_SetScaleXYZ(objTxt,yscale,yscale,1);
			yield;
		}
		Obj_Delete(objTxt);
	}

	task TCut{
		let speed=1;
		ObjRender_SetAlpha(cut,0);
		ascent(i in 0..20){
			ObjRender_SetX(cut,ObjRender_GetX(cut)-speed*9);
			ObjRender_SetY(cut,ObjRender_GetY(cut)+speed*4);
			ObjRender_SetAlpha(cut,i*255/20);
			yield;
			}
		loop(80){
		ObjRender_SetX(cut,ObjRender_GetX(cut)-speed); 
		ObjRender_SetY(cut,ObjRender_GetY(cut)+speed/2); 
		yield;
		}
		descent(i in 0..20){
			ObjRender_SetX(cut,ObjRender_GetX(cut)-speed*9);
			ObjRender_SetY(cut,ObjRender_GetY(cut)+speed*4);
			ObjRender_SetAlpha(cut,i*255/20);
			yield;
			}
		Obj_Delete(cut);
		}
}

function TCharge01(x,y,size,frame,r,g,b){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/charge.png";
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,x,y,0);
	ObjRender_SetAlpha(obj,0);
	ObjRender_SetScaleXYZ(obj,size,size,0);
	ObjRender_SetColor(obj,r,g,b);
	TAlpha;
	TShrink;
	return obj;
	task TAlpha{
		let l=10;
		let alpha=255/l;
		loop(l){
			ObjRender_SetAlpha(obj,alpha);
			alpha+=255/(l*2);
			yield;
			}
		}
	task TShrink{
		let l=frame;
		let a = size*2/l/l;
		ascent(i in 0..l){
			ObjRender_SetScaleXYZ(obj,size,size,0);
			size = size-i*a;
			yield;
			}
		Obj_Delete(obj);
		
	}
}

function TCharge02(x,y,size,frame,r,g,b){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/charge.png";
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,x,y,0);
	ObjRender_SetAlpha(obj,0);
	ObjRender_SetScaleXYZ(obj,size,size,0);
	ObjRender_SetColor(obj,r,g,b);
	TAlpha;
	TShrink;
	return obj;
	task TAlpha{
		let l=10;
		let alpha=255/l;
		loop(l){
			ObjRender_SetAlpha(obj,alpha);
			alpha+=255/(l*2);
			yield;
			}
		}
	task TShrink{
			let a = size/frame;
			loop(frame){
			ObjRender_SetScaleXYZ(obj,size,size,0);
			size = size-a;
			yield;
			}
		Obj_Delete(obj);
		
	}
}