script_enemy_main {
	#include_function "lib\SHOT_REPLACE\shot_replace.dnh"
	let ImgPup1 = "script\img\enemysprites.png";
	let frame = -120;
	let objShot = NULL;
	let trig = 0;
	let drawframe = 0;
	let am = 0;
	let amm = 0.5;
	let hs = false;
	let GetPoint = true;
	@Initialize{
		SetLife(200);
		SetInvincibility(120);
		SetScore(2000);
		LoadGraphic(ImgPup1);
		SetTexture(ImgPup1);
        		SetGraphicRect(0, 0, 64, 64);
		shotinit;
		Summoner;
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	task Summoner {
		yield;
		while(GetSpeed > 0) {
			SetSpeed(GetSpeed - 0.05);
			yield;
		}
		SetSpeed(0);
		Shooter(GetX, GetY, 2, 90, -0.5, RED03, YELLOW12, 0);
		loop(150) { yield; }
		hs = true;
	}
	@MainLoop{
		SetCollisionA(GetX, GetY, 16);
		SetCollisionB(GetX, GetY, 8);
		yield;
		if(hs) {
			SetSpeed(GetSpeed - 0.05);
		}
		if(frame > 60 && IsOffScreen) {
			GetPoint = false;
			VanishEnemy;
		}
		trig+=10;
		amm = cos(trig);
		am += amm;
		frame++;
	}
	@DrawLoop{
		let dx = 0;
		let dy = 96;
		if(drawframe%16 > 4) {
			dx += 32;
		}
		if(drawframe%16 > 8) {
			dx += 32;
		}
		if(drawframe%16 > 12) {
			dx += 32;
		}
		SetGraphicRect(dx, dy, dx + 32, dy + 32);
		DrawGraphic(GetX, GetY);
		dx = 0;
 	}
	@Finalize{
		Obj_Delete(objShot);
		if(GetPoint) {
			loop(5) {
				CreateItem(ITEM_SCORE,GetX+rand(-50,50),GetY - rand(20,100));
			}
		}
	}
	task Shooter(x, y, v, angle, max_av, graphic1, graphic2, delay) {
		let av = 0;
		objShot = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(objShot, x, y);
		Obj_SetSpeed(objShot, v);
		Obj_SetAngle(objShot, angle);
		ObjShot_SetGraphic(objShot, graphic1);
		ObjShot_SetDelay(objShot, delay);
		loop(delay) { yield; }
		while(Obj_BeDeleted(objShot) == false) {
			if(frame%2 == 1) {
				CreateShot02(Obj_GetX(objShot), Obj_GetY(objShot), 3, rand(0, 360), -0.25, rand(1, 2), graphic2, 10);
			}
			Obj_SetAngle(objShot, Obj_GetAngle(objShot) + av);
			if(av < max_av) {
				av += 0.01;
			}
			else if(av > max_av) {
				av -= 0.01;
			}
			yield;
		}
	}
    task AimAmulet(x, y, v, angle, graphic1, graphic2, delay) {
	let obj = Obj_Create(OBJ_SHOT);
	let aim = false;
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj, angle);
	Obj_SetSpeed(obj, v);
	ObjShot_SetGraphic(obj, graphic1);
	while(Obj_BeDeleted(obj) == false) {
		if(Obj_GetSpeed(obj) > 0 && aim == false) {
			Obj_SetSpeed(obj, Obj_GetSpeed(obj) - 0.05);
		}
		else if(Obj_GetSpeed(obj) < 0) {
			Obj_SetSpeed(obj, 0);
		}
		if(delay > 0) {
			delay--;
		}
		else if(aim == false) {
			Obj_SetAngle(obj, atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));
			ObjShot_SetGraphic(obj, graphic2);
			aim = true;
		}
		else {
			if(Obj_GetSpeed(obj) < v) {
				Obj_SetSpeed(obj, Obj_GetSpeed(obj) + 0.05);
			}
		}
		if(GetLife <= 0) {
			Obj_Delete(obj);
		}
		yield;
	}
  }
}