let csd = GetCurrentScriptDirectory;

let Sprite = csd~"img/Sprite.png";
let Hex = csd~"img/Hex.png";
let NBG1 = csd~"img/NBG1.png";
let BG1 = csd~"img/SpellBG1.png";
let BG2 = csd~"img/SpellBG2.png";

let Shot1 = csd~"se/Shot1.wav";
let Shot2 = csd~"se/Shot2.wav";
let Shot3 = csd~"se/Shot3.wav";
let Shot4 = csd~"se/BulletWave.wav";
let Laser1 = csd~"se/Laser1.wav";
let Laser2 = csd~"se/Laser2.wav";
let Laser3 = csd~"se/Laser3.wav";
let Laser4 = csd~"se/Laser4.wav";
let Laser5 = csd~"se/Laser5.wav";
let Charge = csd~"se/Charge2.wav";
let Charge2 = csd~"se/Charge3.wav";

let objScene;
let objEnemy;
let objHex;
let objBG1;
let objBG2;

sub InitSub
{
DeleteShotAll(TYPE_ALL, TYPE_ITEM); 		//Clear any existing bullets
objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);	//Creates the main enemy
ObjEnemy_Regist(objEnemy);			//Immediately spawns main enemy
objHex = ObjPrim_Create(OBJ_SPRITE_2D);		//Creates the hex object
objBG1 = ObjPrim_Create(OBJ_SPRITE_2D);		//Creates BG1
objBG2 = ObjPrim_Create(OBJ_SPRITE_2D);		//Creates BG2
}

task SetSpellText(string,c)	//String: Text to draw, c: Determines RGB
{
let y = 64;
let rgb;
if(c == 0){rgb = [1,0,0];}
if(c == 1){rgb = [0,1,0];}
if(c == 2){rgb = [0,0,1];}

TWait(60);

let txt = ObjText_Create;
ObjText_SetText(txt,string);
ObjText_SetFontSize(txt,12);
ObjText_SetFontColorTop(txt,255,255,255);
ObjText_SetFontColorBottom(txt,128+rgb[0]*127,128+rgb[1]*127,128+rgb[2]);

ObjText_SetFontBorderType(txt,BORDER_FULL);
ObjText_SetFontBorderColor(txt,rgb[0]*64,rgb[1]*64,rgb[2]*64);
ObjText_SetFontBorderWidth(txt,1);

ObjText_SetHorizontalAlignment(txt, ALIGNMENT_RIGHT);
ObjText_SetMaxWidth(txt, 300);
ObjRender_SetX(txt, 368 - 300);

ascent(i in 0..60)
	{
	ObjRender_SetAlpha(txt,i*255/60);
	ObjRender_SetY(txt,80-i);
	y--;
	yield;
	}


while(!Obj_IsDeleted(objEnemy)){yield;}
Obj_Delete(txt);
}

function ItemDrop(bonus)
{

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

loop(20){CreateItemA1(ITEM_POINT_S,GetX+rand(-96,96),GetY+rand(-64,64),50000);}

/*
if(bonus == 1)
	{
	CreateItemA1(ITEM_1UP,GetX,GetY,5000);
	}
else
	{
	CreateItemA1(ITEM_SPELL_S,GetX,GetY,5000);
	}
*/

}


task DrawTask(drawbg)
{
let hs = 0;
let bgs = 0;
	let acc1 = 0;
	let acc2 = 0;
	let acc3 = 0;
	let acc4 = 0;

ObjPrim_SetTexture(objEnemy, Sprite);		//Set boss texture

ObjPrim_SetTexture(objHex, Hex);		//Set hex texture
ObjRender_SetBlendType(objHex, BLEND_ADD_RGB);	//Additive mode
Obj_SetRenderPriorityI(objHex,39);

if(drawbg)
	{
	ObjPrim_SetTexture(objBG1, BG1);		//Set BG1 texture
	Obj_SetRenderPriorityI(objBG1,25);

	ObjPrim_SetTexture(objBG2, BG2);		//Set BG2 texture
	ObjRender_SetBlendType(objBG2, BLEND_ALPHA);	//Subtract mode
	ObjRender_SetAlpha(objBG2, 60);
	Obj_SetRenderPriorityI(objBG2,26);
	}

while(!Obj_IsDeleted(objEnemy))
	{
	let GetX = ObjMove_GetX(objEnemy);
	let GetY = ObjMove_GetY(objEnemy);
	let angle = ObjMove_GetAngle(objEnemy);
	let speed = ObjMove_GetSpeed(objEnemy);

	//Find out boss pose, and set rect accordingly

	ObjSprite2D_SetSourceRect(objEnemy, 0, 0, 128, 128);
	ObjSprite2D_SetDestCenter(objEnemy);
	ObjRender_SetAngleZ(objEnemy,acc3);

	//Set hex rect and position

	ObjRender_SetPosition(objHex,GetX,GetY,0);
	ObjSprite2D_SetSourceRect(objHex, 0, 0, 128, 128);
	ObjSprite2D_SetDestCenter(objHex);
	ObjRender_SetAngleZ(objHex,hs);
	ObjRender_SetScaleXYZ(objHex,1.2+acc2,1.2+acc2,1);
	hs += 8;
	acc1 += 2;	
	acc2 += 0.011*cos(acc1);
	acc3 += rand(0,360);

	if(drawbg)
		{
		ObjSprite2D_SetSourceRect(objBG1,0,bgs,512,512+bgs);
		ObjSprite2D_SetDestRect(objBG1,0,0,512,512);
		ObjSprite2D_SetSourceRect(objBG2,-bgs/3,bgs/2,512-bgs/3,512+bgs/2);
		ObjSprite2D_SetDestRect(objBG2,0,0,512,512);
		bgs++;
		}
	yield;
	}

Obj_Delete(objHex);			//Delete hex
Obj_Delete(objBG1);			//Delete BG1
Obj_Delete(objBG2);			//Delete BG2
}