

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

@Initialize
{
InitSub;

MainTask;
DrawTask(false);
FinalTask;
}

@Loading
{
LoadSound(Shot1);
LoadSound(Shot2);
LoadEnemyShotData(path);
}

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

@Event
{
alternative(GetEventType())
case(EV_REQUEST_LIFE){SetScriptResult(2800);}	//Set life to 2500
case(EV_REQUEST_TIMER){SetScriptResult(40);}	//Set timer to 40
}

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

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

let frame = 0;
let frame2 = 0;
let frame3 = 0;
let frame4 = 0;
let pattern1 = 0;
let pattern2 = 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))	//While enemy is existing...
	{
	let GetX = ObjMove_GetX(objEnemy);
	let GetY = ObjMove_GetY(objEnemy);
	let GetAngleToPlayer = atan2(GetPlayerY - GetY, GetPlayerX - GetX);

	//Pattern start

	if(frame == 120)
		{
		loop(5)
			{
			CreateShotA2(GetX+50*cos(a2+acc1),GetY+50*sin(a2+acc1),0,a2+acc1,0.1,1.5+acc2,60,10);
			CreateShotA2(GetX-50*cos(a2+acc3),GetY-50*sin(a2+acc3),0,a2+acc1+92,0.1,1.5+acc2,47,10);
			a2 += 360/5;
			}
		frame = 115;
		frame2 = 0;
		a1 += 10;
		acc1 += 11;
		a2 = 0;
		acc2 += 0.1;
		acc3 += 12;
		PlaySE(Shot1);
		}

if (acc2 >= 1){acc2 = 1;}

	//Pattern end

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

	frame++;
	frame2++;
	pattern1++;
	pattern2++;
	yield;
	}

}

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

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

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
}
