local Entity = require "scenes.levels.entities.parent"

local Ennemy = Entity:extend()

function Ennemy:new(level, x, y, w, h, hp, power, armor)
  local w = w or 16
  local h = h or 16
  Ennemy.super.new(self, level, "ennemy", x, y, w, h)
  self.power = power or 1
  self.armor = armor or 0
  self.maxhp = hp    or 3
  self.hp    = self.maxhp
end

function Ennemy:update(dt)

end

function Ennemy:draw()
  love.graphics.setColor(1, 0, 0, 1)
  utils.graphics.box(self.x, self.y, self.w, self.h)
  love.graphics.setColor(0, 0, 0, 1)
  love.graphics.rectangle("fill", self.x, self.y - 6, self.w, 2)
  love.graphics.setColor(1, 0, 0, 1)
  local barwidth = math.floor((self.hp / self.maxhp) * self.w)
  love.graphics.rectangle("fill", self.x, self.y - 6, barwidth, 2)
  utils.graphics.resetColor()
end

function Ennemy:getDamage(base_damage)
  local damage = math.max(base_damage - self.armor, 1)
  self.hp = math.max(0, self.hp - damage)
  self.obj.Numbers(self.level, self.x+8, self.y+8, damage, {1,0,0})
  if (self.hp == 0) then
    self:destroy()
    self.obj.GFX(self.level, self.x+8, self.y+8, "poof", 1)
    self.level.playermanager.score  = self.level.playermanager.score  + 100
  end
end

return Ennemy
