mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
203 lines
5.8 KiB
Markdown
203 lines
5.8 KiB
Markdown
|
|
# Health UI Display - What Changed
|
||
|
|
|
||
|
|
## Before ❌
|
||
|
|
|
||
|
|
```
|
||
|
|
Problem: Health UI not visible
|
||
|
|
- Emoji hearts (❤️ 💔 🖤)
|
||
|
|
- Inline CSS styles (position: fixed; z-index: 100)
|
||
|
|
- Z-index too low (100 < inventory's 1000)
|
||
|
|
- Never appears on screen
|
||
|
|
```
|
||
|
|
|
||
|
|
## After ✅
|
||
|
|
|
||
|
|
```
|
||
|
|
Solution: Health UI now displays properly
|
||
|
|
- PNG icon hearts (assets/icons/heart.png)
|
||
|
|
- Proper CSS file (css/health-ui.css)
|
||
|
|
- Z-index: 1100 (above inventory)
|
||
|
|
- Appears above inventory when damaged
|
||
|
|
```
|
||
|
|
|
||
|
|
## Visual Layout
|
||
|
|
|
||
|
|
```
|
||
|
|
┌──────────────────────────────────────────────────────────┐
|
||
|
|
│ │
|
||
|
|
│ ❤️ ❤️ ❤️ ❤️ 💔 │
|
||
|
|
│ (Health UI - NEW z-index: 1100) │
|
||
|
|
│ │
|
||
|
|
│ ┌────────────────────────────────────────────────────┐ │
|
||
|
|
│ │ │ │
|
||
|
|
│ │ [Game World] │ │
|
||
|
|
│ │ Player running around │ │
|
||
|
|
│ │ │ │
|
||
|
|
│ │ │[I] │
|
||
|
|
│ │ │[n] │
|
||
|
|
│ │ │[v] │
|
||
|
|
│ │ │[e] │
|
||
|
|
│ └────────────────────────────────────────────────────┘ │
|
||
|
|
│ Inventory UI (z-index: 1000) │
|
||
|
|
│ │
|
||
|
|
└──────────────────────────────────────────────┘
|
||
|
|
```
|
||
|
|
|
||
|
|
## Code Changes Summary
|
||
|
|
|
||
|
|
### Change 1: Image-Based Hearts
|
||
|
|
|
||
|
|
**Before:**
|
||
|
|
```javascript
|
||
|
|
const heart = document.createElement('div');
|
||
|
|
heart.textContent = '❤️'; // Emoji
|
||
|
|
```
|
||
|
|
|
||
|
|
**After:**
|
||
|
|
```javascript
|
||
|
|
const heart = document.createElement('img');
|
||
|
|
heart.src = 'assets/icons/heart.png'; // PNG icon
|
||
|
|
```
|
||
|
|
|
||
|
|
### Change 2: Proper CSS Styling
|
||
|
|
|
||
|
|
**Before:**
|
||
|
|
```javascript
|
||
|
|
this.container.style.cssText = `
|
||
|
|
z-index: 100; // TOO LOW
|
||
|
|
display: none;
|
||
|
|
`;
|
||
|
|
```
|
||
|
|
|
||
|
|
**After:**
|
||
|
|
```css
|
||
|
|
#health-ui-container {
|
||
|
|
z-index: 1100; /* ABOVE inventory (z-index: 1000) */
|
||
|
|
display: flex;
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
### Change 3: CSS File Created
|
||
|
|
|
||
|
|
**New file:** `css/health-ui.css`
|
||
|
|
```css
|
||
|
|
z-index: 1100; /* Key fix */
|
||
|
|
pointer-events: none; /* Don't block clicks */
|
||
|
|
background: rgba(0, 0, 0, 0.8); /* Dark background */
|
||
|
|
border: 2px solid #333; /* Pixel-art style */
|
||
|
|
image-rendering: pixelated; /* Crisp icons */
|
||
|
|
```
|
||
|
|
|
||
|
|
## Heart Display Examples
|
||
|
|
|
||
|
|
### Full Health (Hidden)
|
||
|
|
```
|
||
|
|
Status: No damage taken
|
||
|
|
Display: [HIDDEN]
|
||
|
|
Console: (health-ui not showing)
|
||
|
|
```
|
||
|
|
|
||
|
|
### Partially Damaged
|
||
|
|
```
|
||
|
|
Player HP: 60 / 100 (3/5 hearts)
|
||
|
|
Display: ❤️ ❤️ ❤️ 🖤 🖤
|
||
|
|
Status: UI visible above inventory
|
||
|
|
```
|
||
|
|
|
||
|
|
### Half Damage
|
||
|
|
```
|
||
|
|
Player HP: 50 / 100 (2.5/5 hearts)
|
||
|
|
Display: ❤️ ❤️ 💔 🖤 🖤
|
||
|
|
Status: UI visible above inventory
|
||
|
|
```
|
||
|
|
|
||
|
|
### Nearly Dead
|
||
|
|
```
|
||
|
|
Player HP: 10 / 100 (0.5/5 hearts)
|
||
|
|
Display: 💔 🖤 🖤 🖤 🖤
|
||
|
|
Status: UI visible above inventory
|
||
|
|
```
|
||
|
|
|
||
|
|
## Z-Index Hierarchy
|
||
|
|
|
||
|
|
```
|
||
|
|
2000 ┌─────────────────────────┐
|
||
|
|
│ Minigames (laptop) │
|
||
|
|
│ person-chat, phone │
|
||
|
|
1100 ├─────────────────────────┤
|
||
|
|
│ Health UI ← NEW! │
|
||
|
|
1000 ├─────────────────────────┤
|
||
|
|
│ Inventory UI │
|
||
|
|
│ Notifications │
|
||
|
|
100 ├─────────────────────────┤
|
||
|
|
│ Other elements │
|
||
|
|
0 └─────────────────────────┘
|
||
|
|
```
|
||
|
|
|
||
|
|
## Asset Files
|
||
|
|
|
||
|
|
```
|
||
|
|
assets/icons/
|
||
|
|
├── heart.png ← Full heart (used for full AND empty with opacity)
|
||
|
|
├── heart-half.png ← Half heart (for remainder)
|
||
|
|
└── (other icons)
|
||
|
|
```
|
||
|
|
|
||
|
|
## Files Changed
|
||
|
|
|
||
|
|
✏️ **js/ui/health-ui.js** - Updated to use PNG icons
|
||
|
|
🆕 **css/health-ui.css** - New CSS file with proper styling
|
||
|
|
📝 **index.html** - Added CSS link
|
||
|
|
|
||
|
|
## Event Flow
|
||
|
|
|
||
|
|
```
|
||
|
|
Combat happens
|
||
|
|
↓
|
||
|
|
Player takes damage
|
||
|
|
↓
|
||
|
|
combatSystem emits: CombatEvents.PLAYER_HP_CHANGED
|
||
|
|
↓
|
||
|
|
HealthUI.updateHP() called
|
||
|
|
↓
|
||
|
|
Health UI shows (if hp < maxHP)
|
||
|
|
↓
|
||
|
|
Hearts update: ❤️ ❤️ 💔 🖤 🖤
|
||
|
|
↓
|
||
|
|
Health UI displays above inventory ✅
|
||
|
|
```
|
||
|
|
|
||
|
|
## Testing Checklist
|
||
|
|
|
||
|
|
- [ ] Load index.html in browser
|
||
|
|
- [ ] Take damage (get hit by hostile NPC)
|
||
|
|
- [ ] Health UI appears above inventory
|
||
|
|
- [ ] Hearts update correctly (full/half/empty)
|
||
|
|
- [ ] UI hides when health restored to full
|
||
|
|
- [ ] Icons are crisp and pixelated
|
||
|
|
- [ ] No console errors
|
||
|
|
|
||
|
|
## Quick Reference
|
||
|
|
|
||
|
|
| Element | Value |
|
||
|
|
|---------|-------|
|
||
|
|
| Z-Index | 1100 |
|
||
|
|
| Position | Top center, 60px from top |
|
||
|
|
| Positioning | Fixed (always visible when shown) |
|
||
|
|
| Full Heart Icon | assets/icons/heart.png |
|
||
|
|
| Half Heart Icon | assets/icons/heart-half.png |
|
||
|
|
| Empty Heart | heart.png at 0.2 opacity |
|
||
|
|
| Max Hearts | 5 (configurable via COMBAT_CONFIG.ui.maxHearts) |
|
||
|
|
| Max HP | 100 (20 HP per heart) |
|
||
|
|
|
||
|
|
## Pixel-Art Style
|
||
|
|
|
||
|
|
All images use:
|
||
|
|
```css
|
||
|
|
image-rendering: pixelated; /* Standard */
|
||
|
|
image-rendering: -moz-crisp-edges; /* Firefox */
|
||
|
|
image-rendering: crisp-edges; /* Chrome/Safari */
|
||
|
|
```
|
||
|
|
|
||
|
|
This ensures icons look crisp even when scaled, maintaining the pixel-art aesthetic.
|