Skip to content

Player HUD

Ayooluwa Fadeyibi edited this page Oct 18, 2026 · 16 revisions

Player HUD

Introduction

The Player HUD handles all components and features visually displayed on the game screen relating to the player. It gives the player constant feedback on their health, equipment, resources and level context without interrupting gameplay.

This page is the overview. Each substantial component has its own page with the same layout: purpose, class diagram, lifecycle, public methods, tuning constants, tests and a link back here.

Shared Design Ideas

  • Screen-space overlay. Every HUD element is a UIComponent that adds actors to the UI Stage, drawn independently of the world camera, so it stays fixed while the level scrolls.
  • Event-driven updates. Components do not poll game state. They listen for events fired on the player entity (updateHealth, inventoryChanged, inventorySelectionChanged, goldChanged, itemDictionaryChanged, itemPurchased, ...) and update when one arrives. The arrow wheel is the exception: it polls its state in draw() because it only exists while Tab is held.
  • One visual style. Hotbar slots, the backpack, the item dictionary and the arrow wheel share the dark teal box with a brown selected border (see the Graphics UI Style Guide).
  • Data and UI are separate. Each display reads a data component (CombatStatsComponent, InventoryComponent, ItemDictionaryComponent, ShopComponent, ArrowWheelComponent) and holds no game state of its own.

Components

Component Summary Page
Health Row of hearts, top-left, that flicker out as health is lost and grow with max health Player HUD: Health
Hotbar Bottom-edge row of inventory slots with a highlighted selection Player HUD: Hotbar
Arrow Wheel Pie menu opened by holding Tab to choose the arrow type Player HUD: Arrow Wheel
Item Dictionary Full-screen overlay (I) of every item, discovered on pickup Player HUD: Item Dictionary
Shop Pausing overlay (F at a shopkeeper) for buying arrows and potions Player HUD: Shop
Gold, Game Icon Short enough to stay on this page below

HUD health bar HUD hotbar Arrow wheel Item dictionary grid Shop overlay

Game Currency

The player's gold is shown in the HUD directly below the hearts, as a number followed by a gold coin icon (images/items/gold_coin.png, drawn 40x40px). It is built by PlayerStatsDisplay in the same root Table as the health row.

  • Gold is stored on InventoryComponent (getGold(), hasGold(int), addGold(int)). addGold clamps the result to [0, Integer.MAX_VALUE], so gold can never go negative.
  • The player starts with the gold value from configs/player.json (currently 50), passed to new InventoryComponent(stats.gold) in PlayerFactory.
  • PlayerStatsDisplay listens for the goldChanged event on the player and rewrites the label text, so the counter updates the moment gold is picked up or spent. The label is only created if the player has an InventoryComponent.
  • Gold is earned by pressing F near a gold pickup (PlayerInteractionComponent.pickupGold), which adds the pickup's amount and fires goldPickedUp. It is spent in the shop.

Gold counter and health bar in the HUD

Game Icon

The game window is titled Odysseus and uses a custom icon, set in DesktopLauncher:

  • Lwjgl3ApplicationConfiguration.setWindowIcon is given three sizes (desktop_icon_256.png, _64.png, _32.png in assets/images/ui/) so the OS can pick the best fit for the title bar, taskbar and alt-tab.
  • GLFW ignores window icons on macOS, so MacDockIcon.set("images/ui/desktop_icon_256.png") sets the Dock icon through Cocoa once the game has started (called from create() after super.create()).

Game icon in the macOS Dock

Relevant Development Links

Clone this wiki locally