dofile("scripts/entities/entityinclude.lua")

flag = 0
node = 0
gfx = ""
function commonInit(me, g, f)
	gfx = g
	flag = f
	setupEntity(me, gfx)
	entity_setEntityType(me, ET_NEUTRAL)
	--[[
	if not isFlag(flag, 0) then
		entity_alpha(me, 0)
	end
	]]--
	entity_setWeight(me, 200)
	if isFlag(flag, 0) then
		debugLog("SETTING MOVABLE to TRUE")
		entity_setProperty(me, EP_MOVABLE, true)
	else
		entity_setProperty(me, EP_MOVABLE, false)
	end
	--entity_setActivation(me, AT_CLICK, 512, 32)
end

function hitSurface(me)
end

function update(me, dt)
	if node == 0 then
		node = entity_getNearestNode(me, gfx)
	end
	if isFlag(flag, 0) then
		entity_updateMovement(me, dt)
		x = node_x(node)
		y = node_y(node)
		--debugLog(string.format("node(%d, %d)", x, y))
		if entity_isPositionInRange(me, x, y, 64) then
			--debugLog("IN RANGE!")
			entity_stopPull(me)
			entity_setProperty(me, EP_MOVABLE, false)
			setFlag(flag, 1)			
		end
	else
		entity_setPosition(me, node_x(node), node_y(node))
	end
end

function activate(me)
--[[
	if isFlag(flag, 0) then
		entity_alpha(me, 0, 1)
		spawnParticleEffect("Collect", entity_x(me), entity_y(me))
		setFlag(flag, 1)
		entity_setActivation(me, AT_NONE)
	end
	]]--
end

function enterState(me, state)
end

function exitState(me, state)
end


