//Annoying Midori

script_enemy_main{

let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;

let shoot=0;
let angle=0;
let speed=0;
let fade=1;
if(GetArgument==1){ fade=1; }

let oldX=0;
let oldY=0;

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=rand_int(0,20); let time=0; let animation=0;
let shots=0;
let oldX=0; let oldY=0;

let GRboss=("\script\Images\CharacterSprites\Midori.png");
let SEshots3=("script\SoundEffects\shots3.wav");

@Initialize{
	LoadGraphic("\script\Images\CharacterSprites\Midori.png");
	
	LoadSE("script\SoundEffects\shots3.wav");

	SetInvincibility(60);
	SetLife(1000);
	SetDamageRate(10,10);
	SetScore(1000);
	SetEnemyMarker(true);
}
	
@MainLoop{

if(GetX<=minx-32 || GetX>=maxx+32 || GetY<=miny-32 || GetY>=maxy+32 && time>=60){ VanishEnemy; }
SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);



if(GetArgument==1){

if(GetCommonData("Difficulty")==1){
	if(shoot==1){
	let angle=rand(0,360);
		loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"509a.txt",GetX,GetY,0,0,angle);
		angle+=360/10;
		}
	usespell=-20;
	shoot=2;
	}
} //Easy

if(GetCommonData("Difficulty")==2){
	if(shoot==1){
	let angle=rand(0,360);
		loop(15){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"509a.txt",GetX,GetY,0,0,angle);
		angle+=360/15;
		}
	usespell=-20;
	shoot=2;
	}
} //Normal

if(GetCommonData("Difficulty")==3){
	if(shoot==1){
	let angle=rand(0,360);
		loop(20){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"509a.txt",GetX,GetY,0,0,angle);
		angle+=360/20;
		}
	usespell=-20;
	shoot=2;
	}
} //Hard

if(GetCommonData("Difficulty")==4){
	if(shoot==1){
	let angle=rand(0,360);
		loop(25){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"509a.txt",GetX,GetY,0,0,angle);
		angle+=360/25;
		}
	usespell=-20;
	shoot=2;
	}
} //Lunatic

if(GetX<cx && GetLife==1000){
	SetAngle(0);
	SetSpeed(1.5);
}
if(GetX>=cx && GetLife==1000){
	SetAngle(0);
	SetSpeed(0);
}
if(time>=190 || GetLife<1000){
	SetLife(999);
	SetAngle(GetAngle-0.7);
	SetSpeed(GetSpeed+0.075);
	angle++;
	shoot++;
}

} //Type 1

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

if(GetArgument==2 || GetArgument==3){

if(GetCommonData("Difficulty")==1){
	if(frame>=35 && frame<40){
		loop(3){
		SetShotDirectionType(PLAYER);
		CreateShot02(GetX+10,GetY-35,rand(2.5,4),rand(-15,15),-0.05,rand(1.5,2),167,0);
		SetShotDirectionType(ABSOLUTE);
		}
	usespell=20;
	}
	if(frame==35){ PlaySE(SEshots3); }
	if(frame==40){ frame=-20; }
} //Easy

if(GetCommonData("Difficulty")==2){
	if(frame>=40 && frame<45){
		loop(4){
		SetShotDirectionType(PLAYER);
		CreateShot02(GetX+10,GetY-35,rand(3,4.5),rand(-20,20),-0.05,rand(1.5,2),167,0);
		SetShotDirectionType(ABSOLUTE);
		}
	usespell=20;
	}
	if(frame==40){ PlaySE(SEshots3); }
	if(frame==45){ frame=-20; }
} //Normal

if(GetCommonData("Difficulty")==3){
	if(frame>=25 && frame<30){
		loop(5){
		SetShotDirectionType(PLAYER);
		CreateShot02(GetX+10,GetY-35,rand(4,5),rand(-25,25),-0.05,rand(1.5,2),167,0);
		SetShotDirectionType(ABSOLUTE);
		}
	usespell=20;
	}
	if(frame==25){ PlaySE(SEshots3); }
	if(frame==30){ frame=-15; }
} //Hard

if(GetCommonData("Difficulty")==4){
	if(frame>=25 && frame<30){
		loop(6){
		SetShotDirectionType(PLAYER);
		CreateShot02(GetX+10,GetY-35,rand(5,6),rand(-30,30),-0.05,rand(1.5,2.5),167,0);
		SetShotDirectionType(ABSOLUTE);
		}
	usespell=20;
	}
	if(frame==25){ PlaySE(SEshots3); }
	if(frame==30){ frame=-15; }
} //Lunatic

if(time==0){ SetSpeed(3); }
if(GetArgument==2){ SetAngle(180-30*cos(time*1.5)); }
if(GetArgument==3){ SetAngle(0+30*cos(time*1.5)); }
SetSpeed(GetSpeed+0.02);

} //Type 2/3


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

if(GetArgument==4 || GetArgument==5){

if(GetCommonData("Difficulty")==1){
	if(time%5==0 && GetX<maxx && GetX>minx){
	let shot1=0;
	let angle=0;
		loop(2){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2.5,(time*6)+angle,0,-0.03,0,167);
		SetShotDirectionType(PLAYER);
		SetShotDataA(shot1,60,3.5,0,0,0,0,161);
		SetShotDirectionType(ABSOLUTE);
		FireShot(shot1);
		angle+=360/2;
		}
	}
	if(time%5==0 && GetX<maxx && GetX>minx){ PlaySE(SEshots3); }
} //Easy

if(GetCommonData("Difficulty")==2){
	if(time%3==0 && GetX<maxx && GetX>minx){
	let shot1=0;
	let angle=0;
		loop(3){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,3,(time*6)+angle,0,-0.03,0,167);
		SetShotDirectionType(PLAYER);
		SetShotDataA(shot1,60,4,0,0,0,0,161);
		SetShotDirectionType(ABSOLUTE);
		FireShot(shot1);
		angle+=360/3;
		}
	}
	if(time%4==0 && GetX<maxx && GetX>minx){ PlaySE(SEshots3); }
} //Normal

if(GetCommonData("Difficulty")==3){
	if(time%3==0 && GetX<maxx && GetX>minx){
	let shot1=0;
	let angle=0;
		loop(4){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,4,(time*6)+angle,0,-0.03,0,167);
		SetShotDirectionType(PLAYER);
		SetShotDataA(shot1,60,4.5,0,0,0,0,161);
		SetShotDirectionType(ABSOLUTE);
		FireShot(shot1);
		angle+=360/4;
		}
	}
	if(time%4==0 && GetX<maxx && GetX>minx){ PlaySE(SEshots3); }
} //Hard

if(GetCommonData("Difficulty")==4){
	if(time%2==0 && GetX<maxx && GetX>minx){
	let shot1=0;
	let angle=0;
		loop(4){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,5,(time*6)+angle,0,-0.03,0,167);
		SetShotDirectionType(PLAYER);
		SetShotDataA(shot1,60,5,0,0,0,0,161);
		SetShotDirectionType(ABSOLUTE);
		FireShot(shot1);
		angle+=360/4;
		}
	}
	if(time%4==0 && GetX<maxx && GetX>minx){ PlaySE(SEshots3); }
} //Lunatic

SetSpeed(4);
if(GetArgument==4){ SetAngle(160); }
if(GetArgument==5){ SetAngle(20); }

SetShotAutoDeleteClip(200,200,200,200);

} //Type 4/5


oldX=GetX;
oldY=GetY;
time++;
frame++;

if(usespell>0){ usespell--; }
if(usespell<0){ usespell++; }

}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255*fade,255*fade,255*fade);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		if(oldX>GetX){ SetGraphicRect(128,outfit,256,outfit+128); }
		if(oldX<GetX){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
	SetColor(255,255,255);
}

@Finalize{
}

}