#TouhouDanmakufu[Player]
#ScriptVersion[2]
#Menu[Masahiro Hamasaki]
#Text[Attack Type: 5 Elements]
#Image[.\Images\MasahiroSelect.png]
#ReplayName[Masahiro Hamasaki]

script_player_main{

SetCommonData("PlayerType",1);

//GENERAL

let allowattack=0;
let shooton=0;
let focus=0;
let focusscale=0;
let invin=0;
let invintime=0;
let hitboxfade=0;
let justcontinued=false;
let nrofbombs=0;
let newbombs=3;
let dead=0;

//ELEMENT SWITCH

let EFelementcircle=0;
let elementcircle=[];
let EFelementbar1=0;
let EFelementbar2=0;

let elementswitch=false;
let cancelswitch=false;

let currentelement=0;
let newelement=0;
let elementincrease=0;

let elementspin=GetCommonData("PlayerType")*72;

let elementswitchtime=0;
let elementbarsize=0;

let elementsfade=255;

//FAMILIARS

let familiars=[0,0,0,0,0,0];
let nroffamiliars=0;

let ani=0;

//SHOT TYPES

//Fire
let core=0; let coremovetime=0; let coremovecounter=0; let coreangle=0; let coreaccel=0;
let angle1a=0; let angle1b=0;

//Water
let angle2a=0; let angle2b=0;

//Earth
let angle3a=0; let angle3b=0;

//Wood
let shot4a=0; let bullet4a=[]; let timer4a=[];
let shot4b=0; let bullet4b=[]; let timer4b=[];
let shot4c=0; let bullet4c=[]; let timer4c=[];
let shot4d=0; let bullet4d=[]; let timer4d=[];

//Metal
let angle5a=0; let graphic5a=0;

//OTHER

let GRfamiliars=GetCurrentScriptDirectory~"Images\Familiars.png";
let GRmasahiro=GetCurrentScriptDirectory~"Images\MasahiroPlayer.png";
let GRfocus=GetCurrentScriptDirectory~"Images\FocusCircle.png";
let GRinvin=GetCurrentScriptDirectory~"Images\InvincibilityCircle.png";
let GRhitbox=GetCurrentScriptDirectory~"Images\Hitbox.png";
let GRelementcycle=GetCurrentScriptDirectory~"Images\ElementCycle.png";
let GRelementload=GetCurrentScriptDirectory~"Images\ElementLoad.png";

let SEshot1=GetCurrentScriptDirectory~"Sounds\Shot1.wav";
let SEdeathbomb=GetCurrentScriptDirectory~"Sounds\DeathBomb.wav";

let SEswitchelement=GetCurrentScriptDirectory~"Sounds\SwitchElement.wav";
let SEchooseelement=GetCurrentScriptDirectory~"Sounds\ChooseElement.wav";

let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let time=0; let frame=0;

SetCommonData("PlayerType",GetCommonDataDefault("PlayerType",1));
SetCommonData("Power",GetCommonDataDefault("Power",0));
SetCommonData("Points",GetCommonDataDefault("Points",0));

LoadCommonData;

SetCommonData("MaxPoints",0);
SetCommonData("BombOn",0); 
SetCommonData("EndOfBomb",0); 
SetCommonData("ItemRadius",24);
SetCommonData("ItemCollect",0);
SetCommonData("ItemCollectLine",0);
SetCommonData("ResetPlayer",0);
SetCommonData("DrainPower",0);

@Initialize{
	LoadGraphic("\script\Images\OtherEffects\Items.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\Familiars.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\MasahiroPlayer.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\FocusCircle.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\SpellCircle.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\InvincibilityCircle.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\Hitbox.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\ElementCycle.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\ElementLoad.png");

	LoadGraphic(GetCurrentScriptDirectory~"Images\BombFire1.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\BombFire2.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\ExplosionAdd.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\BackgroundFire.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\BombWater.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\BombEarth1.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\BombEarth2.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\BombEarth3.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\BombWood1.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\BombWood2.png");
	LoadGraphic(GetCurrentScriptDirectory~"Images\BombMetal.png");

	LoadSE(GetCurrentScriptDirectory~"Sounds\Shot1.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\DeathBomb.wav");

	LoadSE(GetCurrentScriptDirectory~"Sounds\BombFire1.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombFire2.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombFire3.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombWater1.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombWater2.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombEarth1.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombEarth2.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombWood1.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombWood2.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombMetal1.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombMetal2.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\BombMetal3.wav");

	LoadSE(GetCurrentScriptDirectory~"Sounds\SwitchElement.wav");
	LoadSE(GetCurrentScriptDirectory~"Sounds\ChooseElement.wav");

	LoadPlayerShotData(GetCurrentScriptDirectory~"MasahiroShot.txt");

	if(GetCommonData("PlayerType")!=1){ SetRibirthFrame(20); }
	if(GetCommonData("PlayerType")==1){ SetRibirthFrame(26); }
	if(GetCommonData("PlayerType")!=5){ SetInitialBombCount(3); }
	if(GetCommonData("PlayerType")==5 && nrofbombs>3){ SetInitialBombCount(nrofbombs); }
	if(GetCommonData("PlayerType")==5 && nrofbombs<=3){ SetInitialBombCount(3); }
	if(GetCommonData("PlayerType")!=4){ SetSpeed(4.5,2); }
	if(GetCommonData("PlayerType")==4){ SetSpeed(4,1.5); }
	if(GetCommonData("PlayerType")!=2){ SetCommonData("ItemRadius",20); SetItemCollectLine(160); SetCommonData("ItemCollectLine",160); }
	if(GetCommonData("PlayerType")==2){ SetCommonData("ItemRadius",30); SetItemCollectLine(GetCenterY); SetCommonData("ItemCollectLine",200); }
}
	
@MainLoop{

if(GetPlayerLife<=1){ justcontinued=true; }
if(Continued==true && justcontinued==true && GetPlayerLife>3){ while(GetPlayerLife>3){ ExtendPlayer(-1); } justcontinued=false; }
if(GetPlayerLife>1){ justcontinued=false; }

if(GetCommonDataDefault("Stage",0)>0){ SetCommonData("TotalTime",GetCommonData("TotalTime")+(1/60)); }

if(GetCommonDataDefault("InEvent",0)==0 && GetKeyState(VK_SLOWMOVE)==KEY_HOLD){ SetCommonData("FocusTime",GetCommonDataDefault("FocusTime",0)+(1/60)); }

SetIntersectionCircle(GetPlayerX,GetPlayerY,0);
if(GetCommonData("InEvent")==1){ allowattack=0; SetPlayerInvincibility(2); }
if(GetCommonData("InEvent")==0){ allowattack=1; }



if(OnMissed==false && dead==1){
	if(OnBomb==false){
		if(GetCommonData("PlayerType")!=5){ SetInitialBombCount(3); }
		if(GetCommonData("PlayerType")==5 && newbombs>3){ SetInitialBombCount(newbombs); }
		if(GetCommonData("PlayerType")==5 && newbombs<=3){ SetInitialBombCount(3); }
	}
	dead=0;
}

if(OnMissed==false){ newbombs=GetPlayerBomb; }

if(OnMissed==true){ dead=1; }


//===================================================================================================================
//Change Element

currentelement=GetCommonData("PlayerType");
	
if(GetKeyState(VK_USER)==KEY_PUSH && GetCommonDataDefault("Stage",0)>=0 && GetCommonDataDefault("InEvent",0)==0 && GetCommonDataDefault("InSpellcardPractise",0)==0 && OnBomb==false){
	newelement++;
	if(newelement>5){ newelement-=5; }
	elementswitch=true;
	elementswitchtime=0;
	elementbarsize=0;
	PlaySE(SEswitchelement);
}

let nextelement=currentelement+newelement;
if(nextelement>5){ nextelement-=5; }

if(cancelswitch==false){
	if(elementspin!=nextelement*72){ elementspin+=72/12; }
	if(elementspin>360){ elementspin-=360; }
}
if(cancelswitch==true){
	if(elementspin!=nextelement*72){ elementspin-=72/6; }
	if(elementspin<=0){ elementspin+=360; }
}

if(elementswitch==true){ elementswitchtime++; elementbarsize+=1/150; }

if(elementswitchtime>=150 && currentelement!=nextelement){
	elementswitch=false;
	cancelswitch=false;
	elementbarsize=0;
	SetCommonData("PlayerType",nextelement);
	currentelement=GetCommonData("PlayerType");
	newelement=0;
	nextelement=0;
	elementswitchtime=0;
	elementbarsize=0;
	SetCommonData("DrainPower",4);
	SetCommonData("NotSwitchedElements",1);
	SetCommonData("ResetPlayer",1);
	PlaySE(SEchooseelement);
}
if(elementswitchtime>=150 && currentelement==nextelement){
	elementswitch=false;
	cancelswitch=false;
	elementbarsize=0;
	currentelement=GetCommonData("PlayerType");
	newelement=0;
	nextelement=0;
	elementswitchtime=0;
	elementbarsize=0;
}

//===================================================================================================================
//Reset Player

if(GetCommonDataDefault("ResetPlayer",0)==1){
let i=0;
	while(i<length(familiars)){
	Obj_Delete(familiars[i]);
	i++;
	}

let i=0;
	while(i<length(elementcircle)){
	if(Obj_BeDeleted(elementcircle[i])){ i--; }
	else{ Obj_Delete(elementcircle[i]); }
	i++;
	}
while(length(elementcircle)>0){ elementcircle=erase(elementcircle,0); }

	Obj_Delete(EFelementbar1);
	Obj_Delete(EFelementbar2);
	Obj_Delete(core);

	if(GetCommonData("PlayerType")!=1){ SetRibirthFrame(20); }
	if(GetCommonData("PlayerType")==1){ SetRibirthFrame(26); }
	if(GetCommonData("PlayerType")!=4){ SetSpeed(4.5,2); }
	if(GetCommonData("PlayerType")==4){ SetSpeed(4,1.5); }
	if(GetCommonData("PlayerType")!=2){ SetCommonData("ItemRadius",20); SetItemCollectLine(160); SetCommonData("ItemCollectLine",160); }
	if(GetCommonData("PlayerType")==2){ SetCommonData("ItemRadius",30); SetItemCollectLine(GetCenterY); SetCommonData("ItemCollectLine",200); }

	elementswitch=false;
	cancelswitch=false;
	newelement=0;
	nextelement=0;
	elementswitchtime=0;
	elementbarsize=0;

	SetCommonData("SwitchElement",0);
	SetCommonData("ResetPlayer",0);
	time=0;
}


//===================================================================================================================

//Make Famliars

if(time==0){
let i=0;
let opacity=255;
if(GetCommonData("PlayerType")==1){ nroffamiliars=5; opacity=155; }
if(GetCommonData("PlayerType")==5){ nroffamiliars=6; opacity=210; }
if(GetCommonData("PlayerType")==4){ nroffamiliars=2; opacity=255; }
if(GetCommonData("PlayerType")==3){ nroffamiliars=4; opacity=255; }
if(GetCommonData("PlayerType")==2){ nroffamiliars=3; opacity=210; }
	loop(nroffamiliars){
	familiars[i]=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(familiars[i],GetPlayerX,GetPlayerY);
	ObjEffect_SetScale(familiars[i],1,1);
	ObjEffect_SetLayer(familiars[i],1); ObjEffect_SetTexture(familiars[i],GRfamiliars); ObjEffect_SetRenderState(familiars[i],ALPHA);
	ObjEffect_SetPrimitiveType(familiars[i],PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(familiars[i],4);
		if(GetCommonData("PlayerType")==1){
		ObjEffect_SetRenderState(familiars[i],ADD);
		ObjEffect_SetVertexXY(familiars[i],0,-15,-15); ObjEffect_SetVertexUV(familiars[i],0,0,0);
		ObjEffect_SetVertexXY(familiars[i],1,15,-15); ObjEffect_SetVertexUV(familiars[i],1,30,0);
		ObjEffect_SetVertexXY(familiars[i],2,-15,15); ObjEffect_SetVertexUV(familiars[i],2,0,29);
		ObjEffect_SetVertexXY(familiars[i],3,15,15); ObjEffect_SetVertexUV(familiars[i],3,30,29);
		}
		if(GetCommonData("PlayerType")==5){
		ObjEffect_SetVertexXY(familiars[i],0,-10,-10); ObjEffect_SetVertexUV(familiars[i],0,79,31);
		ObjEffect_SetVertexXY(familiars[i],1,10,-10); ObjEffect_SetVertexUV(familiars[i],1,99,31);
		ObjEffect_SetVertexXY(familiars[i],2,-10,10); ObjEffect_SetVertexUV(familiars[i],2,79,51);
		ObjEffect_SetVertexXY(familiars[i],3,10,10); ObjEffect_SetVertexUV(familiars[i],3,99,51);
		}
		if(GetCommonData("PlayerType")==4){
		ObjEffect_SetVertexXY(familiars[i],0,-15,-14); ObjEffect_SetVertexUV(familiars[i],0,48,31);
		ObjEffect_SetVertexXY(familiars[i],1,15,-14); ObjEffect_SetVertexUV(familiars[i],1,78,31);
		ObjEffect_SetVertexXY(familiars[i],2,-15,14); ObjEffect_SetVertexUV(familiars[i],2,48,59);
		ObjEffect_SetVertexXY(familiars[i],3,15,14); ObjEffect_SetVertexUV(familiars[i],3,78,59);
		}
		if(GetCommonData("PlayerType")==3){
		ObjEffect_SetVertexXY(familiars[i],0,-6.5,-6.5); ObjEffect_SetVertexUV(familiars[i],0,23,31);
		ObjEffect_SetVertexXY(familiars[i],1,6.5,-6.5); ObjEffect_SetVertexUV(familiars[i],1,46,31);
		ObjEffect_SetVertexXY(familiars[i],2,-6.5,6.5); ObjEffect_SetVertexUV(familiars[i],2,23,54);
		ObjEffect_SetVertexXY(familiars[i],3,6.5,6.5); ObjEffect_SetVertexUV(familiars[i],3,46,54);
		}
		if(GetCommonData("PlayerType")==2){
		ObjEffect_SetVertexXY(familiars[i],0,-10,-10.5); ObjEffect_SetVertexUV(familiars[i],0,1,31);
		ObjEffect_SetVertexXY(familiars[i],1,10,-10.5); ObjEffect_SetVertexUV(familiars[i],1,21,31);
		ObjEffect_SetVertexXY(familiars[i],2,-10,10.5); ObjEffect_SetVertexUV(familiars[i],2,1,52);
		ObjEffect_SetVertexXY(familiars[i],3,10,10.5); ObjEffect_SetVertexUV(familiars[i],3,21,52);
		}
	ObjEffect_SetVertexColor(familiars[i],0,opacity,255,255,255); ObjEffect_SetVertexColor(familiars[i],1,opacity,255,255,255);
	ObjEffect_SetVertexColor(familiars[i],2,opacity,255,255,255); ObjEffect_SetVertexColor(familiars[i],3,opacity,255,255,255);
	i++;
	}
	core=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(core,GetPlayerX,GetPlayerY);
}

//===================================================================================================================
//Mini Elemental Circle & Element Countdown Bar

if(time==0){
let xsize=16;
let ysize=16;
let graphic=0;
	loop(5){
	EFelementcircle=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFelementcircle,386,434);
	ObjEffect_SetScale(EFelementcircle,1,1);
	ObjEffect_SetLayer(EFelementcircle,5); ObjEffect_SetTexture(EFelementcircle,GRelementcycle); ObjEffect_SetRenderState(EFelementcircle,ALPHA);
	ObjEffect_SetPrimitiveType(EFelementcircle,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFelementcircle,4);
	ObjEffect_SetVertexXY(EFelementcircle,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFelementcircle,0,0+graphic,0);
	ObjEffect_SetVertexXY(EFelementcircle,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(EFelementcircle,1,xsize+graphic,0);
	ObjEffect_SetVertexXY(EFelementcircle,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFelementcircle,2,0+graphic,ysize);
	ObjEffect_SetVertexXY(EFelementcircle,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(EFelementcircle,3,xsize+graphic,ysize);
	ObjEffect_SetVertexColor(EFelementcircle,0,255,255,255,255); ObjEffect_SetVertexColor(EFelementcircle,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFelementcircle,2,255,255,255,255); ObjEffect_SetVertexColor(EFelementcircle,3,255,255,255,255);
	elementcircle=elementcircle~[EFelementcircle];
	graphic+=16;
	}
let xsize=48;
let ysize=16;
	EFelementbar2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFelementbar2,318,448);
	ObjEffect_SetScale(EFelementbar2,1,1);
	ObjEffect_SetLayer(EFelementbar2,5); ObjEffect_SetTexture(EFelementbar2,GRelementload); ObjEffect_SetRenderState(EFelementbar2,ALPHA);
	ObjEffect_SetPrimitiveType(EFelementbar2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFelementbar2,4);
	ObjEffect_SetVertexXY(EFelementbar2,0,0,-(ysize/2)); ObjEffect_SetVertexUV(EFelementbar2,0,0,16);
	ObjEffect_SetVertexXY(EFelementbar2,1,xsize,-(ysize/2)); ObjEffect_SetVertexUV(EFelementbar2,1,xsize,16);
	ObjEffect_SetVertexXY(EFelementbar2,2,0,ysize/2); ObjEffect_SetVertexUV(EFelementbar2,2,0,ysize+16);
	ObjEffect_SetVertexXY(EFelementbar2,3,xsize,ysize/2); ObjEffect_SetVertexUV(EFelementbar2,3,xsize,ysize+16);
	ObjEffect_SetVertexColor(EFelementbar2,0,255,255,255,255); ObjEffect_SetVertexColor(EFelementbar2,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFelementbar2,2,255,255,255,255); ObjEffect_SetVertexColor(EFelementbar2,3,255,255,255,255);

	EFelementbar1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFelementbar1,340,448);
	ObjEffect_SetScale(EFelementbar1,1,1);
	ObjEffect_SetLayer(EFelementbar1,5); ObjEffect_SetTexture(EFelementbar1,GRelementload); ObjEffect_SetRenderState(EFelementbar1,ALPHA);
	ObjEffect_SetPrimitiveType(EFelementbar1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFelementbar1,4);
	ObjEffect_SetVertexXY(EFelementbar1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFelementbar1,0,0,0);
	ObjEffect_SetVertexXY(EFelementbar1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(EFelementbar1,1,xsize,0);
	ObjEffect_SetVertexXY(EFelementbar1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFelementbar1,2,0,ysize);
	ObjEffect_SetVertexXY(EFelementbar1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(EFelementbar1,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFelementbar1,0,255,255,255,255); ObjEffect_SetVertexColor(EFelementbar1,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFelementbar1,2,255,255,255,255); ObjEffect_SetVertexColor(EFelementbar1,3,255,255,255,255);
}

let i=0;
let graphic=0;
while(i<length(elementcircle)){
	Obj_SetPosition(elementcircle[i],386+20*cos((i*72)-18-elementspin),434+20*sin((i*72)-18-elementspin));

let graphic=(i*16);
	if(Obj_GetY(elementcircle[i])>=420){
	ObjEffect_SetVertexColor(elementcircle[i],0,elementsfade,130,130,130); ObjEffect_SetVertexColor(elementcircle[i],1,elementsfade,130,130,130);
	ObjEffect_SetVertexColor(elementcircle[i],2,elementsfade,130,130,130); ObjEffect_SetVertexColor(elementcircle[i],3,elementsfade,130,130,130);
	ObjEffect_SetVertexXY(elementcircle[i],0,-(16/2),-(16/2)); ObjEffect_SetVertexXY(elementcircle[i],1,16/2,-(16/2));
	ObjEffect_SetVertexXY(elementcircle[i],2,-(16/2),16/2); ObjEffect_SetVertexXY(elementcircle[i],3,16/2,16/2);
	ObjEffect_SetVertexUV(elementcircle[i],0,0+graphic,0); ObjEffect_SetVertexUV(elementcircle[i],1,16+graphic,0);
	ObjEffect_SetVertexUV(elementcircle[i],2,0+graphic,16); ObjEffect_SetVertexUV(elementcircle[i],3,16+graphic,16);
	}

let graphic=(i*32);
	if(Obj_GetY(elementcircle[i])<420){
	ObjEffect_SetVertexColor(elementcircle[i],0,elementsfade,255,255,255); ObjEffect_SetVertexColor(elementcircle[i],1,elementsfade,255,255,255);
	ObjEffect_SetVertexColor(elementcircle[i],2,elementsfade,255,255,255); ObjEffect_SetVertexColor(elementcircle[i],3,elementsfade,255,255,255);	
	ObjEffect_SetVertexXY(elementcircle[i],0,-(32/2),-(32/2)); ObjEffect_SetVertexXY(elementcircle[i],1,32/2,-(32/2));
	ObjEffect_SetVertexXY(elementcircle[i],2,-(32/2),32/2); ObjEffect_SetVertexXY(elementcircle[i],3,32/2,32/2);
	ObjEffect_SetVertexUV(elementcircle[i],0,0+graphic,16); ObjEffect_SetVertexUV(elementcircle[i],1,32+graphic,16);
	ObjEffect_SetVertexUV(elementcircle[i],2,0+graphic,48); ObjEffect_SetVertexUV(elementcircle[i],3,32+graphic,48);
	}

i++;
}

	ObjEffect_SetScale(EFelementbar2,elementbarsize,1);
	ObjEffect_SetVertexColor(EFelementbar1,0,elementsfade,255,255,255); ObjEffect_SetVertexColor(EFelementbar1,1,elementsfade,255,255,255);
	ObjEffect_SetVertexColor(EFelementbar1,2,elementsfade,255,255,255); ObjEffect_SetVertexColor(EFelementbar1,3,elementsfade,255,255,255);
	ObjEffect_SetVertexColor(EFelementbar2,0,elementsfade,255,255,255); ObjEffect_SetVertexColor(EFelementbar2,1,elementsfade,255,255,255);
	ObjEffect_SetVertexColor(EFelementbar2,2,elementsfade,255,255,255); ObjEffect_SetVertexColor(EFelementbar2,3,elementsfade,255,255,255);

if((GetPlayerX>290 && GetPlayerY>380) || OnBomb==true){ if(elementsfade>100){ elementsfade-=155/20; } }
else{ if(elementsfade<255){ elementsfade+=155/20; } }


//===================================================================================================================
//Basic Shot

if(GetKeyState(VK_SHOT)==KEY_HOLD && OnBomb==false && allowattack==1 && time%4==0){
	CreatePlayerShot01(GetPlayerX-10,GetPlayerY-20,12,270,7,1,GetCommonData("PlayerType"));
	CreatePlayerShot01(GetPlayerX+10,GetPlayerY-20,12,270,7,1,GetCommonData("PlayerType"));
PlaySE(SEshot1);
}

//===================================================================================================================


// Type 1 - Fire

if(GetCommonData("PlayerType")==1){
	if(GetCommonData("Power")>=30){ Obj_SetPosition(familiars[0],Obj_GetX(core)+24*cos(time*2),Obj_GetY(core)+15*sin(time*2)); }
	if(GetCommonData("Power")<30){ Obj_SetPosition(familiars[0],-100,-100); }
	if(GetCommonData("Power")>=60){ Obj_SetPosition(familiars[1],Obj_GetX(core)+24*cos(72+time*2),Obj_GetY(core)+15*sin(72+time*2)); }
	if(GetCommonData("Power")<60){ Obj_SetPosition(familiars[1],-100,-100); }
	if(GetCommonData("Power")>=90){ Obj_SetPosition(familiars[2],Obj_GetX(core)+24*cos(144+time*2),Obj_GetY(core)+15*sin(144+time*2)); }
	if(GetCommonData("Power")<90){ Obj_SetPosition(familiars[2],-100,-100); }
	if(GetCommonData("Power")>=120){ Obj_SetPosition(familiars[3],Obj_GetX(core)+24*cos(216+time*2),Obj_GetY(core)+15*sin(216+time*2)); }
	if(GetCommonData("Power")<120){ Obj_SetPosition(familiars[3],-100,-100); }
	if(GetCommonData("Power")>=150){ Obj_SetPosition(familiars[4],Obj_GetX(core)+24*cos(288+time*2),Obj_GetY(core)+15*sin(288+time*2)); }
	if(GetCommonData("Power")<150){ Obj_SetPosition(familiars[4],-100,-100); }

	angle1a=atan2(GetPlayerY-Obj_GetY(core),GetPlayerX-Obj_GetX(core));

let i=0;
	loop(nroffamiliars){
	ObjEffect_SetVertexUV(familiars[i],0,0+ani,0);
	ObjEffect_SetVertexUV(familiars[i],1,30+ani,0);
	ObjEffect_SetVertexUV(familiars[i],2,0+ani,29);
	ObjEffect_SetVertexUV(familiars[i],3,30+ani,29);
	angle1b=atan2(GetPlayerY-Obj_GetY(familiars[i])+100,GetPlayerX-Obj_GetX(familiars[i]));
	angle1a=90;

	if(GetKeyState(VK_SLOWMOVE)==KEY_FREE && GetKeyState(VK_SHOT)==KEY_HOLD && OnBomb==false && allowattack==1){
		if(GetCommonData("Power")>=30 && GetCommonData("Power")<60 && i<1){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1b+rand(-1,1),0.33,1,11); }
		if(GetCommonData("Power")>=60 && GetCommonData("Power")<90 && i<2){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1b+rand(-1,1),0.33,1,11); }
		if(GetCommonData("Power")>=90 && GetCommonData("Power")<120 && i<3){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1b+rand(-1,1),0.38,1,11); }
		if(GetCommonData("Power")>=120 && GetCommonData("Power")<150 && i<4){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1b+rand(-1,1),0.35,1,11); }
		if(GetCommonData("Power")>=150){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1b+rand(-1,1),0.6,1,11); }
	}
	if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD && GetKeyState(VK_SHOT)==KEY_HOLD && OnBomb==false && allowattack==1){
		if(GetCommonData("Power")>=30 && GetCommonData("Power")<60 && i<1){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1a+rand(-1,1),0.3,1,11); }
		if(GetCommonData("Power")>=60 && GetCommonData("Power")<90 && i<2){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1a+rand(-1,1),0.35,1,11); }
		if(GetCommonData("Power")>=90 && GetCommonData("Power")<120 && i<3){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1a+rand(-1,1),0.35,1,11); }
		if(GetCommonData("Power")>=120 && GetCommonData("Power")<150 && i<4){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1a+rand(-1,1),0.3,1,11); }
		if(GetCommonData("Power")>=150){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),10,180+angle1a+rand(-1,1),0.27,1,11); }
	}
	i++;
	}

if(GetKeyState(VK_SLOWMOVE)==KEY_FREE){ 
	if(coremovecounter==0){
		coremovetime=2;
		coreangle=(((GetPlayerX-Obj_GetX(core))^2+(GetPlayerY-50-Obj_GetY(core))^2)^0.5)/coremovetime*(3.14159/2);
		Obj_SetAngle(core,atan2(GetPlayerY-50-Obj_GetY(core),GetPlayerX-Obj_GetX(core)));
	}
	if(coremovecounter<coremovetime){
		coreaccel+=180/coremovetime;
		Obj_SetSpeed(core,coreangle*sin(coreaccel)/15);
		coremovecounter++;
		if(coremovecounter==coremovetime){ coremovecounter=0; coreaccel=0; }
		coreaccel=0;
	}
}

if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){ Obj_SetSpeed(core,0); }

if(time%7==0){ ani+=30; if(ani>90){ ani=0; } }
}

//===================================================================================================================

// Type 5 - Water
if(GetCommonData("PlayerType")==5){
	if(GetCommonData("Power")>=25){ Obj_SetPosition(familiars[0],GetPlayerX-28+4*cos(time*3),GetPlayerY-14+4*sin(time*3)); }
	if(GetCommonData("Power")<25){ Obj_SetPosition(familiars[0],-100,-100); }
	if(GetCommonData("Power")>=75){ Obj_SetPosition(familiars[1],GetPlayerX-22+3*cos(time*3),GetPlayerY-30+3*sin(time*3)); }
	if(GetCommonData("Power")<75){ Obj_SetPosition(familiars[1],-100,-100); }
	if(GetCommonData("Power")>=125){ Obj_SetPosition(familiars[2],GetPlayerX-8+2*cos(time*3),GetPlayerY-40+2*sin(time*3)); }
	if(GetCommonData("Power")<125){ Obj_SetPosition(familiars[2],-100,-100); }
	if(GetCommonData("Power")>=125){ Obj_SetPosition(familiars[3],GetPlayerX+8-2*cos(-time*3),GetPlayerY-40-2*sin(-time*3)); }
	if(GetCommonData("Power")<125){ Obj_SetPosition(familiars[3],-100,-100); }
	if(GetCommonData("Power")>=75){ Obj_SetPosition(familiars[4],GetPlayerX+22-3*cos(-time*3),GetPlayerY-30-3*sin(-time*3)); }
	if(GetCommonData("Power")<75){ Obj_SetPosition(familiars[4],-100,-100); }
	if(GetCommonData("Power")>=25){ Obj_SetPosition(familiars[5],GetPlayerX+28-4*cos(-time*3),GetPlayerY-14-4*sin(-time*3)); }
	if(GetCommonData("Power")<25){ Obj_SetPosition(familiars[5],-100,-100); }

let i=0;
if(GetKeyState(VK_SLOWMOVE)==KEY_FREE){ angle2a=-25; angle2b=0; }
if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){ angle2a=2; }
if(GetKeyState(VK_LEFT)==KEY_HOLD){ if(angle2b<20){ angle2b+=1; } }
if(GetKeyState(VK_RIGHT)==KEY_HOLD){ if(angle2b>-20){ angle2b-=1; } }

	loop(nroffamiliars){
		if(GetKeyState(VK_SLOWMOVE)==KEY_FREE && GetKeyState(VK_SHOT)==KEY_HOLD && OnBomb==false && allowattack==1){
if(GetCommonData("Power")>=25 && GetCommonData("Power")<50){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+rand(-3,3),0.7,1,12); }
if(GetCommonData("Power")>=50 && GetCommonData("Power")<75){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+rand(-3,3),0.85,1,12); }
if(GetCommonData("Power")>=75 && GetCommonData("Power")<100){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+rand(-3,3),0.75,1,12); }
if(GetCommonData("Power")>=100 && GetCommonData("Power")<125){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+rand(-3,3),0.9,1,12); }
if(GetCommonData("Power")>=125 && GetCommonData("Power")<150){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+rand(-3,3),0.8,1,12); }
if(GetCommonData("Power")>=150){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+rand(-3,3),0.8,1,12); }
		angle2a+=10;
		}
		if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD && GetKeyState(VK_SHOT)==KEY_HOLD && OnBomb==false && allowattack==1){
if(GetCommonData("Power")>=25 && GetCommonData("Power")<50){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+angle2b+rand(-3,3),0.23,1,12); }
if(GetCommonData("Power")>=50 && GetCommonData("Power")<75){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+angle2b+rand(-3,3),0.28,1,12); }
if(GetCommonData("Power")>=75 && GetCommonData("Power")<100){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+angle2b+rand(-3,3),0.23,1,12); }
if(GetCommonData("Power")>=100 && GetCommonData("Power")<125){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+angle2b+rand(-3,3),0.28,1,12); }
if(GetCommonData("Power")>=125 && GetCommonData("Power")<150){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+angle2b+rand(-3,3),0.25,1,12); }
if(GetCommonData("Power")>=150){ CreatePlayerShot01(Obj_GetX(familiars[i]),Obj_GetY(familiars[i]),rand(10,15),270+angle2a+angle2b+rand(-3,3),0.32,1,12); }
		angle2a-=1;
		}
	i++;
	}
}

//===================================================================================================================

// Type 4 - Earth
if(GetCommonData("PlayerType")==4){
	if(GetCommonData("Power")>=70){ Obj_SetPosition(familiars[0],GetPlayerX-30*cos(angle3b),GetPlayerY+8-30*sin(angle3b)); }
	if(GetCommonData("Power")<70){ Obj_SetPosition(familiars[0],-100,-100); }
	if(GetCommonData("Power")>=70){ Obj_SetPosition(familiars[1],GetPlayerX+30*cos(angle3b),GetPlayerY+8+30*sin(angle3b)); }
	if(GetCommonData("Power")<70){ Obj_SetPosition(familiars[1],-100,-100); }

	if(GetKeyState(VK_SLOWMOVE)==KEY_FREE){
		if(GetKeyState(VK_DOWN)==KEY_HOLD){ if(angle3a<50){ angle3a+=4; } }
		if(GetKeyState(VK_UP)==KEY_HOLD){ if(angle3a>-20){ angle3a-=4; } }
		if(GetKeyState(VK_LEFT)==KEY_HOLD){ if(angle3b<35){ angle3b+=3; } }
		if(GetKeyState(VK_RIGHT)==KEY_HOLD){ if(angle3b>-35){ angle3b-=3; } }
	}
	if(time%2==0){
	let a=0;
		if(GetKeyState(VK_SHOT)==KEY_HOLD && OnBomb==false && allowattack==1){
			loop(2){
				if(GetCommonData("Power")>=70 && GetCommonData("Power")<110 && time%3==0){ 
				CreatePlayerShot01(Obj_GetX(familiars[0]),Obj_GetY(familiars[0]),rand(5,6),270-20+angle3a+30*sin(angle3b)-a+rand(-2,2),1.7,1,13);
				CreatePlayerShot01(Obj_GetX(familiars[1]),Obj_GetY(familiars[1]),rand(5,6),270+20-angle3a+30*sin(angle3b)+a+rand(-2,2),1.7,1,13);
				}
			a+=15;
			}
			loop(3){
				if(GetCommonData("Power")>=110 && GetCommonData("Power")<150 && time%3==0){ 
				CreatePlayerShot01(Obj_GetX(familiars[0]),Obj_GetY(familiars[0]),rand(6,7),270+25+angle3a+30*sin(angle3b)-a+rand(-2,2),3,1,13);
				CreatePlayerShot01(Obj_GetX(familiars[1]),Obj_GetY(familiars[1]),rand(6,7),270-25-angle3a+30*sin(angle3b)+a+rand(-2,2),3,1,13);
				}
			a+=15;
			}
			loop(4){
				if(GetCommonData("Power")>=150 && time%2==0){ 
				CreatePlayerShot01(Obj_GetX(familiars[0]),Obj_GetY(familiars[0]),rand(7,8),270+60+angle3a+30*sin(angle3b)-a+rand(-2,2),1.7,1,13);
				CreatePlayerShot01(Obj_GetX(familiars[1]),Obj_GetY(familiars[1]),rand(7,8),270-60-angle3a+30*sin(angle3b)+a+rand(-2,2),1.7,1,13);
				}
			a+=15;
			}
		}
	}
}

//===================================================================================================================

// Type 3 - Wood
if(GetCommonData("PlayerType")==3){
	if(GetCommonData("Power")>=150){ Obj_SetPosition(familiars[0],GetPlayerX-24,GetPlayerY+8); }
	if(GetCommonData("Power")<150){ Obj_SetPosition(familiars[0],-100,-100); }
	if(GetCommonData("Power")>=150){ Obj_SetPosition(familiars[1],GetPlayerX+24,GetPlayerY+8); }
	if(GetCommonData("Power")<150){ Obj_SetPosition(familiars[1],-100,-100); }
	if(GetCommonData("Power")>=45){ Obj_SetPosition(familiars[2],GetPlayerX-10,GetPlayerY-40); }
	if(GetCommonData("Power")<45){ Obj_SetPosition(familiars[2],-100,-100); }
	if(GetCommonData("Power")>=45){ Obj_SetPosition(familiars[3],GetPlayerX+10,GetPlayerY-40); }
	if(GetCommonData("Power")<45){ Obj_SetPosition(familiars[3],-100,-100); }
let i=0;
	loop(nroffamiliars){
	ObjEffect_SetAngle(familiars[i],0,0,time*6);
	ObjEffect_SetScale(familiars[i],1.5,1.5);
	i++;
	}

let shootspeed=16;
if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD && GetKeyState(VK_SHOT)==KEY_HOLD){ shootspeed=8; }
if(time%shootspeed==0 && GetKeyState(VK_SHOT)==KEY_HOLD && OnBomb==false && allowattack==1){
let i=0;
let shotdamage=0;
if(GetCommonData("Power")>=45 && GetCommonData("Power")<80){ shotdamage=0.6; }
if(GetCommonData("Power")>=80 && GetCommonData("Power")<115){ shotdamage=0.8; }
if(GetCommonData("Power")>=115 && GetCommonData("Power")<150){ shotdamage=0.8; }
if(GetCommonData("Power")>=150){ shotdamage=1.2; }
	shot4a=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot4a,Obj_GetX(familiars[i]),Obj_GetY(familiars[i]));
	Obj_SetAngle(shot4a,270); Obj_SetSpeed(shot4a,8);
	Obj_SetAutoDelete(shot4a,true);
	ObjShot_SetDamage(shot4a,shotdamage);
	ObjShot_SetPenetration(shot4a,5);
	ObjShot_SetGraphic(shot4a,14);
	bullet4a=bullet4a~[shot4a];
	timer4a=timer4a~[shot4a];
	timer4a[length(bullet4a)-1]=rand(-2,2);
	i++;

	shot4b=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot4b,Obj_GetX(familiars[i]),Obj_GetY(familiars[i]));
	Obj_SetAngle(shot4b,270); Obj_SetSpeed(shot4b,8);
	Obj_SetAutoDelete(shot4b,true);
	ObjShot_SetDamage(shot4b,shotdamage);
	ObjShot_SetDamage(shot4a,shotdamage);
	ObjShot_SetPenetration(shot4a,5);
	ObjShot_SetGraphic(shot4b,14);
	bullet4b=bullet4b~[shot4b];
	timer4b=timer4b~[shot4b];
	timer4b[length(bullet4b)-1]=rand(-2,2);
	i++;

	shot4c=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot4c,Obj_GetX(familiars[i]),Obj_GetY(familiars[i]));
	Obj_SetAngle(shot4c,270); Obj_SetSpeed(shot4c,6);
	Obj_SetAutoDelete(shot4c,true);
	ObjShot_SetDamage(shot4c,shotdamage);
	ObjShot_SetPenetration(shot4a,5);
	ObjShot_SetGraphic(shot4c,14);
	bullet4c=bullet4c~[shot4c];
	timer4c=timer4c~[shot4c];
	timer4c[length(bullet4c)-1]=rand(-2,2);
	i++;

	shot4d=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot4d,Obj_GetX(familiars[i]),Obj_GetY(familiars[i]));
	Obj_SetAngle(shot4d,270); Obj_SetSpeed(shot4d,6);
	Obj_SetAutoDelete(shot4d,true);
	ObjShot_SetDamage(shot4d,shotdamage);
	ObjShot_SetPenetration(shot4a,5);
	ObjShot_SetGraphic(shot4d,14);
	bullet4d=bullet4d~[shot4d];
	timer4d=timer4d~[shot4d];
	timer4d[length(bullet4d)-1]=rand(-2,2);
	i++;
}
let i=0;
	while(i<length(bullet4a)){
		if(Obj_BeDeleted(bullet4a[i])){
		bullet4a=erase(bullet4a,i); timer4a=erase(timer4a,i); i--;
		}
		else{
			if(GetKeyState(VK_SLOWMOVE)==KEY_FREE){
				if(timer4a[i]<90){ timer4a[i]=timer4a[i]+rand(1,1.5); }
				Obj_SetSpeed(bullet4a[i],6);
			}
			if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
				if(timer4a[i]<90){ timer4a[i]=timer4a[i]+rand(2.5,3); }
				Obj_SetSpeed(bullet4a[i],8);
			}
		Obj_SetAngle(bullet4a[i],225+timer4a[i]);
		}
		i++;
	}
let i=0;
	while(i<length(bullet4b)){
		if(Obj_BeDeleted(bullet4b[i])){
		bullet4b=erase(bullet4b,i); timer4b=erase(timer4b,i); i--;
		}
		else{
			if(GetKeyState(VK_SLOWMOVE)==KEY_FREE){
				if(timer4b[i]<90){ timer4b[i]=timer4b[i]+rand(1,1.5); }
				Obj_SetSpeed(bullet4b[i],6);
			}
			if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
				if(timer4b[i]<90){ timer4b[i]=timer4b[i]+rand(2.5,3); }
				Obj_SetSpeed(bullet4b[i],8);
			}
		Obj_SetAngle(bullet4b[i],315-timer4b[i]);
		}
		i++;
	}
let i=0;
	while(i<length(bullet4c)){
		if(Obj_BeDeleted(bullet4c[i])){
		bullet4c=erase(bullet4c,i); timer4c=erase(timer4c,i); i--;
		}
		else{
			if(GetKeyState(VK_SLOWMOVE)==KEY_FREE){
				if(timer4c[i]<30){ timer4c[i]=timer4c[i]+rand(0.5,1); }
				Obj_SetSpeed(bullet4c[i],6);
			}
			if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
				if(timer4c[i]<30){ timer4c[i]=timer4c[i]+rand(1.2,1.7); }
				Obj_SetSpeed(bullet4c[i],8);
			}
		Obj_SetAngle(bullet4c[i],260+(timer4c[i]/2));
		}
		i++;
	}
let i=0;
	while(i<length(bullet4d)){
		if(Obj_BeDeleted(bullet4d[i])){
		bullet4d=erase(bullet4d,i); timer4d=erase(timer4d,i); i--;
		}
		else{
			if(GetKeyState(VK_SLOWMOVE)==KEY_FREE){
				if(timer4d[i]<30){ timer4d[i]=timer4d[i]+rand(0.5,1); }
				Obj_SetSpeed(bullet4d[i],6);
			}
			if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
				if(timer4d[i]<30){ timer4d[i]=timer4d[i]+rand(1.2,1.7); }
				Obj_SetSpeed(bullet4d[i],8);
			}
		Obj_SetAngle(bullet4d[i],280-(timer4d[i]/2));
		}
		i++;
	}
}

//===================================================================================================================

// Type 2 - Metal
if(GetCommonData("PlayerType")==2){
	if(GetCommonData("Power")>=60){ Obj_SetPosition(familiars[0],GetPlayerX-24+3*cos(time*3),GetPlayerY-10); }
	if(GetCommonData("Power")<60){ Obj_SetPosition(familiars[0],-100,-100); }
	if(GetCommonData("Power")>=60){ Obj_SetPosition(familiars[1],GetPlayerX+24-3*cos(time*3),GetPlayerY-10); }
	if(GetCommonData("Power")<60){ Obj_SetPosition(familiars[1],-100,-100); }
	if(GetCommonData("Power")>=150){ Obj_SetPosition(familiars[2],GetPlayerX,GetPlayerY-44); }
	if(GetCommonData("Power")<150){ Obj_SetPosition(familiars[2],-100,-100); }

	if(GetKeyState(VK_SLOWMOVE)==KEY_FREE && GetKeyState(VK_SHOT)==KEY_HOLD && OnBomb==false && allowattack==1){
	angle5a=3*cos(time*2);
		if(GetCommonData("Power")>=60 && GetCommonData("Power")<105){ 
		CreatePlayerShot01(Obj_GetX(familiars[0])+150*cos(260+angle5a),Obj_GetY(familiars[0])+150*sin(260+angle5a),50,260+angle5a,0.14,100,15);
		CreatePlayerShot01(Obj_GetX(familiars[1])+150*cos(280-angle5a),Obj_GetY(familiars[1])+150*sin(280-angle5a),50,280-angle5a,0.14,100,15);
		}
		if(GetCommonData("Power")>=105 && GetCommonData("Power")<150){ 
		CreatePlayerShot01(Obj_GetX(familiars[0])+150*cos(260+angle5a),Obj_GetY(familiars[0])+150*sin(260+angle5a),50,260+angle5a,0.2,100,15);
		CreatePlayerShot01(Obj_GetX(familiars[1])+150*cos(280-angle5a),Obj_GetY(familiars[1])+150*sin(280-angle5a),50,280-angle5a,0.2,100,15);
		}
		if(GetCommonData("Power")>=150){ 
		CreatePlayerShot01(Obj_GetX(familiars[0])+150*cos(260+angle5a),Obj_GetY(familiars[0])+150*sin(260+angle5a),50,260+angle5a,0.28,100,15);
		CreatePlayerShot01(Obj_GetX(familiars[1])+150*cos(280-angle5a),Obj_GetY(familiars[1])+150*sin(280-angle5a),50,280-angle5a,0.28,100,15);
		CreatePlayerShot01(Obj_GetX(familiars[2]),Obj_GetY(familiars[2])-150,50,270,0.2,100,15);
		}
	}
	if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD && GetKeyState(VK_SHOT)==KEY_HOLD && OnBomb==false && allowattack==1){
	angle5a=0;
		if(GetCommonData("Power")>=60 && GetCommonData("Power")<105){ 
		CreatePlayerShot01(Obj_GetX(familiars[0])+150*cos(274+angle5a),Obj_GetY(familiars[0])+150*sin(272+angle5a),50,274+angle5a,0.06,100,15);
		CreatePlayerShot01(Obj_GetX(familiars[1])+150*cos(266-angle5a),Obj_GetY(familiars[1])+150*sin(268-angle5a),50,266-angle5a,0.06,100,15);
		}
		if(GetCommonData("Power")>=105 && GetCommonData("Power")<150){ 
		CreatePlayerShot01(Obj_GetX(familiars[0])+150*cos(274+angle5a),Obj_GetY(familiars[0])+150*sin(272+angle5a),50,274+angle5a,0.1,100,15);
		CreatePlayerShot01(Obj_GetX(familiars[1])+150*cos(266-angle5a),Obj_GetY(familiars[1])+150*sin(268-angle5a),50,266-angle5a,0.1,100,15);
		}
		if(GetCommonData("Power")>=150){ 
		CreatePlayerShot01(Obj_GetX(familiars[0])+150*cos(274+angle5a),Obj_GetY(familiars[0])+150*sin(272+angle5a),50,274+angle5a,0.12,100,15);
		CreatePlayerShot01(Obj_GetX(familiars[1])+150*cos(266-angle5a),Obj_GetY(familiars[1])+150*sin(268-angle5a),50,266-angle5a,0.12,100,15);
		CreatePlayerShot01(Obj_GetX(familiars[2]),Obj_GetY(familiars[2])-150,50,270,0.26,100,15);
		}
	}
let i=0;
	loop(nroffamiliars){
	ObjEffect_SetAngle(familiars[i],0,0,-time*10);
	i++;
	}
}


//===================================================================================================================

//Focus Circle

if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD && focusscale<=0){ 
let xsize=199;
let ysize=199;
	focus=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(focus,GetPlayerX,GetPlayerY);
	ObjEffect_SetScale(focus,focusscale,focusscale);
	ObjEffect_SetLayer(focus,0); ObjEffect_SetTexture(focus,GRfocus); ObjEffect_SetRenderState(focus,ALPHA);
	ObjEffect_SetPrimitiveType(focus,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(focus,4);
	ObjEffect_SetVertexXY(focus,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(focus,0,0,0);
	ObjEffect_SetVertexXY(focus,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(focus,1,xsize,0);
	ObjEffect_SetVertexXY(focus,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(focus,2,0,ysize);
	ObjEffect_SetVertexXY(focus,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(focus,3,xsize,ysize);
	ObjEffect_SetVertexColor(focus,0,255,255,255,255); ObjEffect_SetVertexColor(focus,1,255,255,255,255);
	ObjEffect_SetVertexColor(focus,2,255,255,255,255); ObjEffect_SetVertexColor(focus,3,255,255,255,255);
}

if(GetCommonData("PlayerType")==1){
	ObjEffect_SetVertexColor(focus,0,200,255,80,80); ObjEffect_SetVertexColor(focus,1,200,255,80,80);
	ObjEffect_SetVertexColor(focus,2,200,255,80,80); ObjEffect_SetVertexColor(focus,3,200,255,80,80);
}
if(GetCommonData("PlayerType")==5){
	ObjEffect_SetVertexColor(focus,0,150,50,50,50); ObjEffect_SetVertexColor(focus,1,150,50,50,50);
	ObjEffect_SetVertexColor(focus,2,150,50,50,50); ObjEffect_SetVertexColor(focus,3,150,50,50,50);
}
if(GetCommonData("PlayerType")==4){
	ObjEffect_SetVertexColor(focus,0,190,255,255,100); ObjEffect_SetVertexColor(focus,1,190,255,255,100);
	ObjEffect_SetVertexColor(focus,2,190,255,255,100); ObjEffect_SetVertexColor(focus,3,190,255,255,100);
}
if(GetCommonData("PlayerType")==3){
	ObjEffect_SetVertexColor(focus,0,170,0,255,255); ObjEffect_SetVertexColor(focus,1,170,0,255,255);
	ObjEffect_SetVertexColor(focus,2,170,0,255,255); ObjEffect_SetVertexColor(focus,3,170,0,255,255);
}
if(GetCommonData("PlayerType")==2){
	ObjEffect_SetVertexColor(focus,0,200,255,255,255); ObjEffect_SetVertexColor(focus,1,200,255,255,255);
	ObjEffect_SetVertexColor(focus,2,200,255,255,255); ObjEffect_SetVertexColor(focus,3,200,255,255,255);
}

if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){ if(focusscale<0.7){ focusscale+=0.07; } }
if(GetKeyState(VK_SLOWMOVE)==KEY_FREE){ if(focusscale>0){ focusscale-=0.07; } }
if(focusscale>0.7){ focusscale=0.7; }
if(focusscale<0){ Obj_Delete(focus); focusscale=0; }

ObjEffect_SetScale(focus,focusscale,focusscale);
Obj_SetPosition(focus,GetPlayerX,GetPlayerY);
ObjEffect_SetAngle(focus,0,0,time*6);


if(OnBomb==true){ SetCommonData("BombOn",1); SetCommonData("ItemCollect",1); }
if(OnBomb==false){ SetCommonData("BombOn",0); SetCommonData("ItemCollect",0); }

//===================================================================================================================

//Focus Circle

if(GetTimeOfPlayerInvincibility>0 && invintime==0){ 
let xsize=199;
let ysize=199;
	invin=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(invin,GetPlayerX,GetPlayerY);
	ObjEffect_SetScale(invin,0,0);
	ObjEffect_SetLayer(invin,0); ObjEffect_SetTexture(invin,GRinvin); ObjEffect_SetRenderState(invin,ADD);
	ObjEffect_SetPrimitiveType(invin,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(invin,4);
	ObjEffect_SetVertexXY(invin,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(invin,0,0,0);
	ObjEffect_SetVertexXY(invin,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(invin,1,xsize,0);
	ObjEffect_SetVertexXY(invin,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(invin,2,0,ysize);
	ObjEffect_SetVertexXY(invin,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(invin,3,xsize,ysize);
	ObjEffect_SetVertexColor(invin,0,120,255,255,255); ObjEffect_SetVertexColor(invin,1,120,255,255,255);
	ObjEffect_SetVertexColor(invin,2,120,255,255,255); ObjEffect_SetVertexColor(invin,3,120,255,255,255);
}

if(GetTimeOfPlayerInvincibility>0){ invintime++; }
ObjEffect_SetScale(invin,GetTimeOfPlayerInvincibility/120,GetTimeOfPlayerInvincibility/120);
if(GetTimeOfPlayerInvincibility<=0){ Obj_Delete(invin); invintime=0; }

Obj_SetPosition(invin,GetPlayerX,GetPlayerY);
ObjEffect_SetAngle(invin,0,0,-time*5);

//===================================================================================================================

if(OnMissed==false && GetKeyState(VK_SLOWMOVE)==KEY_HOLD && hitboxfade<1){ hitboxfade+=1/10; }
if(OnMissed==true || GetKeyState(VK_SLOWMOVE)==KEY_FREE && hitboxfade>0){ hitboxfade-=1/10; }
if(hitboxfade<0){ hitboxfade=0; }
if(hitboxfade>1){ hitboxfade=1; }


time++;

if(GetCommonDataDefault("SpellcardPractise",0)==1){
	SetRibirthFrame(0); 
	ForbidBomb(true);
}
if(GetCommonDataDefault("SpellcardPractise",0)==0){
	if(GetCommonData("PlayerType")!=1){ SetRibirthFrame(20); }
	if(GetCommonData("PlayerType")==1){ SetRibirthFrame(26); }
}

}

@Missed{
	SetCommonData("ResetPlayer",1);
	if(focusscale>0){ focusscale-=0.07; }
	if(focusscale<=0){ Obj_Delete(focus); focusscale=0; }
	ObjEffect_SetScale(focus,focusscale,focusscale);
	
	dead=1;
}

@SpellCard{
	if(GetCommonData("PlayerType")==1 && IsLastSpell==false){ UseSpellCard("BombFire",0); }
	if(GetCommonData("PlayerType")==1 && IsLastSpell==true){ UseSpellCard("BombFire",0.1); }
	if(GetCommonData("PlayerType")==5 && IsLastSpell==false){ UseSpellCard("BombWater",0); }
	if(GetCommonData("PlayerType")==5 && IsLastSpell==true){ UseSpellCard("BombWater",1); }
	if(GetCommonData("PlayerType")==4 && IsLastSpell==false){ UseSpellCard("BombEarth",0); }
	if(GetCommonData("PlayerType")==4 && IsLastSpell==true){ UseSpellCard("BombEarth",2); }
	if(GetCommonData("PlayerType")==3 && IsLastSpell==false){ UseSpellCard("BombWood",0); }
	if(GetCommonData("PlayerType")==3 && IsLastSpell==true){ UseSpellCard("BombWood",2); }
	if(GetCommonData("PlayerType")==2 && IsLastSpell==false){ UseSpellCard("BombMetal",0); }
	if(GetCommonData("PlayerType")==2 && IsLastSpell==true){ UseSpellCard("BombMetal",1); }
	if(IsLastSpell==true){ PlaySE(SEdeathbomb); }
	UseSpellCard("Spellcircle",0);
	SetCommonData("ResetPlayer",1);
	cancelswitch=true;
}

@DrawLoop{
	SetTexture(GRmasahiro);
		if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD){ SetGraphicRect(100,0,150,80); }
		else if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD){ SetGraphicRect(50,0,100,80); }
		else{ SetGraphicRect(0,0,50,80); }
	SetAlpha(255);
	DrawGraphic(GetPlayerX,GetPlayerY);

	SetTexture(GRhitbox);
	SetGraphicRect(0,0,10,10);
	SetAlpha(hitboxfade*255);
	DrawGraphic(GetPlayerX,GetPlayerY);
}

@Finalize{
}

}

//====================================================================================================

// BOMB FIRE

script_spell BombFire{

let time=0;
let bombtime=0;

let effect1=0;
let fade1=0;
let scale1=0;

let shot2=0;
let bullet2=[];
let timer2=[];
let angle2=[];
let xpos2=[];
let ypos2=[];
let ani2=[];

let explosion=0;
let object3=[];
let timer3=[];
let xpos3=[];

let GRheatwave=GetCurrentScriptDirectory~"Images\BombFire1.png";
let GRfire=GetCurrentScriptDirectory~"Images\BombFire2.png";
let GRexplosion=GetCurrentScriptDirectory~"Images\ExplosionAdd.png";
let BGfire=GetCurrentScriptDirectory~"Images\BackgroundFire.png";

let SEfire1=GetCurrentScriptDirectory~"Sounds\BombFire1.wav";
let SEfire2=GetCurrentScriptDirectory~"Sounds\BombFire2.wav";
let SEfire3=GetCurrentScriptDirectory~"Sounds\BombFire3.wav";

@Initialize{
}

@MainLoop{

if(time<300){ SetSpeed(1,1); }
if(time==0){ SetPlayerInvincibility(360); }

//Heatwave

if(time==0){
let xsize=199;
let ysize=199;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetPlayerX,GetPlayerY);
	ObjEffect_SetAngle(effect1,0,0,0); ObjEffect_SetScale(effect1,1,1);
	ObjEffect_SetLayer(effect1,5); ObjEffect_SetTexture(effect1,GRheatwave); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect1,0,fade1,255,255,255); ObjEffect_SetVertexColor(effect1,1,fade1,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,fade1,255,255,255); ObjEffect_SetVertexColor(effect1,3,fade1,255,255,255);
PlaySE(SEfire1);
}

Obj_SetPosition(effect1,GetPlayerX,GetPlayerY);
ObjEffect_SetVertexColor(effect1,0,fade1,255,255,255); ObjEffect_SetVertexColor(effect1,1,fade1,255,255,255);
ObjEffect_SetVertexColor(effect1,2,fade1,255,255,255); ObjEffect_SetVertexColor(effect1,3,fade1,255,255,255);
ObjEffect_SetAngle(effect1,0,0,-time*4);
if(fade1<170 && time<250){ fade1+=5; }
if(fade1>0){ fade1-=170/50; }
if(scale1<5){ scale1+=0.02; }
ObjEffect_SetScale(effect1,scale1,scale1);
SetIntersectionCircle(GetPlayerX,GetPlayerY,scale1*80,8,true);

//==================================================

//Shots

if(time>=0 && time<150 && time%2==0){
let xsize=79;
let ysize=119;
	shot2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(shot2,GetPlayerX,GetPlayerY); Obj_SetAngle(shot2,270+rand(-120,120));
	Obj_SetSpeed(shot2,3); ObjShot_SetGraphic(shot2,11);
	let size=rand(0.25,0.4);
	ObjEffect_SetScale(shot2,size,size);
	ObjEffect_SetLayer(shot2,3); ObjEffect_SetTexture(shot2,GRfire); ObjEffect_SetRenderState(shot2,ADD);
	ObjEffect_SetPrimitiveType(shot2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(shot2,4);
	ObjEffect_SetVertexXY(shot2,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(shot2,0,0,0);
	ObjEffect_SetVertexXY(shot2,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(shot2,1,xsize,0);
	ObjEffect_SetVertexXY(shot2,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(shot2,2,0,ysize);
	ObjEffect_SetVertexXY(shot2,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(shot2,3,xsize,ysize);
	ObjEffect_SetVertexColor(shot2,0,200,255,255,255); ObjEffect_SetVertexColor(shot2,1,200,255,255,255);
	ObjEffect_SetVertexColor(shot2,2,200,255,255,255); ObjEffect_SetVertexColor(shot2,3,200,255,255,255);
	bullet2=bullet2~[shot2];
	timer2=timer2~[shot2];
	timer2[length(bullet2)-1]=0;
	angle2=angle2~[shot2];
	angle2[length(bullet2)-1]=Obj_GetAngle(shot2);
	xpos2=xpos2~[shot2];
	xpos2[length(bullet2)-1]=0;
	ypos2=ypos2~[shot2];
	ypos2[length(bullet2)-1]=0;
	ani2=ani2~[shot2];
	ani2[length(bullet2)-1]=0;
}

if(time>=30 && time<280 && time%12==0){ PlaySE(SEfire2); }
if(time>=90 && time<300 && (time+6)%12==0){ PlaySE(SEfire3); }


let i=0;
while(i<length(bullet2)){
	if(Obj_BeDeleted(bullet2[i])){
	bullet2=erase(bullet2,i); timer2=erase(timer2,i); angle2=erase(angle2,i); xpos2=erase(xpos2,i); ypos2=erase(ypos2,i);
	i--;
	}
	else{
	if(angle2[i]<270){ Obj_SetAngle(bullet2[i],Obj_GetAngle(bullet2[i])+0.5*sin(timer2[i])); }
	if(angle2[i]>=270){ Obj_SetAngle(bullet2[i],Obj_GetAngle(bullet2[i])-0.5*sin(timer2[i])); }
	if(timer2[i]<60 && Obj_GetSpeed(bullet2[i])>0){ Obj_SetSpeed(bullet2[i],Obj_GetSpeed(bullet2[i])-0.03); }
	if(timer2[i]>=60){
		Obj_SetSpeed(bullet2[i],Obj_GetSpeed(bullet2[i])+0.1);
		SetIntersectionCircle(Obj_GetX(bullet2[i]),Obj_GetY(bullet2[i]),40,1.75,true);
	}
	ObjEffect_SetAngle(bullet2[i],0,0,Obj_GetAngle(bullet2[i])+90);

	let xsize=79;
	let ysize=119;
	if(timer2[i]%7==0){ ani2[i]=ani2[i]+80; }
	ObjEffect_SetVertexUV(bullet2[i],0,ani2[i],0); ObjEffect_SetVertexUV(bullet2[i],1,ani2[i]+xsize,0);
	ObjEffect_SetVertexUV(bullet2[i],2,ani2[i],ysize); ObjEffect_SetVertexUV(bullet2[i],3,ani2[i]+xsize,ysize);

if(timer2[i]>=70 && timer2[i]%10==0){
let xsize=69;
let ysize=69;
let angle=rand(0,360);
let radius=rand(10,40);
	explosion=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(explosion,Obj_GetX(bullet2[i])+radius*cos(angle),Obj_GetY(bullet2[i])+radius*sin(angle));
	ObjEffect_SetAngle(explosion,0,0,rand(0,360)); ObjEffect_SetScale(explosion,1,1);
	ObjEffect_SetLayer(explosion,5); ObjEffect_SetTexture(explosion,GRexplosion); ObjEffect_SetRenderState(explosion,ADD);
	ObjEffect_SetPrimitiveType(explosion,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(explosion,4);
	ObjEffect_SetVertexXY(explosion,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(explosion,0,0,0);
	ObjEffect_SetVertexXY(explosion,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(explosion,1,xsize,0);
	ObjEffect_SetVertexXY(explosion,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(explosion,2,0,ysize);
	ObjEffect_SetVertexXY(explosion,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(explosion,3,xsize,ysize);
	ObjEffect_SetVertexColor(explosion,0,200,255,255,255); ObjEffect_SetVertexColor(explosion,1,200,255,255,255);
	ObjEffect_SetVertexColor(explosion,2,200,255,255,255); ObjEffect_SetVertexColor(explosion,3,200,255,255,255);
	object3=object3~[explosion];
	timer3=timer3~[explosion];
	timer3[length(object3)-1]=0;
	xpos3=xpos3~[explosion];
	xpos3[length(object3)-1]=0;
}

	xpos2[i]=Obj_GetX(bullet2[i]);
	ypos2[i]=Obj_GetY(bullet2[i]);
	timer2[i]=timer2[i]+1;
	}
i++;
}

//==================================================

//Explosions

let i=0;
while(i<length(object3)){
	if(Obj_BeDeleted(object3[i])){
	object3=erase(object3,i); timer3=erase(timer3,i); xpos3=erase(xpos3,i);
	i--;
	}
	else{
	SetIntersectionCircle(Obj_GetX(object3[i]),Obj_GetY(object3[i]),50,0.3+GetArgument,true);
	let xsize=69;
	let ysize=69;
	ObjEffect_SetVertexUV(object3[i],0,xpos3[i],0); ObjEffect_SetVertexUV(object3[i],1,xpos3[i]+xsize,0);
	ObjEffect_SetVertexUV(object3[i],2,xpos3[i],ysize); ObjEffect_SetVertexUV(object3[i],3,xpos3[i]+xsize,ysize);
	if(timer3[i]%4==0 && xpos3[i]<490){ xpos3[i]=xpos3[i]+70; }
	if(xpos3[i]>=490){ Obj_Delete(object3[i]); }
	timer3[i]=timer3[i]+1;
	}
	i++;
}



if(time==300){ SetCommonData("EndOfBomb",1); SetSpeed(4.5,2); End; }

time++;

} //Mainloop
} //Bomb Fire


//==========================================================================================================


//BOMB WATER

script_spell BombWater{

let time=0;
let bombtime=0;
let angle=0;
let fade=0;

let shot1=0;
let shot2=0;
let effect1=0;

let GRrainbow=GetCurrentScriptDirectory~"Images\BombWater.png";

let SEwater1=GetCurrentScriptDirectory~"Sounds\BombWater1.wav";
let SEwater2=GetCurrentScriptDirectory~"Sounds\BombWater2.wav";

@Initialize{
}

@MainLoop{

if(time<300){ SetSpeed(1,1); }
if(time==0){ SetPlayerInvincibility(360); }


if(time>=0 && time<180){
let xpos=rand(-40,-25);
if(GetArgument==1){ xpos=rand(-60,-40); }
	loop(2+GetArgument){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetPlayerX+xpos,GetPlayerY+rand(-5,10));
	Obj_SetAngle(shot1,270+angle);
	Obj_SetSpeed(shot1,rand(10,13));
	Obj_SetAutoDelete(shot1,true);
	ObjShot_SetDamage(shot1,0.7);
	ObjShot_SetPenetration(shot1,99);
	ObjShot_SetGraphic(shot1,22);

	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetPlayerX-xpos,GetPlayerY+rand(-5,10));
	Obj_SetAngle(shot1,270+angle);
	Obj_SetSpeed(shot1,rand(10,13));
	Obj_SetAutoDelete(shot1,true);
	ObjShot_SetDamage(shot1,0.7);
	ObjShot_SetPenetration(shot1,99);
	ObjShot_SetGraphic(shot1,22);
	xpos+=rand(15,30);
	}
if(time%6==0){ PlaySE(SEwater1); }
}

if(GetKeyState(VK_LEFT)==KEY_HOLD){ angle-=0.3; }
if(GetKeyState(VK_RIGHT)==KEY_HOLD){ angle+=0.3; }

if(time>=120 && time<270){
	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,GetCenterX+rand(-180,180),GetClipMinY);
	Obj_SetAngle(shot2,90+rand(-5,5));
	Obj_SetSpeed(shot2,rand(6,7));
	Obj_SetAutoDelete(shot2,true);
	Obj_SetAlpha(shot2,180);
	ObjShot_SetDamage(shot2,5);
	ObjShot_SetPenetration(shot2,1);
	ObjShot_SetGraphic(shot2,12);
}

if(time==120){ PlaySE(SEwater2); }

if(time==90){
let xsize=384;
let ysize=448;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetCenterX,GetCenterY); ObjEffect_SetScale(effect1,1,1);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,GRrainbow); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect1,0,fade,255,255,255); ObjEffect_SetVertexColor(effect1,1,fade,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,fade,255,255,255); ObjEffect_SetVertexColor(effect1,3,fade,255,255,255);
}

if(time>=90 && time<210 && fade<180){ fade+=3; }
if(time>=260 && time<300 && fade>0){ fade-=3; }

ObjEffect_SetVertexColor(effect1,0,fade,255,255,255); ObjEffect_SetVertexColor(effect1,1,fade,255,255,255);
ObjEffect_SetVertexColor(effect1,2,fade,255,255,255); ObjEffect_SetVertexColor(effect1,3,fade,255,255,255);


if(time==300){ Obj_Delete(effect1); SetCommonData("EndOfBomb",1); SetSpeed(4,1.5); End; }

time++;

} //Mainloop
} //Bomb Water


//==========================================================================================================


//BOMB EARTH

script_spell BombEarth{

let time=0;
let bombtime=0;
let fade=0;
let effect1x=0;
let effect1y=0;
let shake=10;

let shot1=0;
let effect1=0;

let effect2=0;
let object2=[];
let scale2=[];
let timer2=[];
let speed2=[];
let fade2=[];

let effect3=0;
let fade3=230;

let GRcracks=GetCurrentScriptDirectory~"Images\BombEarth1.png";
let GRshockwave=GetCurrentScriptDirectory~"Images\BombEarth2.png";
let GRflash=GetCurrentScriptDirectory~"Images\BombEarth3.png";

let SEearth1=GetCurrentScriptDirectory~"Sounds\BombEarth1.wav";
let SEearth2=GetCurrentScriptDirectory~"Sounds\BombEarth2.wav";

@Initialize{
}

@MainLoop{

if(time<200){ SetSpeed(1,1); }
if(time==0){ SetPlayerInvincibility(260); }

if(time==0){
let xsize=255*3;
let ysize=255*3;
effect1x=GetPlayerX;
effect1y=GetPlayerY;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,effect1x,effect1y); ObjEffect_SetScale(effect1,2,2);
	ObjEffect_SetLayer(effect1,0); ObjEffect_SetTexture(effect1,GRcracks); ObjEffect_SetRenderState(effect1,ALPHA);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect1,0,fade,255,255,255); ObjEffect_SetVertexColor(effect1,1,fade,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,fade,255,255,255); ObjEffect_SetVertexColor(effect1,3,fade,255,255,255);

	effect3=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect3,GetCenterX,GetCenterY); ObjEffect_SetScale(effect3,1,1);
	ObjEffect_SetLayer(effect3,7); ObjEffect_SetTexture(effect3,GRflash); ObjEffect_SetRenderState(effect3,ALPHA);
	ObjEffect_SetPrimitiveType(effect3,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect3,4);
	ObjEffect_SetVertexXY(effect3,0,-250,-250); ObjEffect_SetVertexUV(effect3,0,0,0);
	ObjEffect_SetVertexXY(effect3,1,-250,250); ObjEffect_SetVertexUV(effect3,1,500,0);
	ObjEffect_SetVertexXY(effect3,2,250,-250); ObjEffect_SetVertexUV(effect3,2,0,500);
	ObjEffect_SetVertexXY(effect3,3,250,250); ObjEffect_SetVertexUV(effect3,3,500,500);
	ObjEffect_SetVertexColor(effect3,0,fade3,255,255,255); ObjEffect_SetVertexColor(effect3,1,fade3,255,255,255);
	ObjEffect_SetVertexColor(effect3,2,fade3,255,255,255); ObjEffect_SetVertexColor(effect3,3,fade3,255,255,255);
PlaySE(SEearth1);
}

ObjEffect_SetVertexColor(effect1,0,fade,255,255,255); ObjEffect_SetVertexColor(effect1,1,fade,255,255,255);
ObjEffect_SetVertexColor(effect1,2,fade,255,255,255); ObjEffect_SetVertexColor(effect1,3,fade,255,255,255);
Obj_SetPosition(effect1,effect1x+(shake+GetArgument)*cos(time*30),effect1y+((shake+GetArgument)*0.8)*cos(time*26)); 
if(shake>0){ shake-=0.04; }
if(fade<200 && time<170){ fade+=5; }
if(fade>0 && time>=170){ fade-=5; }

ObjEffect_SetVertexColor(effect3,0,fade3,255,255,255); ObjEffect_SetVertexColor(effect3,1,fade3,255,255,255);
ObjEffect_SetVertexColor(effect3,2,fade3,255,255,255); ObjEffect_SetVertexColor(effect3,3,fade3,255,255,255);
if(fade3>0){ fade3-=1+(time/15); }


if(time==0){
let xsize=127;
let ysize=127;
effect1x=GetPlayerX;
effect1y=GetPlayerY;
let speed=0.04;
	loop(4+GetArgument){
	effect2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect2,effect1x,effect1y); ObjEffect_SetScale(effect2,0,0);
	ObjEffect_SetLayer(effect2,1); ObjEffect_SetTexture(effect2,GRshockwave); ObjEffect_SetRenderState(effect2,ADD);
	ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
	ObjEffect_SetVertexXY(effect2,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect2,0,0,0);
	ObjEffect_SetVertexXY(effect2,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect2,1,xsize,0);
	ObjEffect_SetVertexXY(effect2,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect2,2,0,ysize);
	ObjEffect_SetVertexXY(effect2,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect2,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect2,0,180,255,255,255); ObjEffect_SetVertexColor(effect2,1,180,255,255,255);
	ObjEffect_SetVertexColor(effect2,2,180,255,255,255); ObjEffect_SetVertexColor(effect2,3,180,255,255,255);
	object2=object2~[effect2];
	scale2=scale2~[effect2];
	scale2[length(object2)-1]=0;
	timer2=timer2~[effect2];
	timer2[length(object2)-1]=0;
	speed2=speed2~[effect2];
	speed2[length(object2)-1]=speed;
	fade2=fade2~[effect2];
	fade2[length(object2)-1]=255;
	speed+=0.02;
	}
}

let i=0;
while(i<length(object2)){
	if(Obj_BeDeleted(object2[i])){
	object2=erase(object2,i); scale2=erase(scale2,i); timer2=erase(timer2,i); speed2=erase(speed2,i); fade2=erase(fade2,i);
	i--;
	}
	else{
	ObjEffect_SetScale(object2[i],scale2[i],scale2[i]);
	Obj_SetPosition(object2[i],effect1x+(shake+GetArgument)*cos(time*30),effect1y+((shake+GetArgument)*0.8)*cos(time*26)); 
	ObjEffect_SetVertexColor(object2[i],0,fade2[i],255,255,255); ObjEffect_SetVertexColor(object2[i],1,fade2[i],255,255,255);
	ObjEffect_SetVertexColor(object2[i],2,fade2[i],255,255,255); ObjEffect_SetVertexColor(object2[i],3,fade2[i],255,255,255);
	fade2[i]=255-(scale2[i]*30);
	scale2[i]=scale2[i]+speed2[i];
	timer2[i]=timer2[i]+1;
	}
	i++;
}

if(time>=20 && time<200 && time%20==0){ PlaySE(SEearth2); }


let size=0;
let strength=12+(GetArgument*2);
	SetIntersectionCircle(effect1x,effect1y,100,strength*(1-(time/300))*0.6,true);
	SetIntersectionCircle(effect1x,effect1y,200,strength*(1-(time/300))*0.8,true);
	SetIntersectionCircle(effect1x,effect1y,300,strength*(1-(time/300))*1,false);

if(time==200){ Obj_Delete(effect1); SetCommonData("EndOfBomb",1); SetSpeed(4.5,2); End; }

time++;

} //Mainloop
} //Bomb Earth


//==========================================================================================================


//BOMB WOOD

script_spell BombWood{

let time=0;
let bombtime=0;
let angle=rand(0,360);

let effect1=0;
let effect2=0;

let object1=[];
let timer1=[];
let rotation1=[];
let angle1=[];

let object2=[];
let scale2=[];
let angle2=[];
let fade2=[];
let timer2=[];

let GRseeds=GetCurrentScriptDirectory~"Images\BombWood1.png";
let GRroots=GetCurrentScriptDirectory~"Images\BombWood2.png";

let SEwood1=GetCurrentScriptDirectory~"Sounds\BombWood1.wav";
let SEwood2=GetCurrentScriptDirectory~"Sounds\BombWood2.wav";

@Initialize{
}

@MainLoop{

if(time<300){ SetSpeed(1,1); }
if(time==0){ SetPlayerInvincibility(360); }


if(time>=0 && time<90 && time%(9-GetArgument)==0){
let xsize=19;
let ysize=19;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetPlayerX,GetPlayerY); ObjEffect_SetScale(effect1,1,1);
	Obj_SetSpeed(effect1,rand(5,8)); Obj_SetAngle(effect1,270+60*cos(angle));
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,GRseeds); ObjEffect_SetRenderState(effect1,ALPHA);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect1,0,255,255,255,255); ObjEffect_SetVertexColor(effect1,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,255,255,255,255); ObjEffect_SetVertexColor(effect1,3,255,255,255,255);
	object1=object1~[effect1];
	timer1=timer1~[effect1];
	timer1[length(object1)-1]=0;
	rotation1=rotation1~[effect1];
	rotation1[length(object1)-1]=rand(-5,5);
	angle1=angle1~[effect1];
	angle1[length(object1)-1]=rand(0,360);
angle+=360/10;
PlaySE(SEwood1);
}


let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); rotation1=erase(rotation1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
		if(Obj_GetSpeed(object1[i])>0){ Obj_SetSpeed(object1[i],Obj_GetSpeed(object1[i])-0.1); }
		ObjEffect_SetAngle(object1[i],0,0,angle1[i]);
		SetIntersectionCircle(Obj_GetX(object1[i]),Obj_GetY(object1[i]),20,0.5,true);
		if(Obj_GetSpeed(object1[i])<=0){

let xsize=149;
let ysize=199;
let angle=rand(0,360);
	loop(5){
	effect2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect2,Obj_GetX(object1[i]),Obj_GetY(object1[i])); ObjEffect_SetScale(effect2,0,0);
	ObjEffect_SetLayer(effect2,2); ObjEffect_SetTexture(effect2,GRroots); ObjEffect_SetRenderState(effect2,ALPHA);
	ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
	ObjEffect_SetVertexXY(effect2,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect2,0,0,0);
	ObjEffect_SetVertexXY(effect2,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect2,1,xsize,0);
	ObjEffect_SetVertexXY(effect2,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect2,2,0,ysize);
	ObjEffect_SetVertexXY(effect2,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect2,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect2,0,255,255,255,255); ObjEffect_SetVertexColor(effect2,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect2,2,255,255,255,255); ObjEffect_SetVertexColor(effect2,3,255,255,255,255);
	object2=object2~[effect2];
	timer2=timer2~[effect2];
	timer2[length(object2)-1]=0;
	angle2=angle2~[effect2];
	angle2[length(object2)-1]=angle;
	scale2=scale2~[effect2];
	scale2[length(object2)-1]=0;
	fade2=fade2~[effect2];
	fade2[length(object2)-1]=255;
	angle+=360/5;
	}

		Obj_Delete(object1[i]);
		}
	angle1[i]=angle1[i]+rotation1[i];
	timer1[i]=timer1[i]+1;
	}
i++;
}

let i=0;
while(i<length(object2)){
	if(Obj_BeDeleted(object2[i])){
	object2=erase(object2,i); timer2=erase(timer2,i); angle2=erase(angle2,i); scale2=erase(scale2,i); fade2=erase(fade2,i);
	i--;
	}
	else{
	if(scale2[i]<1 && timer2[i]<90){ Obj_SetPosition(object2[i],Obj_GetX(object2[i])+1.7*cos(angle2[i]-90),Obj_GetY(object2[i])+1.7*sin(angle2[i]-90)); }
	if(scale2[i]<1 && timer2[i]>=90){ Obj_SetPosition(object2[i],Obj_GetX(object2[i])-1.7*cos(angle2[i]-90),Obj_GetY(object2[i])-1.7*sin(angle2[i]-90)); }
	ObjEffect_SetAngle(object2[i],0,0,angle2[i]);
	ObjEffect_SetScale(object2[i],scale2[i]/1.5,scale2[i]);
let distance=-(scale2[i]*80);
	loop(8){
	if(distance<-30){ SetIntersectionCircle(Obj_GetX(object2[i])+distance*cos(angle2[i]-90),Obj_GetY(object2[i])+distance*sin(angle2[i]-90),20,0.5,true); }
	if(distance>=-30 && scale2[i]>0.3){ SetIntersectionCircle(Obj_GetX(object2[i])+distance*cos(angle2[i]-90),Obj_GetY(object2[i])+distance*sin(angle2[i]-90),20,2.5,true); }
	distance+=(scale2[i]*80)/4;
	}

	if(scale2[i]<1 && timer2[i]<90){ scale2[i]=scale2[i]+0.02; }
	if(scale2[i]>0 && timer2[i]>=90){ scale2[i]=scale2[i]-0.02; }
	if(scale2[i]<0){ Obj_Delete(object2[i]); }

	if(timer2[i]==0){ PlaySE(SEwood2); }

	timer2[i]=timer2[i]+1;
	}
i++;
}


if(time==300){ SetCommonData("EndOfBomb",1); SetSpeed(4.5,2); End; }

time++;

} //Mainloop
} //Bomb Wood



//==========================================================================================================


//BOMB METAL

script_spell BombMetal{

let time=0;
let bombtime=0;
let angle=0;
let fade=0;
let ani=0;
let lastsfx=0;

let shot1=0;
let bullet1=[];
let timer1=[];
let angle1=[];
let pulled1=[];

let effect1=0;
let object1=[];

let effect2=0;
let object2=[];
let timer2=[];
let radius2=[];
let fade2=[];
let scale2=[];

let effect3=0;
let object3=[];
let timer3=[];
let radius3=[];
let fade3=[];
let scale3=[];

let GRtrackerbeam=GetCurrentScriptDirectory~"Images\BombMetal.png";

let SEmetal1=GetCurrentScriptDirectory~"Sounds\BombMetal1.wav";
let SEmetal2=GetCurrentScriptDirectory~"Sounds\BombMetal2.wav";
let SEmetal3=GetCurrentScriptDirectory~"Sounds\BombMetal3.wav";

@Initialize{
}

@MainLoop{

if(time<300){ SetSpeed(1,1); }
if(time==0){ SetPlayerInvincibility(420); }


if(time>=0 && time<30){
	loop(5+GetArgument){
	let radius=rand(150,450);
	let angle=270+rand(-60,60);
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetPlayerX+radius*cos(angle),GetPlayerY+radius*sin(angle));
	Obj_SetAngle(shot1,rand(0,360));
	Obj_SetSpeed(shot1,0);
	ObjShot_SetDelay(shot1,10);
	Obj_SetAutoDelete(shot1,true);
	ObjShot_SetGraphic(shot1,25);
	ObjShot_SetDamage(shot1,0.1);
	ObjShot_SetPenetration(shot1,300);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=0;
	pulled1=pulled1~[shot1];
	pulled1[length(bullet1)-1]=0;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i); pulled1=erase(pulled1,i); if(lastsfx==0){ PlaySE(SEmetal3); lastsfx=4; }
	i--;
	}
	else{

	if(time<150){
	Obj_SetAngle(bullet1[i],atan2(GetPlayerY-Obj_GetY(bullet1[i]),GetPlayerX-Obj_GetX(bullet1[i])));
		if(angle+90>=Obj_GetAngle(bullet1[i])-15 && angle+90<=Obj_GetAngle(bullet1[i])+15){
			if((((GetPlayerX-Obj_GetX(bullet1[i]))^2+(GetPlayerY-Obj_GetY(bullet1[i]))^2)^0.5)>=30){
			Obj_SetSpeed(bullet1[i],2+500/(((GetPlayerX-Obj_GetX(bullet1[i]))^2+(GetPlayerY-Obj_GetY(bullet1[i]))^2)^0.5));
			}
			if((((GetPlayerX-Obj_GetX(bullet1[i]))^2+(GetPlayerY-Obj_GetY(bullet1[i]))^2)^0.5)<30){
			Obj_SetSpeed(bullet1[i],5);
			}
		}
	} //Pulling in

	if(time>=150 && time<180 && Obj_GetSpeed(bullet1[i])>0.3){ Obj_SetSpeed(bullet1[i],Obj_GetSpeed(bullet1[i])-0.05); }
	if(time>=150 && time<180 && Obj_GetSpeed(bullet1[i])<=0.3 && Obj_GetSpeed(bullet1[i])>=0.2){ Obj_SetSpeed(bullet1[i],0); }
	if((((GetPlayerX-Obj_GetX(bullet1[i]))^2+(GetPlayerY-Obj_GetY(bullet1[i]))^2)^0.5)<30 && Obj_GetSpeed(bullet1[i])>0.3){ Obj_SetSpeed(bullet1[i],0); }

	if(time>=180){
	let shoot=rand_int(0,300-time);
		if((((GetPlayerX-Obj_GetX(bullet1[i]))^2+(GetPlayerY-Obj_GetY(bullet1[i]))^2)^0.5)<100 || (atan2(GetPlayerY-Obj_GetY(bullet1[i]),GetPlayerX-Obj_GetX(bullet1[i]))>angle+90-15 && atan2(GetPlayerY-Obj_GetY(bullet1[i]),GetPlayerX-Obj_GetX(bullet1[i]))<angle+90+15)){
			if(Obj_GetSpeed(bullet1[i])<1){
			Obj_SetAngle(bullet1[i],angle-90+rand(-7,7));
			Obj_SetSpeed(bullet1[i],0);
			}

			if(shoot<=3){ Obj_SetSpeed(bullet1[i],4); }

			if((((GetPlayerX-Obj_GetX(bullet1[i]))^2+(GetPlayerY-Obj_GetY(bullet1[i]))^2)^0.5)>50){
			Obj_SetSpeed(bullet1[i],Obj_GetSpeed(bullet1[i])+1);
			}
			ObjShot_SetDamage(bullet1[i],5+(0.02*GetCommonData("Power")));
		}
	}

	if(time>=330){ ObjShot_FadeDelete(bullet1[i]); }
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(lastsfx>0){ lastsfx--; }

//=============================================

//Tractor Beam

if(time==0){
let xsize=124;
let ysize=239;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetPlayerX,GetPlayerY); ObjEffect_SetScale(effect1,2,2);
	ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,GRtrackerbeam); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect1,0,fade,255,255,255); ObjEffect_SetVertexColor(effect1,1,fade,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,fade,255,255,255); ObjEffect_SetVertexColor(effect1,3,fade,255,255,255);
PlaySE(SEmetal1);
}

if(time>=10 && time<120 && time%8==0){
let xsize=71;
let ysize=33;
	effect2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect2,GetPlayerX,GetPlayerY); ObjEffect_SetScale(effect2,2,2);
	ObjEffect_SetLayer(effect2,3); ObjEffect_SetTexture(effect2,GRtrackerbeam); ObjEffect_SetRenderState(effect2,ADD);
	ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
	ObjEffect_SetVertexXY(effect2,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect2,0,0,251);
	ObjEffect_SetVertexXY(effect2,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect2,1,xsize,251);
	ObjEffect_SetVertexXY(effect2,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect2,2,0,251+ysize);
	ObjEffect_SetVertexXY(effect2,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect2,3,xsize,251+ysize);
	ObjEffect_SetVertexColor(effect2,0,0,255,255,255); ObjEffect_SetVertexColor(effect2,1,0,255,255,255);
	ObjEffect_SetVertexColor(effect2,2,0,255,255,255); ObjEffect_SetVertexColor(effect2,3,0,255,255,255);
	object2=object2~[effect2];
	timer2=timer2~[effect2];
	timer2[length(object2)-1]=0;
	radius2=radius2~[effect2];
	radius2[length(object2)-1]=350;
	fade2=fade2~[effect2];
	fade2[length(object2)-1]=0;
	scale2=scale2~[effect2];
	scale2[length(object2)-1]=2;
}

let i=0;
while(i<length(object2)){
	if(Obj_BeDeleted(object2[i])){
	object2=erase(object2,i); timer2=erase(timer2,i); radius2=erase(radius2,i); fade2=erase(fade2,i); scale2=erase(scale2,i);
	i--;
	}
	else{
	ObjEffect_SetVertexColor(object2[i],0,fade2[i],255,255,255); ObjEffect_SetVertexColor(object2[i],1,fade2[i],255,255,255);
	ObjEffect_SetVertexColor(object2[i],2,fade2[i],255,255,255); ObjEffect_SetVertexColor(object2[i],3,fade2[i],255,255,255);
	ObjEffect_SetScale(object2[i],scale2[i],scale2[i]);
	Obj_SetPosition(object2[i],GetPlayerX+(radius2[i])*cos(angle-90),GetPlayerY+(radius2[i])*sin(angle-90));
	ObjEffect_SetAngle(object2[i],0,0,angle);

	if(radius2[i]>200){ fade2[i]=fade2[i]+7; }
	if(radius2[i]<200){ fade2[i]=fade2[i]-7; }
	if(radius2[i]>0){ radius2[i]=radius2[i]-6; }

	if(time>=180){ Obj_Delete(object2[i]); }
	if(radius2[i]>50){ scale2[i]=3-170/radius2[i]; }
	timer2[i]=timer2[i]+1;
	}
i++;
}


if(time>=180 && time<290 && time%5==0){
let xsize=71;
let ysize=33;
	effect3=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect3,GetPlayerX,GetPlayerY); ObjEffect_SetScale(effect3,0,0);
	ObjEffect_SetLayer(effect3,3); ObjEffect_SetTexture(effect3,GRtrackerbeam); ObjEffect_SetRenderState(effect3,ADD);
	ObjEffect_SetPrimitiveType(effect3,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect3,4);
	ObjEffect_SetVertexXY(effect3,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect3,0,0,251);
	ObjEffect_SetVertexXY(effect3,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect3,1,xsize,251);
	ObjEffect_SetVertexXY(effect3,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect3,2,0,251+ysize);
	ObjEffect_SetVertexXY(effect3,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect3,3,xsize,251+ysize);
	ObjEffect_SetVertexColor(effect3,0,0,255,255,255); ObjEffect_SetVertexColor(effect3,1,0,255,255,255);
	ObjEffect_SetVertexColor(effect3,2,0,255,255,255); ObjEffect_SetVertexColor(effect3,3,0,255,255,255);
	object3=object3~[effect3];
	timer3=timer3~[effect3];
	timer3[length(object3)-1]=0;
	radius3=radius3~[effect3];
	radius3[length(object3)-1]=0;
	fade3=fade3~[effect3];
	fade3[length(object3)-1]=0;
	scale3=scale3~[effect3];
	scale3[length(object3)-1]=0;
}

let i=0;
while(i<length(object3)){
	if(Obj_BeDeleted(object3[i])){
	object3=erase(object3,i); timer3=erase(timer3,i); radius3=erase(radius3,i); fade3=erase(fade3,i); scale3=erase(scale3,i);
	i--;
	}
	else{
	ObjEffect_SetVertexColor(object3[i],0,fade3[i],255,255,255); ObjEffect_SetVertexColor(object3[i],1,fade3[i],255,255,255);
	ObjEffect_SetVertexColor(object3[i],2,fade3[i],255,255,255); ObjEffect_SetVertexColor(object3[i],3,fade3[i],255,255,255);
	ObjEffect_SetScale(object3[i],scale3[i],scale3[i]);
	Obj_SetPosition(object3[i],GetPlayerX+(radius3[i])*cos(angle-90),GetPlayerY+(radius3[i])*sin(angle-90));
	ObjEffect_SetAngle(object3[i],0,0,angle);
	if(radius3[i]<50){ fade3[i]=fade3[i]+12; }
	if(radius3[i]>=200){ fade3[i]=fade3[i]-6; }
	radius3[i]=radius3[i]+12;

	if(time>=360){ Obj_Delete(object3[i]); }
	if(radius3[i]>50){ scale3[i]=3-170/radius3[i]; }
	timer3[i]=timer3[i]+1;
	}
i++;
}

if(time==180){ PlaySE(SEmetal2); }

if(GetKeyState(VK_LEFT)==KEY_HOLD){ angle-=0.8; }
if(GetKeyState(VK_RIGHT)==KEY_HOLD){ angle+=0.8; }
if(time%4==0 && time<210){ ani+=125; }
if(time%4==0 && time>=210){ ani-=125; }

if(time<140 && fade<210){ fade+=5; }
if(time>=140 && time<180 && fade>0){ fade-=5; }

if(time>=180 && time<300 && fade<210){ fade+=5; }
if(time>=300 && fade>0){ fade-=5; }

let xsize=124;
let ysize=239;
ObjEffect_SetVertexUV(effect1,0,0+ani,0); ObjEffect_SetVertexUV(effect1,1,xsize+ani,0);
ObjEffect_SetVertexUV(effect1,2,0+ani,ysize); ObjEffect_SetVertexUV(effect1,3,xsize+ani,ysize);
ObjEffect_SetVertexColor(effect1,0,fade,255,255,255); ObjEffect_SetVertexColor(effect1,1,fade,255,255,255);
ObjEffect_SetVertexColor(effect1,2,0,255,255,255); ObjEffect_SetVertexColor(effect1,3,0,255,255,255);

ObjEffect_SetAngle(effect1,0,0,angle);
Obj_SetPosition(effect1,GetPlayerX+140*cos(angle-90),GetPlayerY+140*sin(angle-90));


if(time==360){ SetCommonData("EndOfBomb",1); SetSpeed(4.5,2); End; }

time++;

} //Mainloop
} //Bomb Metal

//==========================================================================================================


// BOMB SPELLCIRCLE

script_spell Spellcircle{

let time=0;
let scale=0;
let fade=120;
let OBJspellcircle=0;

let GRspellcircle=GetCurrentScriptDirectory~"Images\SpellCircle.png";

@Initialize{
}

@MainLoop{


if(time==0){
let xsize=249;
let ysize=249;
	OBJspellcircle=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(OBJspellcircle,GetPlayerX,GetPlayerY);
	ObjEffect_SetScale(OBJspellcircle,scale,scale);
	ObjEffect_SetLayer(OBJspellcircle,1); ObjEffect_SetTexture(OBJspellcircle,GRspellcircle); ObjEffect_SetRenderState(OBJspellcircle,ADD);
	ObjEffect_SetPrimitiveType(OBJspellcircle,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJspellcircle,4);
	ObjEffect_SetVertexXY(OBJspellcircle,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(OBJspellcircle,0,0,0);
	ObjEffect_SetVertexXY(OBJspellcircle,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(OBJspellcircle,1,xsize,0);
	ObjEffect_SetVertexXY(OBJspellcircle,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(OBJspellcircle,2,0,ysize);
	ObjEffect_SetVertexXY(OBJspellcircle,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(OBJspellcircle,3,xsize,ysize);
	ObjEffect_SetVertexColor(OBJspellcircle,0,fade,255,255,255); ObjEffect_SetVertexColor(OBJspellcircle,1,fade,255,255,255);
	ObjEffect_SetVertexColor(OBJspellcircle,2,fade,255,255,255); ObjEffect_SetVertexColor(OBJspellcircle,3,fade,255,255,255);
}


Obj_SetPosition(OBJspellcircle,GetPlayerX,GetPlayerY);
ObjEffect_SetAngle(OBJspellcircle,0,0,time*4);
ObjEffect_SetScale(OBJspellcircle,scale,scale);

if(scale<1){ scale+=0.03; }

if(GetCommonData("EndOfBomb")==1){
	if(scale>0){ scale-=0.1; }
	if(scale<=0 || GetCommonDataDefault("InEvent",0)==1){ Obj_Delete(OBJspellcircle); SetCommonData("EndOfBomb",0); End; }
}

time++;

} //Mainloop
} //Spellcircle