

#include"script/default_system/Default_ShotConst.txt"
#include"script/default_system/Default_Effect.txt"
#include"./lib.txt"
let path = GetCurrentScriptDirectory() ~ "sup/supershot.txt";
let path2 = GetCurrentScriptDirectory() ~ "sup/LargeLights.txt";

@Initialize
{
InitSub;

SetSpellText("Spark - Mysterious Blasts",2);
VulnTask;
MainTask;
DrawTask(true);
FinalTask;	
}

@MainLoop{yield;}
function TWait(t){loop(t){yield;}}

@Loading
{
LoadSound(Shot1);
LoadSound(Shot4);
LoadSound(Laser1);
LoadSound(Laser3);
LoadSound(Charge);
LoadSound(Charge2);
LoadEnemyShotData(path);
LoadEnemyShotData(path2);
}

@Event
{
alternative(GetEventType())
case(EV_REQUEST_LIFE){SetScriptResult(3500);}	//Set life to 3500
case(EV_REQUEST_TIMER){SetScriptResult(50);}	//Set timer to 50
case(EV_REQUEST_SPELL_SCORE){SetScriptResult(30000);}	//Set score
}

task BulletA(x,y,v,angle,graphic,delay)
{
let frame2 = 0;

	let BulletA = CreateShotA1(x,y,v,angle,graphic,delay);
	while(!Obj_IsDeleted(BulletA))
	{
		ObjMove_SetAngle(BulletA,ObjMove_GetAngle(BulletA) + 1);
		if(frame2 == 60)
		{
			CreateShotA2(ObjMove_GetX(BulletA),ObjMove_GetY(BulletA),0,atan2(GetPlayerY-ObjMove_GetY(BulletA),GetPlayerX-ObjMove_GetX(BulletA)),0.3,2,150,0);		
		PlaySE(Shot1);
		frame2 = 0;
		}
		frame2++;

		yield;
	}

}

task VulnTask
{
ObjEnemy_SetDamageRate(objEnemy, 100, 100);	//Sets damage rate
TWait(1500);					//Wait 1500 frames
ObjEnemy_SetDamageRate(objEnemy, 200, 200);	//Decrease armor
}

task MainTask
{
let cx = 192;
let cy = 224;

ObjMove_SetDestAtFrame(objEnemy, cx, cy-100, 90);	//Move in 90 frames
TWait(60);

PlaySE(Charge);
TWait(60);

objScene = GetEnemyBossSceneObjectID();
ObjEnemyBossScene_StartSpell(objScene);

let frame = 0;
let frame2 = 0;
let frame3 = 0;
let frame4 = 0;
let a1 = 0;
let a2 = 0;
let a3 = 0;
let a4 = 0;
let a5 = 0;
let a6 = 0;
let acc1 = 0;
let acc2 = 0;
let acc3 = 0;
let acc4 = 0;
let acc5 = 0;
let acc6 = 0;

while(!Obj_IsDeleted(objEnemy))
	{
	let GetX = ObjMove_GetX(objEnemy);
	let GetY = ObjMove_GetY(objEnemy);
	let GetAngleToPlayer = atan2(GetPlayerY - GetY, GetPlayerX - GetX);
	
	//Pattern start

	if(frame >= 120 && frame <= 240)
		{
		loop(1)
			{
			CreateShotA1(GetX+30*cos(a2),GetY+10*sin(a2),5,a2,218,20);
			CreateShotA1(GetX+10*cos(a2),GetY+30*sin(a2),4,-a2,217,20);
			let obj = CreateShotA2(GetX+40*cos(a2),GetY+30*sin(a2),4,a2,-0.06,0,11,20);
			ObjMove_AddPatternA3(obj,140,0,atan2(GetPlayerY - ObjMove_GetY(obj), GetPlayerX - ObjMove_GetX(obj))-rand(-10,10),0.02,0,3,11);
			a2 += 360/1;
			}
		acc3 -= 2;
		a2 += 17;
		a1 += 10;
		acc1 += 0.3;
		PlaySE(Shot1);
		}
	if(frame >= 260 && frame <= 380)
		{

		PlaySE(Shot4);
		}
	if(frame == 380)
		{
		frame = -50;
}
	//Pattern end

	//Enemy collision
	
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, GetX, GetY, 32);
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, GetX, GetY, 24);

	frame++;
	frame3++;
	yield;
	}
}

task FinalTask
{
while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0){yield;}	//Wait until death

let GetX = ObjMove_GetX(objEnemy);
let GetY = ObjMove_GetY(objEnemy);

ItemDrop(0);

TExplosionA(GetX, GetY, 10, 0.6);	//Explosion effect
DeleteShotAll(TYPE_ALL, TYPE_ITEM);	//All shots to item
Obj_Delete(objEnemy);			//Delete enemy
TWait(30);				//Wait a bit
CloseScript(GetOwnScriptID());		//End this script
}

