-- HUD: handler for ingame hud HUD = {} HUD.__index = HUD function HUD:new(assetLoader, players) self = setmetatable({}, HUD) self.assetLoader = assetLoader self.players = players self.y = Config.ROOM_H - 2 self.h = Config.SCREEN_H - Config.ROOM_H + 2 self.playerIconSprites = {} self.playerSkillData = {} return self end function HUD:update(dt) end function HUD:draw() self:drawBackground() for i, player in ipairs(self.players) do self:drawPlayerHUD(i, 8 + ((i - 1) * 72), self.y) end end function HUD:getIconSprite(image) if not image then return nil end local sprite = Sprite:new(image, { size = { image:getWidth(), image:getHeight() }, animations = { default = { 1 } } }) sprite:setAnimation("default") return sprite end function HUD:drawBackground() love.graphics.setColor(0.15, 0.15, 0.2, 1) love.graphics.rectangle("fill", 0, self.y, Config.SCREEN_W, self.h) love.graphics.setColor(0.4, 0.4, 0.5, 1) love.graphics.line(0, self.y, Config.SCREEN_W, self.y) love.graphics.setColor(1, 1, 1, 1) end function HUD:drawSkill(asset, x, y, remainingCooldown, totalCooldown) local image = asset and (asset.icon or asset.drop) local width = (image and image:getWidth()) or 16 local height = (image and image:getHeight()) or 16 love.graphics.setColor(.24, .24, .34, 1) love.graphics.rectangle("fill", x - 1, y - 1, width + 2, height + 2, 2, 2) love.graphics.setColor(.21, .21, .30, 1) love.graphics.rectangle("fill", x, y, width, height, 2, 2) love.graphics.setColor(1, 1, 1, 1) if image then local alpha = 1 if totalCooldown and totalCooldown > 0 and remainingCooldown and remainingCooldown > 0 then alpha = 0.3 + 0.7 * (1 - remainingCooldown / totalCooldown) love.graphics.setColor(alpha, alpha, alpha, 1) love.graphics.draw(image, x, y) love.graphics.setColor(1, 1, 1, 1) local count = math.ceil(remainingCooldown) if count > 0 then Utils.printWithShadow(tostring(count), x + 4, y + 3) end else love.graphics.draw(image, x, y) end end end function HUD:drawPlayerHUD(playerIndex, x, y) local combatant = self.players[playerIndex] -- player color love.graphics.setColor(Config.PLAYER_COLORS[playerIndex][1], Config.PLAYER_COLORS[playerIndex][2], Config.PLAYER_COLORS[playerIndex][3], 1) love.graphics.circle("fill", x + 4, y + 6, 3, 8) love.graphics.setColor(1, 1, 1, 1) -- hp Utils.printWithShadow(tostring(combatant.health or 1) .. "/" .. tostring(combatant.maxHealth), x + 14, y + 2) -- charge skill local chargeAsset = combatant.skillAssets[PlayerSkillSlot.CHARGE] local chargeTotalCooldown = chargeAsset.config.cooldown or 1.0 local chargeRemainingCooldown = combatant.skillCooldowns[chargeAsset.name] self:drawSkill(chargeAsset, x + 4, y + 15, chargeRemainingCooldown, chargeTotalCooldown) -- weapon self:drawSkill(combatant.weapon, x, y + 11) -- defensive skill local defensiveAsset = combatant.skillAssets[PlayerSkillSlot.DEFENSIVE] local defensiveTotalCooldown = defensiveAsset.config.cooldown or 1.0 local defensiveRemainingCooldown = combatant.skillCooldowns[defensiveAsset.name] self:drawSkill(defensiveAsset, x + 24, y + 15, defensiveRemainingCooldown, defensiveTotalCooldown) -- item self:drawSkill(combatant.skillAssets[PlayerSkillSlot.CONSUMABLE], x + 44, y + 15) end