script_enemy_main {

    #include_function ".\enemyanim.txt"
    #include_function ".\..\lib\enemyfunctions.txt"
	let frame=0;
	let item=0;
	let itemval=0;

task laser(ang){
	let counter=0;
	let obj=Obj_Create(OBJ_SINUATE_LASER);
	Obj_SetPosition(obj, GetX, GetY);
	Obj_SetSpeed(obj, 4);
	Obj_SetAngle(obj, ang);
	ObjSinuateLaser_SetLength(obj, 200);
	ObjSinuateLaser_SetWidth(obj, 10);
	ObjShot_SetGraphic(obj, 232);
	while(Obj_BeDeleted(obj)==false){
		counter++;
		if(InField(Obj_GetX(obj), Obj_GetY(obj))==true){
			if(GetCommonData("DIFFICULTY")=="EASY" && counter%15==0){
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang+90, 59, 10);
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang-90, 59, 10);
				PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
			}
			if(GetCommonData("DIFFICULTY")=="NORMAL" && counter%15==0){
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang+60, 59, 10);
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang-60, 59, 10);
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang+120, 59, 10);
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang-120, 59, 10);
				PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
			}
			if(GetCommonData("DIFFICULTY")=="HARD" && counter%15==0){
				ascent(i in 1..4){
					CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang+i*45, 59, 10);
					CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang-i*45, 59, 10);
				}
				PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
			}
			if(GetCommonData("DIFFICULTY")=="LUNATIC" && counter%15==0){
				ascent(i in 1..6){
					CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang+i*30, 59, 10);
					CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, ang-i*30, 59, 10);
				}
				PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
			}
		}else if(counter%2==0){
			if(Obj_GetX(obj)>GetCenterX){
				CreateShot01(GetClipMaxX, GetClipMaxY, 8, rand(245, 270), rand_int(135, 148), 0);
			}else{
				CreateShot01(GetClipMinX, GetClipMaxY, 8, rand(270, 295), rand_int(135, 148), 0);
			}
		}
		yield;
	}
}
	
	@Initialize {
		EnemyInit(30, 100);
		SetMovePosition03(GetX, GetY+150, 10, 3);
	}
	
	@MainLoop{
		SetCollisionA(GetX, GetY, 12);
		SetCollisionB(GetX, GetY, 12);
		frame++;
		if(frame==100){
			PlaySE(GetCurrentScriptDirectory~"sound\Laser1.wav");
			laser(atan2(GetClipMaxY-GetY, GetClipMinX-GetX));
			laser(atan2(GetClipMaxY-GetY, GetClipMaxX-GetX));
		}
		if(frame>=300){
			SetY(GetY-2);
		}
		if(GetY<GetClipMinY-20){VanishEnemy; item=1;}
        yield;
	}
		
	@DrawLoop {
		bigfairy;
	}
	
	@Finalize {
		if(item==0){
			loop(rand_int(15, 25)){ItemDrop(0, GetX, GetY);}
		}
	}
}