script_enemy_main {


	let clocka = GetCurrentScriptDirectory ~ "sprites\clocka.png";
	let clockb = GetCurrentScriptDirectory ~ "sprites\clockb.png";
	let clockc = GetCurrentScriptDirectory ~ "sprites\clockc.png";
	let angle = 0;

	@Initialize {
	DeleteSE("se\seExplode01.wav");
	SetLife(1);
	LoadGraphic(clocka);
	LoadGraphic(clockb);
	LoadGraphic(clockc);
	}

	@MainLoop {
	angle+=0.1;
	if(GetDistance(GetPlayerX, GetPlayerY, GetX, GetY)<72 && OnPlayerMissed==false){
		TimeStop(1, 1, 0, 0);
	}
	if(GetX<GetClipMinX-72 || GetX>GetClipMaxX+72 || GetY<GetClipMinY-72 || GetY>GetClipMaxY+72){
		VanishEnemy;
		}
	yield;
	}

	@DrawLoop {
	SetTexture(clock2);
	SetRenderState(ALPHA);
	SetAlpha(200);
	SetGraphicRect(0, 0, 232, 232);
	SetGraphicAngle(0, 0, angle*2);
	SetGraphicScale(0.8, 0.8);
	DrawGraphic(GetX, GetY);
	
	SetTexture(clock1);
	SetRenderState(ADD);
	SetGraphicRect(0, 0, 256, 256);
	SetGraphicAngle(0, 0, -angle*4);
	SetGraphicScale(0.8, 0.8);
	DrawGraphic(GetX, GetY);
	
	SetTexture(clock3);
	SetRenderState(ADD);
	SetGraphicRect(0, 0, 32, 113);
	SetGraphicAngle(0, 0, angle*60);
	SetGraphicScale(0.8, 0.8);
	DrawGraphic(GetX + 32*cos((angle*60)-90), GetY + 32*sin((angle*60)-90));
	
	SetTexture(clock3);
	SetRenderState(ADD);
	SetGraphicRect(32, 0, 64, 113);
	SetGraphicAngle(0, 0, angle*5);
	SetGraphicScale(0.8, 0.8);
	DrawGraphic(GetX + 32*cos((angle*5)-90), GetY + 32*sin((angle*5)-90));
	}

	@Finalize {
	}	
	
	task DrawClock(x, y){
		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj, x, y);
		ObjEffect_InitializeRect(clock2, 1);
		ObjEffect_SetRenderState(obj, ALPHA);
		Obj_SetAlpha(obj, 100);
		Obj_SetCollisionToPlayer(obj, true);
		ObjEffect_SetXYRect(obj, 232, 232);
		ObjEffect_SetUVRect(obj, 0, 0, 232, 232);
		while(!Obj_BeDeleted(obj)){
			Obj_SetAngle(obj, Obj_GetAngle(obj)+0.2);
			if(Obj_IsIntersected(obj)==true){
				loop{
					TimeStop(1, 1, 0, 0);
				}
			}
			yield;
		}
	
		function ObjEffect_InitializeRect(texture, layer){
			  ObjEffect_SetTexture(obj, texture);
			  ObjEffect_SetLayer(obj, layer);
			  ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
			  ObjEffect_CreateVertex(obj, 4);
		}
		
		function ObjEffect_SetXYRect(id, w, h){
			  ObjEffect_SetVertexXY(id, 0, -(w/2), -(h/2));
			  ObjEffect_SetVertexXY(id, 1, w/2, -(h/2));
			  ObjEffect_SetVertexXY(id, 2, w/2, h/2);
			  ObjEffect_SetVertexXY(id, 3, -(w/2), h/2);
		}
		
		function ObjEffect_SetUVRect(id, left, top, right, bottom){
			  ObjEffect_SetVertexUV(id, 0, left, top);
			  ObjEffect_SetVertexUV(id, 1, right, top);
			  ObjEffect_SetVertexUV(id, 2, right, bottom);
			  ObjEffect_SetVertexUV(id, 3, left, bottom);
		}
	}
	
	function GetDistance(x1,y1,x2,y2){
		return(((x2-x1)^2+(y2-y1)^2)^(1/2))
	}
}