local racing = require("love_src.src.system.racing_phy")

local entity = {}

entity.__index = entity

function entity.load(actor, finish)
  local self = setmetatable({}, entity)
  self.data = {
    pos = {0, 100, 0},
    color = {255/255, 255/255, 255/255},

    actor = actor,

    race = {
      speed = 0.0,
      accel = 10.0,
    },

    finish = finish
  }
  return self
end

function entity:update(dt)
  if (self.data.pos[1] > self.data.finish[1]) then
    self.data.pos[1] = 0
    self.data.race.speed = 0
    self.data.race.accel = 10.0
  end
  self.data.race.speed = racing.accelerate(dt, 1, self.data.race.speed, self.data.actor.data.max_speed, self.data.race.accel)
  -- self:accel(dt)
  self.data.pos[1] = self.data.pos[1] + self.data.race.speed * dt
end

-- function entity:accel(dt)
--   if (self.data.current_accel <= self.data.actor.data.accel) then
--     self.data.current_accel = self.data.current_accel + dt
--   end
--   if (self.data.current_speed <= self.data.actor.data.max_speed) then
--     self.data.current_speed = self.data.current_speed + self.data.current_accel * dt
--   end
-- end

function entity:draw()
  love.graphics.push()
  love.graphics.setColor(self.data.color[1], self.data.color[2], self.data.color[3])
  love.graphics.points(self.data.pos[1], self.data.pos[2])
  love.graphics.print(self.data.race.speed, self.data.pos[1], self.data.pos[2])
  -- love.graphics.print(string.format("Current Accel : %s", self.data.current_accel), 0, 40)
  love.graphics.pop()
  self.data.actor:draw()
end

return entity
