script_enemy_main {
let randnum = rand(-2, 2);
let radius = 50;
let frame1 = 30;
let frame2 = 0;
let frame3 = 0;
let frame4 = 0;
let frame5 = 0;
let frame6 = 0;
let frame7 = 0;
let frame8 = 0;
let angle2 = 0;
let frame9 = 0;
let frame10 = 0;
let frame11 = 0;
let anim1 = 30;
let anim2 = 0;
let anim3 = 0;
let a1 = 0;
let a2 = 0;
let a3 = 0;
let a4 = 0;
let a5 = 0;
let a6 = 0;
let a7 = 0;
let a8 = 0;
let acc1 = 0;
let acc2 = 0;
let acc3 = 0;
let acc4 = 0;
let acc5 = 0;
let acc6 = 0;
let acc7 = 0;
let acc8 = 0;
let acc9 = 0;
let acc10 = 0;
let acc11 = 0;
let acc12 = 0;
let angle1 = 0;
let kospin = 0;
let angle3 = 0;
let ang = 0;
let SP = GetCurrentScriptDirectory~"sp/sp.png";
let Custom = GetCurrentScriptDirectory~"sup\supershot.txt";
let sh1 = GetCurrentScriptDirectory~"shot.wav";
let sh2 = GetCurrentScriptDirectory~"shot2.wav";
let dir = 0;
let r = 120;
    @Initialize {
SetCommonData("alivefairies", GetCommonDataDefault("alivefairies", 0)+1);
movementTask;
SetMovePosition03(GetX, GetY+100, 15, 5);
LoadUserShotData(Custom);
LoadSE(sh1);
LoadSE(sh2);
LoadGraphic(SP);
SetLife(500);
    }
function wait(w){ loop(w){ yield; }}



task DoubleSpoiler{
	loop{
	PlaySE(sh1);
	loop(2){
	
	CreateShotReflect(GetX, GetY, 3, randnum+angle1+angle2+1, 70, 0);
	CreateShotReflect(GetX, GetY, 3, randnum+angle1+angle2+2, 70, 0);
	CreateShotReflect(GetX, GetY, 3, randnum+angle1+angle2-1, 70, 0);
	CreateShotReflect(GetX, GetY, 3, randnum+angle1+angle2-2, 70, 0);
	CreateShotReflect(GetX, GetY, 3, randnum+angle1+angle2, 70, 0);
	angle1+=360/2;
	angle2+=11;
	}
	wait(60);
	}
}

task CreateShotReflect(x, y, v, ang, graphic, delay) {
		let obj_id = Obj_Create(OBJ_SHOT); let border = 0; let  counter = 0;
		Obj_SetPosition(obj_id, x, y);
		ObjShot_SetGraphic(obj_id, graphic);
		Obj_SetSpeed(obj_id, v); Obj_SetAngle(obj_id, ang); ObjShot_SetDelay(obj_id, delay);
		while(!Obj_BeDeleted(obj_id)) {
			if(counter <= 1) {
				
				if(Obj_GetX(obj_id) > GetClipMaxX+border) {  	CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 2, 180-Obj_GetAngle(obj_id), 70, 0); Obj_Delete(obj_id); }
				else if(Obj_GetX(obj_id) < GetClipMinX-border) { 	CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 2, 180-Obj_GetAngle(obj_id), 70, 0); Obj_Delete(obj_id); }
				//if(Obj_GetY(obj_id) < GetClipMinY-border) {  Obj_SetY(obj_id, 2*(GetClipMinY-border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)); counter+=1; }
				//else if(Obj_GetY(obj_id) > GetClipMaxY+border) { Obj_SetY(obj_id, 2*(GetClipMaxY+border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)); counter+=1; }
			}
			yield;
		}
	}
task movementTask
	{
		loop
		{	if(GetArgument==0){
			SetMovePosition03(GetEnemyX+r*cos(dir), GetEnemyY+r*sin(dir), 20, 10);
			
			dir++;
			}
			else{
			SetMovePosition03(GetEnemyX-r*cos(dir), GetEnemyY+r*sin(dir), 20, 10);
			dir--;
			}
		yield;
		}
			
		}
	

    @MainLoop {
yield;
SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 24);


ang++;
if(frame1==120){
DoubleSpoiler;
} 


        frame1++;
        frame2++;
        frame3++;
        frame4++;
    }

    @DrawLoop {
anim1++;
if (anim1 >= 30 && anim1 <= 40 && GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(63, 320, 96, 349);
SetAlpha(255);
DrawGraphic(GetX, GetY);
}
if (anim1 >= 40 && anim1 <= 50 && GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(96, 320, 128, 349);
SetAlpha(255);
DrawGraphic(GetX, GetY);
}
if (anim1 >= 50 && anim1 <= 60 && GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(128, 320, 160, 349);
SetAlpha(255);
DrawGraphic(GetX, GetY);
}


if (anim1 >= 30 && anim1 <= 40 && GetSpeedX > 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(256, 320, 288, 349);
SetAlpha(255);
DrawGraphic(GetX, GetY);
}
if (anim1 >= 40 && anim1 <= 50 && GetSpeedX > 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(288, 320, 319, 349);
SetAlpha(255);
DrawGraphic(GetX, GetY);
}
if (anim1 >= 50 && anim1 <= 60 && GetSpeedX > 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(319, 320, 352, 349);
SetAlpha(255);
DrawGraphic(GetX, GetY);
}




if (anim1 >= 30 && anim1 <= 40 && GetSpeedX < 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(-1,1);
SetGraphicRect(256, 320, 288, 349);
SetAlpha(255);
DrawGraphic(GetX, GetY);
}
if (anim1 >= 40 && anim1 <= 50 && GetSpeedX < 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(-1,1);
SetGraphicRect(288, 320, 319, 349);
SetAlpha(255);
DrawGraphic(GetX, GetY);
}
if (anim1 >= 50 && anim1 <= 60 && GetSpeedX < 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(-1,1);
SetGraphicRect(319, 320, 352, 349);
SetAlpha(255);
DrawGraphic(GetX, GetY);
}
if (anim1 == 60){
anim1 = 30;
}
acc1 += 13;
acc2 += 9;
 }
    @Finalize {
SetCommonData("alivefairies", GetCommonDataDefault("alivefairies", 0)-1);
if(GetX>GetClipMinX-10 && GetX<GetClipMaxX+10 && GetY>GetClipMinY-10 && GetY<GetClipMaxY+10){
PlaySE(GetCurrentScriptDirectory~"explode.wav");
loop(rand(0,1)){
CreateItem(ITEM_SCORE,GetX + rand(-10,10),GetY + rand(-10,10));
}
}
    }
}
