//Firework explosion with random core

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Fairy3-15.png");
let SEfireworks3=("script\SoundEffects\fireworks3.wav");
let SEmagics5=("script\SoundEffects\magics5.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=0; let time=0; let animation=0;
let ani=4;
let scale=0.5;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

let shotcolor=GetArgument[0];

SetSpeed(GetArgument[2]);
if(startx<cx){ SetAngle(0-GetArgument[1]); }
if(startx>cx){ SetAngle(180+GetArgument[1]); }

@Initialize{
	LoadGraphic("\script\Images\Enemies\Fairy3-15.png");
	LoadSE("script\SoundEffects\fireworks3.wav");
	LoadSE("script\SoundEffects\magics5.wav");

	SetInvincibility(60);
	SetLife(4);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

if(GetX<=minx-32 || GetX>=maxx+32 || GetY<=miny-32 || GetY>=maxy+32 && frame>=60){ VanishEnemy; }

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){
SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);


if(GetCommonData("Difficulty")==1){
	if(GetSpeed<=1 && shots<1){
	let angle=rand(0,360);
	let speed=3;
		loop(3){
			loop(15){
			CreateShot02(GetX,GetY,speed,angle,-0.05,speed/2,36+shotcolor,0);
			angle+=360/15;
			}
		angle+=360/30;
		speed-=0.7;
		}
		loop(15){
		let angle=rand(0,360);
		CreateShot12(GetX,GetY,2.5*cos(angle),rand(1,-3),-0.02*cos(angle),0.04,0.25*cos(angle),rand(2,2.5),shotcolor,0);
		}
	PlaySE(SEfireworks3);
	shots++;
	}
	if(shots>=1 && shots<4 && time%4==0){ PlaySE(SEmagics5); shots++; }
} //Easy

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

if(GetCommonData("Difficulty")==2){
	if(GetSpeed<=1 && shots<1){
	let angle=rand(0,360);
	let speed=4;
		loop(3){
			loop(25){
			CreateShot02(GetX,GetY,speed,angle,-0.05,speed/2,36+shotcolor,0);
			angle+=360/25;
			}
		angle+=360/50;
		speed-=0.8;
		}
		loop(25){
		let angle=rand(0,360);
		let size=rand_int(0,1);
		CreateShot12(GetX,GetY,2.5*cos(angle),rand(1,-3),-0.02*cos(angle),0.04,0.25*cos(angle),rand(2,2.5),(12*size)+shotcolor,0);
		}
	PlaySE(SEfireworks3);
	shots++;
	}
	if(shots>=1 && shots<4 && time%4==0){ PlaySE(SEmagics5); shots++; }
} //Normal

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

if(GetCommonData("Difficulty")==3){
	if(GetSpeed<=1 && shots<1){
	let angle=rand(0,360);
	let speed=5;
		loop(4){
			loop(30){
			CreateShot02(GetX,GetY,speed,angle,-0.05,speed/2,36+shotcolor,0);
			angle+=360/30;
			}
		angle+=360/60;
		speed-=0.7;
		}
		loop(30){
		let angle=rand(0,360);
		let size=rand_int(0,1);
		CreateShot12(GetX,GetY,2.5*cos(angle),rand(1,-3),-0.02*cos(angle),0.04,0.25*cos(angle),rand(2.5,3),12+(12*size)+shotcolor,0);
		}
	PlaySE(SEfireworks3);
	shots++;
	}
	if(shots>=1 && shots<4 && time%4==0){ PlaySE(SEmagics5); shots++; }
} //Hard

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

if(GetCommonData("Difficulty")==4){
	if(GetSpeed<=1 && shots<1){
	let angle=rand(0,360);
	let speed=5;
		loop(4){
			loop(40){
			CreateShot02(GetX,GetY,speed,angle,-0.05,speed/2,36+shotcolor,0);
			angle+=360/40;
			}
		angle+=360/80;
		speed-=0.7;
		}
		loop(40){
		let angle=rand(0,360);
		CreateShot12(GetX,GetY,2.5*cos(angle),rand(1,-3),-0.02*cos(angle),0.04,0.25*cos(angle),rand(3,3.5),24+shotcolor,0);
		}
	PlaySE(SEfireworks3);
	shots++;
	}
	if(shots>=1 && shots<4 && time%4==0){ PlaySE(SEmagics5); shots++; }
} //Lunatic
} //Onscreen


if(GetSpeed>0 && shots<1){ SetSpeed(GetSpeed-0.05); }
if(shots>=1){ SetSpeed(GetSpeed+0.03); }
if(shots>=1 && startx<cx){ SetAngle(GetAngle-0.7); }
if(shots>=1 && startx>cx){ SetAngle(GetAngle+0.7); }


oldX=GetX;
oldY=GetY;
frame++;
time++;
animation++;
if(animation>=ani*6){ animation=0; }
if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
let side=0;
	SetTexture(GRenemy);
		if(oldX<GetX || oldX>GetX){ side=128; }
		if(animation>=ani*0 && animation<ani*1){ SetGraphicRect(1,side,256,128+side); }
		if(animation>=ani*1 && animation<ani*2){ SetGraphicRect(257,side,512,128+side); }
		if(animation>=ani*2 && animation<ani*3){ SetGraphicRect(513,side,768,128+side); }
		if(animation>=ani*3 && animation<ani*4){ SetGraphicRect(769,side,1024,128+side); }
		if(animation>=ani*4 && animation<ani*5){ SetGraphicRect(513,side,768,128+side); }
		if(animation>=ani*5 && animation<ani*6){ SetGraphicRect(257,side,512,128+side); }
	SetGraphicAngle(0,0,0);
	if(oldX<GetX){ SetGraphicAngle(180,0,0); }
	SetGraphicScale(scale,scale);
	SetColor(255-invincible,255-invincible,255);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	if(GetArgument[3]==1){
	loop(3){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0); }
	loop(4){ CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0); }
	loop(2){ CreateEnemyFromFile("script\Functions\itemscore.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0); }
	}
	if(GetArgument[3]==2){
	CreateEnemyFromFile("script\Functions\itembomb.txt",GetX,GetY,0,0,0);
	}
#include_function "script/Functions/PlayerTypeBonus.txt";
DeleteEnemyShotInCircle(SHOT,GetX,GetY,50);
}
}

}