oma-lander/game/hud.lua
2026-04-18 23:20:40 +01:00

59 lines
2.1 KiB
Lua

local World = require("game.world")
local Palette = require("rendering.palette")
local Fonts = require("rendering.fonts")
local HUD = {}
function HUD.draw(altitude, hspeed, vspeed)
local p = Palette.get()
local sw, sh = World.screenW, World.screenH
local pad = 12
love.graphics.setFont(Fonts.small)
-- Left column: SCORE, TIME, FUEL
love.graphics.setColor(p.hud)
love.graphics.print("SCORE " .. string.format("%d", World.score), pad, pad)
love.graphics.print("TIME " .. string.format("%.0f", World.time), pad, pad + Fonts.small:getHeight() + 4)
-- Fuel bar
local fuelY = pad + (Fonts.small:getHeight() + 4) * 2
local fuelMax = 750
local fuelFrac = math.max(0, World.fuel / fuelMax)
local barW = sw * 0.15
local barH = Fonts.small:getHeight() * 0.7
love.graphics.print("FUEL", pad, fuelY)
local barX = pad + Fonts.small:getWidth("FUEL") + 8
love.graphics.setColor(p.dim)
love.graphics.rectangle("line", barX, fuelY + 2, barW, barH)
if World.fuel < 150 and math.floor(love.timer.getTime() * 4) % 2 == 0 then
love.graphics.setColor(p.warning)
else
love.graphics.setColor(p.pad)
end
love.graphics.rectangle("fill", barX + 1, fuelY + 3, (barW - 2) * fuelFrac, barH - 2)
love.graphics.setColor(p.hud)
love.graphics.print(string.format("%.0f", World.fuel), barX + barW + 8, fuelY)
-- Right column: ALTITUDE, HORIZONTAL SPEED, VERTICAL SPEED
local rx = sw - pad
local function rightPrint(text, y)
local w = Fonts.small:getWidth(text)
love.graphics.print(text, rx - w, y)
end
love.graphics.setColor(p.hud)
rightPrint(string.format("ALTITUDE %.0f", altitude), pad)
local hdir = hspeed > 0.5 and " >" or (hspeed < -0.5 and "< " or " ")
rightPrint(string.format("HORIZ SPEED %s%.1f", hdir, math.abs(hspeed)), pad + Fonts.small:getHeight() + 4)
local vdir = vspeed > 0.5 and " v" or (vspeed < -0.5 and " ^" or " ")
rightPrint(string.format("VERT SPEED %s%.1f", vdir, math.abs(vspeed)), pad + (Fonts.small:getHeight() + 4) * 2)
end
return HUD