local GroundFrictionSystem = inherited("GroundFrictionSystem", SystemMap)

function GroundFrictionSystem:new()
	local ms = instance(self)
	return ms
end

function GroundFrictionSystem:wants(ent)
	return ent.aspects.ground_friction and ent.aspects.movement
end

function GroundFrictionSystem:ent_added(ent)

end

function GroundFrictionSystem:ent_removed(ent)
end

local action_delta = {
	left = {x = -1, y = 0},
	right = {x = 1, y = 0},
	up = {x = 0, y = -1},
	down = {x = 0, y = 1},
}

function GroundFrictionSystem:step(dt)
	for ent, _ in pairs(self.ents) do
		if ent.z <= 0 then
			local dx,dy = ent.dx,ent.dy
			local tf = ent.ground_friction
			if dx ~= 0 or dy ~= 0 then
				dx = math.approach(dx, 0, dt*math.abs(dx)*tf + tf*dt)
				dy = math.approach(dy, 0, dt*math.abs(dy)*tf + tf*dt)
				ent:set_speed_2d(dx, dy)
			end
		end
	end
end

return GroundFrictionSystem