script_enemy_main{

let opening=30;
let swingspeed=6;
let color=GetArgument;

let core=0;
let direction=0;
let olddirection=[];

let size=0;
let shot1=0;
let timer1=[];
let glass=[];
let glassangle=[];

let shot2=0;
let timer2=[];
let paper=[];
let paperangle=[];
let paperdistance=[];

let laser=0;

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

let SEchime1=("script\SoundEffects\chime1.wav");

@Initialize{
	LoadSE(SEchime1);

	SetLife(1);
	SetScore(100);
}
	
@MainLoop{



if(((GetPlayerX-Obj_GetX(core))^2+(GetPlayerY-Obj_GetY(core))^2)^0.5<40){ ShootDownPlayer; SetPlayerX(cx); SetPlayerY(400); }

if((time+75)%floor(360/swingspeed/2)==0 && time>=20){
let angle=90+opening+direction;
let wavesizea=80;
let wavesizeb=0;
if(GetCommonData("Difficulty")==3){ wavesizeb=5; }
if(GetCommonData("Difficulty")==4){ wavesizeb=5; }
	loop(wavesizea){
	CreateShot01(Obj_GetX(core)+size*cos(angle+olddirection[0]),Obj_GetY(core)+size*sin(angle+olddirection[0]),4,angle,48+color,0);
	angle+=(360-(opening*2))/(wavesizea-1);
	}
angle-=rand(-6,6)+(360-(opening*2))/(wavesizea-1.5);
angle+=(360-(360-(opening*2)))/(wavesizeb*2);
	loop(wavesizeb){
	let speed=0;
	if(GetCommonData("Difficulty")==3){ speed=3; }
	if(GetCommonData("Difficulty")==4){ speed=2; }
		loop(2){
		CreateShot01(Obj_GetX(core)+size*cos(angle+olddirection[0]),Obj_GetY(core)+size*sin(angle+olddirection[0]),speed,angle,47,0);
		speed-=0.5;
		}
	angle+=(360-(360-(opening*2)))/(wavesizeb);
	}
PlaySE(SEchime1);
}


if(time==0){
let angle=0;
	core=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(core,GetX,GetY);
	Obj_SetAngle(core,0);
	Obj_SetAlpha(core,0);
	ObjShot_SetBombResist(core,true);
	ObjShot_SetGraphic(core,0);

let angle=0;
	loop(101){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,90+opening+angle);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetDelay(shot1,20);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,140);
	glass=glass~[shot1];
	timer1=timer1~[shot1];
	timer1[length(glass)-1]=0;
	glassangle=glassangle~[shot1];
	glassangle[length(glass)-1]=90+opening+angle;
	angle+=((360-(opening*2))/100);
	}

let angle=90;
let count=0;
	loop(12){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetDelay(shot1,20);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,24+color);
	paper=paper~[shot1];
	timer2=timer2~[shot1];
	timer2[length(paper)-1]=0;
	paperangle=paperangle~[shot1];
	paperangle[length(paper)-1]=90;
	paperdistance=paperdistance~[shot1];
	paperdistance[length(paper)-1]=120-count;
	olddirection=olddirection~[shot1];
	olddirection[length(paper)-1]=0;
	count+=10;
	}

	laser=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(laser,GetX,GetY);
	Obj_SetAngle(laser,90);
	ObjShot_SetDelay(laser,20);
	ObjShot_SetBombResist(laser,true);
	ObjShot_SetGraphic(laser,155);
	ObjLaser_SetLength(laser,120);
	ObjLaser_SetWidth(laser,10);
	ObjLaser_SetSource(laser,false);
}

let i=0;
	while(i<length(glass)){
		if(Obj_BeDeleted(glass[i])){
		glass=erase(glass,i); timer1=erase(timer1,i); glassangle=erase(glassangle,i);
		i--;
		}
		else{
		Obj_SetPosition(glass[i],Obj_GetX(core)+size*cos(1*direction+glassangle[i]+olddirection[0]),Obj_GetY(core)+size*sin(1*direction+glassangle[i]+olddirection[0]));
		Obj_SetAngle(glass[i],glassangle[i]);

		if(timer1[i]>=20){ Obj_SetAlpha(glass[i],255); }
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
let i=0;
	while(i<length(paper)){
		if(Obj_BeDeleted(paper[i])){
		paper=erase(paper,i); timer2=erase(timer2,i); paperangle=erase(paperangle,i); paperdistance=erase(paperdistance,i); olddirection=erase(olddirection,i);
		i--;
		}
		else{
		Obj_SetPosition(paper[i],Obj_GetX(core)+(size+35+paperdistance[i])*cos(direction+90+olddirection[i]),Obj_GetY(core)+(size+35+paperdistance[i])*sin(direction+90+olddirection[i]));

		Obj_SetAngle(paper[i],paperangle[i]);

		if(timer2[i]>=20){ Obj_SetAlpha(paper[i],255); }
		timer2[i]=timer2[i]+1;
		}
	i++;
	} 



if(size<40){ size+=40/20; } 

Obj_SetPosition(core,GetX,GetY+80);
Obj_SetPosition(laser,Obj_GetX(core)-(size)*cos(direction+90+olddirection[0]),Obj_GetY(core)-(size)*sin(direction+90+olddirection[0]));
Obj_SetAngle(laser,direction*2+90);

direction=(opening/4)*cos(time*swingspeed);
olddirection=olddirection~[direction];
olddirection=erase(olddirection,0);



if(time>=300){
let i=0;
while(i<length(glass)){
	if(Obj_BeDeleted(glass[i])){
	glass=erase(glass,i); timer1=erase(timer1,i); glassangle=erase(glassangle,i);
	i--;
	}
	else{
	Obj_Delete(glass[i]);
	i++;
	}
}
let i=0;
while(i<length(paper)){
	if(Obj_BeDeleted(paper[i])){
	paper=erase(paper,i); timer2=erase(timer2,i); paperangle=erase(paperangle,i); paperdistance=erase(paperdistance,i); olddirection=erase(olddirection,i);
	i--;
	}
	else{
	Obj_Delete(paper[i]);
	i++;
	}
}
Obj_Delete(core);
Obj_Delete(laser);
VanishEnemy;
}



time++;
frame++;

}

@DrawLoop{
}

@Finalize{
}

}