-------------------------------------------------------------------------------
-- Copyright (c) 2012 - Roland Yonaba
-- Moving entities
-------------------------------------------------------------------------------

local Entity = require 'src.entity.base.entity'
local MovingEntity = Entity:extends({ 
  move_speed = 10,
  directions = {
    ['left'] = {x = -1, y = 0},
    ['right'] = {x = 1, y = 0},
    ['up'] = {x = 0, y = -1},
    ['down'] = {x = 0, y = 1},
  },
})

-- Updates the entity
function MovingEntity:update(dt)
    self.y = self.y - ((self.y - self.grid_y) * self.move_speed * dt)
    self.x = self.x - ((self.x - self.grid_x) * self.move_speed * dt)
end

-- Gets next grid position
function MovingEntity:getNextGridPosition(dir)
  local next_x = self.grid_x + self.directions[dir].x
  local next_y = self.grid_y + self.directions[dir].y
  return next_x, next_y
end

return MovingEntity