#ScriptVersion[3]
#ID["Marisa"]
#Title["Marisa Kirisame"]
#Text["Marisa Kirisame[r]Speed: 5,2[r]Shot: Illusion Laser[r]Spell: Love Sign \"Master Spark\"[r]Version 1.0"]
#Image[".\MarisaCutin.png"]
#ReplayName["Marisa"]

let player = GetPlayerObjectID;
let csd = GetCurrentScriptDirectory;
let img_reimu = csd~"Reimu.png";
let img_marisaeffect = csd~"MarisaEffect.png";
let img_circle = csd~"circle.png";
let img_spell = csd~"spell.png";
let array_texture = [img_marisa,img_marisaeffect,img_circle,img_spell];
let sound = [];
let shots = csd~"MarisaShot.txt";
let alive = true;
@Initialize{
	ascent(i in 0..length(array_texture)){
		LoadTexture(array_texture[i]);
	}
	loadSounds;
	LoadPlayerShotData(shots);
	SetPlayerAutoItemCollectLine(130);
	SetPlayerSpeed(5,2);
	ObjPlayer_AddIntersectionCircleA1(player,0,0,1,20);
	THitbox;
	TDraw;
	Option(-48,-32,-15,-32);
	Option(-16,-32,-5,-32);
	Option(16,-32,5,-32);
	Option(48,-32,15,-32);
	Shoot;
}

@MainLoop{
	yield;
}

@Finalize{
}

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_SPELL){
		if (GetPlayerSpell >= 1){
			SetScriptResult(true);
			SetPlayerSpell(GetPlayerSpell-1);
			Spell_1;
		}
		else{
			SetScriptResult(false);
		}
	}
	case(EV_PLAYER_SHOOTDOWN){
		alive = false;
//		loop(8){
//			CreateItemA1(ITEM_POWER_S,GetPlayerX+rand(-50,50),GetPlayerY+rand(-70,-20),10);
//		}
	}
	case(EV_PLAYER_REBIRTH){
		alive = true;
		SetPlayerSpell(3);
		SetPlayerInvincibilityFrame(180);
		Circle(150);
	}
	case(EV_GRAZE){
		play_sound(3,80);
		TGrazeEffect;
	}
	case(EV_HIT){
		play_sound(4,80);
		TDeathEffect;
	}
	case(EV_GET_ITEM){
		play_sound(5,80);
		let itemType = GetEventArgument(0);
		alternative(itemType)
			case(ITEM_SPELL){
				WriteLog("ITEM_SPELL");
			}
			case(ITEM_SPELL_S){
				WriteLog("ITEM_SPELL_S");
			}
			case(ITEM_POWER){
				WriteLog("ITEM_POWER");
			}
			case(ITEM_POWER_S){
				WriteLog("ITEM_POWER_S");
			}
	}
}

function loadSounds{
	//Array sound
	//0 - Shot
	//1 - Spark
	//2 - Spell
	//3 - Graze
	//4 - Hit
	//5 - Item
	let snd_shot = ObjSound_Create;
	ObjSound_Load(snd_shot,csd~"se_plst00.wav");
	ObjSound_SetSoundDivision(snd_shot,SOUND_SE);
	sound = sound ~ [snd_shot];

	let snd_spark = ObjSound_Create;
	ObjSound_Load(snd_spark,csd~"snd_spark.wav");
	ObjSound_SetSoundDivision(snd_spark,SOUND_SE);
	sound = sound ~ [snd_spark];

	let snd_spell = ObjSound_Create;
	ObjSound_Load(snd_spell,csd~"se_slash.wav");
	ObjSound_SetSoundDivision(snd_spell,SOUND_SE);
	sound = sound ~ [snd_spell];

	let snd_graze = ObjSound_Create;
	ObjSound_Load(snd_graze,csd~"se_graze.wav");
	ObjSound_SetSoundDivision(snd_spell,SOUND_SE);
	sound = sound ~ [snd_graze];

	let snd_hit = ObjSound_Create;
	ObjSound_Load(snd_hit,csd~"se_pldead00.wav");
	ObjSound_SetSoundDivision(snd_hit,SOUND_SE);
	sound = sound ~ [snd_hit];

	let snd_item = ObjSound_Create;
	ObjSound_Load(snd_item,csd~"se_item00.wav");
	ObjSound_SetSoundDivision(snd_item,SOUND_SE);
	sound = sound ~ [snd_item];
}

function play_sound(value,volume){
	ObjSound_SetVolumeRate(sound[value],volume);
	ObjSound_Play(sound[value]);
}

task TGrazeEffect{
	let px = GetPlayerX;
	let py = GetPlayerY;
	let x = px;
	let y = py;
	let scale = 1;
	let direction = rand(0,360);

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,img_marisa);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(obj,84,282,92,290);
	ObjSprite2D_SetDestRect(obj,-4,-4,4,4);
	ObjRender_SetAngleZ(obj,rand(0,360));
	ObjRender_SetPosition(obj,px,py,0);
	loop(15){
		x += 5*cos(direction);
		y += 5*sin(direction);
		ObjRender_SetPosition(obj,x,y,0);

		scale -= 0.0667;
		ObjRender_SetScaleXYZ(obj,scale,scale,1);

		yield;
	}

	Obj_Delete(obj);
}

task TDeathEffect{
	let px = GetPlayerX;
	let py = GetPlayerY;
	let scale = 1;
	let alpha = 255;
	let frame = 0;

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,img_marisa);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(obj,31,348,95,412);
	ObjSprite2D_SetDestRect(obj,-32,-32,32,32);
	ObjRender_SetPosition(obj,px,py,0);
	loop(25){	//May change...
		frame ++;
		scale += 0.16;//= 4*(1-((frame/25)-1)^2);
		ObjRender_SetScaleXYZ(obj,scale,scale,1);
		ObjRender_SetAlpha(obj,alpha);
		alpha -= 10.2;
	//	DeleteShotInCircle(TYPE_ALL,TYPE_FADE,px,py,scale*32);	//Having an error with this where it deletes shots that are resistant to spells

		yield;
	}

	Obj_Delete(obj);
}

task THitbox{
	let angle = 0;
	let scale = 0;
	let hitbox = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(hitbox,img_marisa);
	ObjRender_SetBlendType(hitbox,BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(hitbox,5,443,68,506);//69,507
	ObjSprite2D_SetDestRect(hitbox,-32,-32,32,32);
	loop{
		if (GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH){
			scale = 0;
			angle = 0;
		}
		if (GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD && scale < 100){
			scale += 10;
		}
		if (GetVirtualKeyState(VK_SLOWMOVE) == KEY_PULL || GetVirtualKeyState(VK_SLOWMOVE) == KEY_FREE && scale > 0){
			scale -= 10;
		}
		ObjRender_SetPosition(hitbox,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAngleZ(hitbox,angle);
		ObjRender_SetScaleXYZ(hitbox,scale*0.01,scale*0.01,1);
		angle += 2;
		yield;
	}
}

task Circle(maxtime){
	let circle = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let radius = 1;
	let angle = 0;
	let alpha = 0;
	ObjPrim_SetPrimitiveType(circle,PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(circle,130);
	ObjRender_SetBlendType(circle,BLEND_ADD_RGB);
	Obj_SetRenderPriority(circle,0.6);
	ObjPrim_SetTexture(circle,img_circle);
	ascent(i in 0..65){
		ObjPrim_SetVertexUVT(circle,(i*2),i*6*(242/64),0);
		ObjPrim_SetVertexUVT(circle,(i*2)+1,i*6*(242/64),60);
	}
	loop(maxtime){
		if (alpha < 1){
			alpha += (1/80);
		}
		if (alpha > 1){
			alpha = 1;
		}
		ascent(i in 0..65){
			ObjPrim_SetVertexPosition(circle,(i*2),radius*150*cos(i*360/64),radius*150*sin(i*360/64),0);
			ObjPrim_SetVertexPosition(circle,(i*2)+1,radius*120*cos(i*360/64),radius*120*sin(i*360/64),0);
		}
		ObjRender_SetAngleZ(circle,angle);
		ObjRender_SetColor(circle,alpha*128,alpha*128,alpha*128);
		ObjRender_SetPosition(circle,GetPlayerX,GetPlayerY,0);
		radius -= (1/maxtime);
		if (angle < 0){angle += 360;}
		angle -= 2;
		yield;
	}
	Obj_Delete(circle);
}

task TDraw{
	let phase = 0;
	let frame0 = 0;
	let frame1 = 0;
	let frame2 = 0;
	let left = false;
	ObjPrim_SetTexture(player,img_reimu);
	loop{
		if (GetVirtualKeyState(VK_LEFT) == KEY_PUSH ||
		GetVirtualKeyState(VK_LEFT) == KEY_HOLD ||
		GetVirtualKeyState(VK_RIGHT) == KEY_PUSH ||
		GetVirtualKeyState(VK_RIGHT) == KEY_HOLD){
			phase = 1;
		}
		else{
			if (phase == 1 || phase == 2){
				phase = 2;
			}
			else{
				phase = 0;
			}
		}
		alternative(phase)
		case(0){phase0;}
		case(1){phase1;}
		case(2){phase2;}
		ObjSprite2D_SetDestRect(player,-16,-24,16,24);
		yield;
	}
	function phase0{
		frame1 = 0;
		frame2 = 0;
		alternative(frame0)
		case(0,1,2,3,4){ObjSprite2D_SetSourceRect(player,0,0,32,48);}
		case(5,6,7,8,9){ObjSprite2D_SetSourceRect(player,32,0,64,48);}
		case(10,11,12,13,14){ObjSprite2D_SetSourceRect(player,64,0,96,48);}
		case(15,16,17,18,19){ObjSprite2D_SetSourceRect(player,96,0,128,48);}
		case(20,21,22,23,24){ObjSprite2D_SetSourceRect(player,128,0,160,48);}
		case(25,26,27,28,29){ObjSprite2D_SetSourceRect(player,160,0,192,48);}
		case(30,31,32,33,34){ObjSprite2D_SetSourceRect(player,192,0,224,48);}
		case(35,36,37,38,39){ObjSprite2D_SetSourceRect(player,224,0,256,48);}
		frame0 ++;
		if (frame0 >= 40){frame0 = 0;}
	}
	function phase1{
		frame0 = 0;
		frame2 = 0;
		if (GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_RIGHT) == KEY_HOLD){
			alternative(frame1)
			case(0){ObjSprite2D_SetSourceRect(player,32,96,64,144);}
			case(1){ObjSprite2D_SetSourceRect(player,64,96,96,144);}
			case(2){ObjSprite2D_SetSourceRect(player,96,96,128,144);}
			case(3,4,5,6,7){ObjSprite2D_SetSourceRect(player,128,96,160,144);}
			case(8,9,10,11,12){ObjSprite2D_SetSourceRect(player,160,96,192,144);}
			case(13,14,15,16,17){ObjSprite2D_SetSourceRect(player,192,96,224,144);}
			case(18,19,20,21,22){ObjSprite2D_SetSourceRect(player,224,96,256,144);}
			left = false;
		}
		else if (GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_LEFT) == KEY_HOLD){
			alternative(frame1)
			case(0){ObjSprite2D_SetSourceRect(player,32,48,64,96);}
			case(1){ObjSprite2D_SetSourceRect(player,64,48,96,96);}
			case(2){ObjSprite2D_SetSourceRect(player,96,48,128,96);}
			case(3,4,5,6,7){ObjSprite2D_SetSourceRect(player,128,48,160,96);}
			case(8,9,10,11,12){ObjSprite2D_SetSourceRect(player,160,48,192,96);}
			case(13,14,15,16,17){ObjSprite2D_SetSourceRect(player,192,48,224,96);}
			case(18,19,20,21,22){ObjSprite2D_SetSourceRect(player,224,48,256,96);}
			left = true;
		}
		frame1 ++;
		if (frame1 >= 23){frame1 = 3;}
	}
	function phase2{
		frame0 = 0;
		frame1 = 0;
		if (left){
			alternative(frame2)
			case(0){ObjSprite2D_SetSourceRect(player,96,48,128,96);}
			case(1){ObjSprite2D_SetSourceRect(player,64,48,96,96);}
			case(2){ObjSprite2D_SetSourceRect(player,32,48,64,96);}
			case(3){
				phase = 0;
				phase0;
			}
		}
		else{
			alternative(frame2)
			case(0){ObjSprite2D_SetSourceRect(player,96,96,128,144);}
			case(1){ObjSprite2D_SetSourceRect(player,64,96,96,144);}
			case(2){ObjSprite2D_SetSourceRect(player,32,96,64,144);}
			case(3){
				phase = 0;
				phase0;
			}
		}
		frame2 ++;
	}
}

task ShotFade(x,y){
	let count = 0;
	let obj_shotfade = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj_shotfade,BLEND_ADD_RGB);
	ObjPrim_SetTexture(obj_shotfade,img_marisaeffect);
	ObjSprite2D_SetSourceRect(obj_shotfade,0,64,16,96);
	ObjSprite2D_SetDestRect(obj_shotfade,-32,-8,32,8);
	while(!Obj_IsDeleted(obj_shotfade)){
		if (count >= 15){
			Obj_Delete(obj_shotfade);
		}
		ObjRender_SetColor(obj_shotfade,100-(count*7),100-(count*7),100-(count*7));
		ObjRender_SetPosition(obj_shotfade,x,y,0);
		ObjSprite2D_SetDestCenter(obj_shotfade);
		y -= 2;
		count ++;
		yield;
	}
}

task Shot(x,y,speed,graphic,damage){
	let obj_shot = ObjShot_Create(OBJ_SHOT);
	Obj_SetVisible(obj_shot,true);
	ObjMove_SetX(obj_shot,x);
	ObjMove_SetY(obj_shot,y);
	ObjMove_SetSpeed(obj_shot,speed);
	ObjMove_SetAngle(obj_shot,270);
	ObjRender_SetAlpha(obj_shot,90);
	ObjShot_SetGraphic(obj_shot,graphic);
	ObjShot_SetDamage(obj_shot,damage);
	ObjShot_SetPenetration(obj_shot,1);
	ObjShot_Regist(obj_shot);
	while(!Obj_IsDeleted(obj_shot)){
		x = ObjMove_GetX(obj_shot);
		y = ObjMove_GetY(obj_shot);
		if (ObjMove_GetY(obj_shot) < -64){Obj_Delete(obj_shot);}
		yield;
	}
	ShotFade(x,y);
}

task Shoot{
	let shotcount = -1;
	loop{
		if (GetVirtualKeyState(VK_SHOT) == KEY_PUSH || GetVirtualKeyState(VK_SHOT) == KEY_HOLD && shotcount == -1 && alive){
			shotcount = 0;
		}
		if (shotcount == 0){
			if (IsPermitPlayerShot){
				Shot(GetPlayerX-10,GetPlayerY,20,1,3.5);
				Shot(GetPlayerX+10,GetPlayerY,20,1,3.5);
				play_sound(0,70);
			}
		}
		if (shotcount >= 0){
			shotcount ++;
		}
		if (shotcount >= 3){
			shotcount = -1;
		}
		yield;
	}
}

task glow(x1,y1,x2,y2){
	let x = GetPlayerX;
	let y = GetPlayerY;
	let destx = GetPlayerX+x1;
	let desty = GetPlayerY+y1;
	let dir;
	let dist;
	let a = 0;
	let glow = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(glow,BLEND_ADD_RGB);
	ObjPrim_SetTexture(glow,img_marisaeffect);
	Obj_SetRenderPriority(glow,0.42);
	ObjSprite2D_SetSourceRect(glow,0,142,33,174);
	ObjSprite2D_SetDestRect(glow,-17,-16,16,16);
	loop{
		if (GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD){
			destx = GetPlayerX+x2;
			desty = GetPlayerY+y2;
		}
		else{
			destx = GetPlayerX+x1;
			desty = GetPlayerY+y1;
		}
		dir = atan2(desty-y,destx-x);
		dist = GetDist(x,y,destx,desty);
		x += 0.25*dist*cos(dir);
		y += 0.25*dist*sin(dir);
		if (GetVirtualKeyState(VK_SHOT) == KEY_PUSH || GetVirtualKeyState(VK_SHOT) == KEY_HOLD && alive && IsPermitPlayerShot){
			Obj_SetVisible(glow,true);
		}
		else{
			Obj_SetVisible(glow,false);
		}
		ObjRender_SetScaleXYZ(glow,0.75+0.2*cos(a*2),0.75+0.2*cos(a*2),1);
		ObjRender_SetAngleXYZ(glow,0,0,a);
		ObjRender_SetPosition(glow,x,y,0);
		if (GetVirtualKeyState(VK_SHOT) == KEY_PUSH || GetVirtualKeyState(VK_SHOT) == KEY_HOLD && alive && IsPermitPlayerShot){
			a += 20;
		}
		else{
			a = 0;
		}
		yield;
	}
}

task Lasereffect(x1,y1,x2,y2){
	let x = GetPlayerX;
	let y = GetPlayerY;
	let destx = GetPlayerX+x1;
	let desty = GetPlayerY+y1;
	let dir;
	let dist;
	let count = 0;
	let scale = 0;
	let effect = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(effect,BLEND_ADD_RGB);
	Obj_SetRenderPriority(effect,0.41);
	ObjPrim_SetTexture(effect,img_marisa);
	ObjSprite2D_SetSourceRect(effect,264,count,278,512+count);
	ObjSprite2D_SetDestRect(effect,-7,-512,7,0);
	glow(x1,y1,x2,y2);
	loop{
		if (GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD){
			destx = GetPlayerX+x2;
			desty = GetPlayerY+y2;
		}
		else{
			destx = GetPlayerX+x1;
			desty = GetPlayerY+y1;
		}
		if (GetVirtualKeyState(VK_SHOT) == KEY_PUSH || GetVirtualKeyState(VK_SHOT) == KEY_HOLD && alive && IsPermitPlayerShot){
			if (scale < 1){
				scale += 0.05;
			}
			if (scale > 1){
				scale = 1;
			}
		}
		else{
			if (scale > 0){
				scale -= 0.05;
			}
			if (scale < 0){
				scale = 0;
			}
		}
		dir = atan2(desty-y,destx-x);
		dist = GetDist(x,y,destx,desty);
		x += 0.25*dist*cos(dir);
		y += 0.25*dist*sin(dir);
		ObjSprite2D_SetSourceRect(effect,264,count,278,512+count);
		ObjRender_SetScaleXYZ(effect,scale,1,1);
		ObjRender_SetPosition(effect,x,y,0);
		count += 7;
		if (count > 512){
			count -= 512;
		}
		yield;
	}
}

task Laser(x1,y1,x2,y2){
	let x = GetPlayerX;
	let y = GetPlayerY;
	let destx = GetPlayerX+x1;
	let desty = GetPlayerY+y1;
	let dir;
	let dist;
	let laser = ObjShot_Create(OBJ_STRAIGHT_LASER);
	Obj_SetVisible(laser,false);
	ObjShot_Regist(laser);
	ObjShot_SetAutoDelete(laser,false);
	ObjShot_SetGraphic(laser,2);
	ObjShot_SetDamage(laser,0.55);
	ObjMove_SetPosition(laser,GetPlayerX,GetPlayerY);
	ObjLaser_SetLength(laser,512);
	ObjLaser_SetRenderWidth(laser,14);
	ObjLaser_SetIntersectionWidth(laser,14);
	Lasereffect(x1,y1,x2,y2);
	loop{
		if (IsPermitPlayerShot){ObjShot_SetDamage(laser,0.55);}
		else{ObjShot_SetDamage(laser,0);}
		if (GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD){
			destx = GetPlayerX+x2;
			desty = GetPlayerY+y2;
		}
		else{
			destx = GetPlayerX+x1;
			desty = GetPlayerY+y1;
		}
		dir = atan2(desty-y,destx-x);
		dist = GetDist(x,y,destx,desty);
		x += 0.25*dist*cos(dir);
		y += 0.25*dist*sin(dir);
		if (GetVirtualKeyState(VK_SHOT) == KEY_PUSH || GetVirtualKeyState(VK_SHOT) == KEY_HOLD && alive){
			ObjMove_SetPosition(laser,x,y);
		}
		else{
			ObjMove_SetPosition(laser,-1000,-1000);
		}
		yield;
	}
}

task Optionshadow(x1,y1,x2,y2){
	let x = GetPlayerX;
	let y = GetPlayerY;
	let destx = GetPlayerX+x1;
	let desty = GetPlayerY+y1;
	let dir;
	let dist;
	let shadow = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(shadow,BLEND_ADD_RGB);
	Obj_SetRenderPriority(shadow,0.3);
	ObjPrim_SetTexture(shadow,img_marisaeffect);
	ObjSprite2D_SetSourceRect(shadow,1,98,15,112);
	ObjSprite2D_SetDestRect(shadow,-7,-7,7,7);
	loop{
		if (GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD){
			destx = GetPlayerX+x2;
			desty = GetPlayerY+y2;
		}
		else{
			destx = GetPlayerX+x1;
			desty = GetPlayerY+y1;
		}
		dir = atan2(desty-y,destx-x);
		dist = GetDist(x,y,destx,desty);
		x += 0.25*dist*cos(dir);
		y += 0.25*dist*sin(dir);
		ObjRender_SetColor(shadow,90,90,90);
		ObjRender_SetScaleXYZ(shadow,1.75,1.75,1);
		ObjRender_SetPosition(shadow,x,y,0);
		yield;
	}
}
task Option(x1,y1,x2,y2){
	let x = GetPlayerX;
	let y = GetPlayerY;
	let destx = GetPlayerX+x1;
	let desty = GetPlayerY+y1;
	let dir;
	let dist;
	let count = 0;
	Laser(x1,y1,x2,y2);
	let option = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(option,BLEND_ALPHA);
	Obj_SetRenderPriority(option,0.31);
	ObjPrim_SetTexture(option,img_marisa);
	ObjSprite2D_SetSourceRect(option,81,161,95,175);
	ObjSprite2D_SetDestRect(option,-7,-7,7,7);
	Optionshadow(x1,y1,x2,y2);
	loop{
		if (GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD){
			destx = GetPlayerX+x2;
			desty = GetPlayerY+y2;
		}
		else{
			destx = GetPlayerX+x1;
			desty = GetPlayerY+y1;
		}
		dir = atan2(desty-y,destx-x);
		dist = GetDist(x,y,destx,desty);
		x += 0.25*dist*cos(dir);
		y += 0.25*dist*sin(dir);
		ObjRender_SetScaleXYZ(option,1+0.15*sin(count*10),1+0.15*sin(count*10),1);
		ObjRender_SetPosition(option,x,y,0);
		count ++;
		if (count > 360){count -= 360;}
		yield;
	}
}

function GetDist(x1,y1,x2,y2){
	return ((x2-x1)^2+(y2-y1)^2)^0.5;
}

task Shake(time){
	let frame = 0;
	let ratio = 1;
	loop(time){
		if (time-frame <= 70){
			ratio -= (1/70);
		}
		Set2DCameraFocusX(GetStgFrameWidth/2 + ratio*rand(-14,14));
		Set2DCameraFocusY(GetStgFrameHeight/2 + ratio*rand(-14,14));
		frame ++;
		yield;
	}
	Reset2DCamera;
}

task Spell_1{	//Focused Spell
	SetPlayerInvincibilityFrame(430);
	SetPlayerSpeed(1,0.5);
	Circle(430);
	play_sound(2,100);
	play_sound(1,100);
	Shake(296);
	Spark;
	loop(296){yield;}
	SetPlayerSpeed(5,2);
	Obj_Delete(GetSpellManageObject);
	task Spark{
		let alpha = 0;
		let spark = ObjSpell_Create;
		Alpha;
		LittleSpark(128);
		LittleSpark(90);
		ObjPrim_SetTexture(spark,img_spell);
		ObjPrim_SetVertexCount(spark,4);
		ObjPrim_SetPrimitiveType(spark,PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexUVT(spark,0,256,0);
		ObjPrim_SetVertexUVT(spark,1,256,128);
		ObjPrim_SetVertexUVT(spark,2,1,128);
		ObjPrim_SetVertexUVT(spark,3,1,0);
		ObjPrim_SetVertexPosition(spark,0,-166,-511,0);
		ObjPrim_SetVertexPosition(spark,1,166,-511,0);
		ObjPrim_SetVertexPosition(spark,2,166,0,0);
		ObjPrim_SetVertexPosition(spark,3,-166,0,0);
		ObjRender_SetBlendType(spark,BLEND_ADD_RGB);
		Obj_SetRenderPriority(spark,0.6);
		ObjSpell_Regist(spark);
		ObjSpell_SetDamage(spark,6);
		loop(296){
			ObjRender_SetColor(spark,alpha,alpha,alpha);
			ObjRender_SetPosition(spark,GetPlayerX,GetPlayerY,0);
			ObjSpell_SetIntersectionLine(spark,GetPlayerX,GetPlayerY,GetPlayerX,GetPlayerY-500,166);
			yield;
		}
		Obj_Delete(spark);
		task Alpha{
			loop(40){
				alpha += 3.2;
				yield;
			}
			loop(186){yield;}
			loop(70){
				alpha -= 1.9;
				yield;
			}
		}
		task LittleSpark(width){
			let alpha = 0;
			let spark = ObjSpell_Create;
			Alpha;
			ObjPrim_SetTexture(spark,img_spell);
			ObjPrim_SetVertexCount(spark,4);
			ObjPrim_SetPrimitiveType(spark,PRIMITIVE_TRIANGLEFAN);
			ObjPrim_SetVertexUVT(spark,0,256,0);
			ObjPrim_SetVertexUVT(spark,1,256,128);
			ObjPrim_SetVertexUVT(spark,2,1,128);
			ObjPrim_SetVertexUVT(spark,3,1,0);
			ObjPrim_SetVertexPosition(spark,0,-width,-511,0);
			ObjPrim_SetVertexPosition(spark,1,width,-511,0);
			ObjPrim_SetVertexPosition(spark,2,width,0,0);
			ObjPrim_SetVertexPosition(spark,3,-width,0,0);
			ObjRender_SetBlendType(spark,BLEND_ADD_RGB);
			Obj_SetRenderPriority(spark,0.6);
			ObjSpell_Regist(spark);
			ObjSpell_SetDamage(spark,0);
			loop(296){
				ObjRender_SetColor(spark,alpha,alpha,alpha);
				ObjRender_SetPosition(spark,GetPlayerX,GetPlayerY,0);
				ObjSpell_SetIntersectionLine(spark,GetPlayerX,GetPlayerY,GetPlayerX,GetPlayerY-500,166);
				yield;
			}
			Obj_Delete(spark);
			task Alpha{
				loop(40){
					alpha += 3.2;
					yield;
				}
				loop(186){yield;}
				loop(70){
					alpha -= 1.9;
					yield;
				}
			}
		}
	}
}