From 70b6d2a335a40ae60e990cc5f37b828ed9dbf526 Mon Sep 17 00:00:00 2001 From: cursed22bc Date: Tue, 10 Mar 2026 21:26:24 +0200 Subject: pickups --- hud.lua | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'hud.lua') diff --git a/hud.lua b/hud.lua index ce877bb..ddb65fb 100644 --- a/hud.lua +++ b/hud.lua @@ -4,15 +4,14 @@ local HUD = {} HUD.__index = HUD HUD.slots = { - { enabled = false }, - { enabled = false }, + { enabled = false, object = "key", name = "Key" }, + { enabled = false, object = "dbljump", name = "Double Jump" }, { enabled = false }, { enabled = false }, } local SLOT_SIZE = 16 local SLOT_SPACING = 8 -local LOREM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." local function createMissingTexture() local size = SLOT_SIZE @@ -42,6 +41,18 @@ function HUD:new() self.screenW = 0 self.screenH = 0 self.drawScale = 1 + self.player = nil + + for _, slot in ipairs(HUD.slots) do + if slot.object == "key" then + slot.image = love.graphics.newImage("assets/misc/key.png") + slot.image:setFilter("nearest", "nearest") + elseif slot.object == "dbljump" then + slot.image = love.graphics.newImage("assets/misc/dbljump.png") + slot.image:setFilter("nearest", "nearest") + end + end + return self end @@ -64,12 +75,21 @@ function HUD:computeSlotRects(screenW, screenH, drawScale) return rects end -function HUD:update(dt, screenW, screenH, drawScale) +function HUD:update(dt, screenW, screenH, drawScale, player) self.screenW = screenW self.screenH = screenH self.drawScale = drawScale + self.player = player self.slotRects = self:computeSlotRects(screenW, screenH, drawScale) + if player and player.pickups then + for _, slot in ipairs(HUD.slots) do + if slot.object then + slot.enabled = (player.pickups[slot.object] or 0) > 0 + end + end + end + local mx, my = love.mouse.getPosition() local prevHovered = self.hoveredSlot self.hoveredSlot = nil @@ -82,10 +102,19 @@ function HUD:update(dt, screenW, screenH, drawScale) end if self.hoveredSlot and self.hoveredSlot ~= prevHovered then + local slot = HUD.slots[self.hoveredSlot] + local text = "Planned feature that didn't make it into the game ;(" + if slot.name then + local count = 0 + if player and player.pickups and slot.object then + count = player.pickups[slot.object] or 0 + end + text = slot.name .. " x" .. count + end local rect = self.slotRects[self.hoveredSlot] local centerX = screenW / 2 local topY = rect.y + rect.h + 8 * drawScale - self.textbox:show(LOREM, { centerX, topY, "center" }, "show", { + self.textbox:show(text, { centerX, topY, "center" }, "show", { fontSize = 16, centeredText = true, wrapToFit = true, @@ -104,7 +133,7 @@ function HUD:mousepressed(mx, my, button) for i, rect in ipairs(self.slotRects) do if mx >= rect.x and mx < rect.x + rect.w and my >= rect.y and my < rect.y + rect.h then - HUD.slots[i].enabled = not HUD.slots[i].enabled + --HUD.slots[i].enabled = not HUD.slots[i].enabled break end end @@ -119,10 +148,17 @@ function HUD:draw() love.graphics.rectangle("fill", 0, 0, screenW, screenH) for i, rect in ipairs(self.slotRects) do - love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw(self.missingTexture, rect.x, rect.y, 0, drawScale, drawScale) + local slot = HUD.slots[i] + local img = slot.image or self.missingTexture + + if slot.enabled then + love.graphics.setColor(1, 1, 1, 1) + else + love.graphics.setColor(1, 1, 1, 0.25) + end + love.graphics.draw(img, rect.x, rect.y, 0, drawScale, drawScale) - if HUD.slots[i].enabled then + if slot.enabled then love.graphics.setColor(0, 1, 0, 0.3) love.graphics.rectangle("fill", rect.x, rect.y, rect.w, rect.h) end -- cgit v1.2.3