'use strict'; // === HUD RENDERING === function renderHUD() { // Hearts const totalHearts = Math.ceil(gameState.player.maxHp / 2); const fullHearts = Math.floor(gameState.player.hp / 2); const halfHeart = gameState.player.hp % 2 === 1; for (let i = 0; i < totalHearts; i++) { const hx = 12 + i * 22; const hy = 12; drawHeart(ctx, hx, hy, 14, i < fullHearts); if (i === fullHearts && halfHeart) { ctx.save(); ctx.beginPath(); ctx.rect(hx - 7, hy - 7, 14, 14); ctx.clip(); drawHeart(ctx, hx, hy, 14, true); ctx.restore(); } } // Active weapon icon if (gameState.player.activeWeapon) { drawWeaponIcon(ctx, gameState.player.activeWeapon, CANVAS_W - 24, 14); } // Ammo counts if (gameState.player.arrows > 0) { ctx.fillStyle = '#8B4513'; ctx.fillRect(CANVAS_W - 50, 10, 2, 12); ctx.fillStyle = '#808080'; ctx.fillRect(CANVAS_W - 52, 10, 6, 3); ctx.fillStyle = '#FFFFFF'; ctx.font = '9px monospace'; ctx.textAlign = 'right'; ctx.fillText(gameState.player.arrows, CANVAS_W - 54, 22); ctx.textAlign = 'left'; } if (gameState.player.bombs > 0) { ctx.fillStyle = '#333'; ctx.beginPath(); ctx.arc(CANVAS_W - 38, 14, 3, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#FFFFFF'; ctx.font = '9px monospace'; ctx.textAlign = 'right'; ctx.fillText(gameState.player.bombs, CANVAS_W - 42, 22); ctx.textAlign = 'left'; } if (gameState.player.keys > 0) { ctx.fillStyle = '#FFD700'; ctx.beginPath(); ctx.arc(CANVAS_W - 30, 30, 3, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#FFFFFF'; ctx.font = '9px monospace'; ctx.textAlign = 'right'; ctx.fillText(gameState.player.keys, CANVAS_W - 34, 38); ctx.textAlign = 'left'; } // Weapon inventory (bottom right) if (gameState.player.weapons.length > 1) { let wx = CANVAS_W - 16; for (let i = gameState.player.weapons.length - 1; i >= 0; i--) { const w = gameState.player.weapons[i]; const isActive = w === gameState.player.activeWeapon; ctx.fillStyle = isActive ? '#FFD700' : '#555'; ctx.fillRect(wx - 10, CANVAS_H - 20, 12, 16); ctx.strokeStyle = isActive ? '#FFD700' : '#333'; ctx.lineWidth = isActive ? 1.5 : 0.5; ctx.strokeRect(wx - 10, CANVAS_H - 20, 12, 16); drawWeaponIcon(ctx, w, wx - 4, CANVAS_H - 12); wx -= 14; } } // Room name / dungeon info const dungeon = DUNGEONS[gameState.currentDungeon]; if (dungeon) { ctx.fillStyle = '#CCCCCC'; ctx.font = '12px monospace'; ctx.textAlign = 'center'; ctx.fillText(`${dungeon.name} - Room ${gameState.currentRoomIdx + 1}/${gameState.dungeonRooms ? gameState.dungeonRooms.length : '?'}`, CANVAS_W / 2, CANVAS_H - 8); ctx.textAlign = 'left'; } // Controls hint (fades out) if (gameState.messageTimer <= 0 && gameState.currentRoomIdx === 0) { ctx.fillStyle = 'rgba(0,0,0,0.5)'; ctx.fillRect(CANVAS_W / 2 - 100, CANVAS_H - 28, 200, 18); ctx.fillStyle = '#888'; ctx.font = '10px monospace'; ctx.textAlign = 'center'; ctx.fillText('Arrows/WASD: Move Space: Attack E: Interact X: Switch', CANVAS_W / 2, CANVAS_H - 15); ctx.textAlign = 'left'; } } if (typeof module !== 'undefined' && module.exports) { module.exports = { renderHUD }; }