mirror of
https://github.com/kuhyx/praca_magisterska.git
synced 2026-07-04 15:43:14 +02:00
5.0 KiB
5.0 KiB
Part 7: Create Score Manager / UI
← Previous: Part 6 - Game Director | Back to Index | Next: Part 8 - Game Mode and Level →
Step 7.1: Create UI Widget Blueprint
- Content Browser → UI folder
- Right-click → User Interface → Widget Blueprint
- Name:
WBP_HUD - Double-click to open Widget Designer
Expected Result
Widget Designer opens with:
- Hierarchy panel on left
- Canvas preview in center
- Details panel on right
Step 7.2: Design HUD Layout
1. In the Palette panel (left side), search for "Canvas Panel"
- Drag Canvas Panel to the Hierarchy (if not already there)
2. Add Score Text
- In Palette, search for "Text"
- Drag "Text" widget onto Canvas Panel in hierarchy
- Rename it
ScoreText(right-click → Rename) - In Details panel:
- Under "Slot (Canvas Panel Slot)":
- Anchors: Top-Left (click dropdown, select corner)
- Position X:
20 - Position Y:
20 - Size X:
300 - Size Y:
40
- Under "Appearance":
- Text:
Score: 0 - Font Size:
24 - Color: White
- Text:
- Under "Slot (Canvas Panel Slot)":
3. Add Lives Text
- Drag another "Text" widget
- Rename to
LivesText - Position X:
20, Y:60 - Text:
Lives: 3 - Same font settings as Score
4. Add Timer Text
- Drag another "Text" widget
- Rename to
TimerText - Position X:
20, Y:100 - Text:
Time: 05:00 - Same font settings
5. Click "Compile" and "Save" (top buttons)
Expected Result
Preview shows:
┌────────────────────────────────────┐
│ Score: 0 │
│ Lives: 3 │
│ Time: 05:00 │
│ │
│ │
└────────────────────────────────────┘
Step 7.3: Create Score Manager Blueprint
-
Content Browser → Blueprints
-
Right-click → Blueprint Class → Actor
-
Name:
BP_ScoreManager -
Double-click to open
-
Create Variables:
| Variable Name | Type | Default Value |
|---|---|---|
Score |
Integer | 0 |
CurrentLives |
Integer | 3 |
HUDWidget |
Object Reference to WBP_HUD | - |
HUDWidgetClass |
Class Reference | (set to WBP_HUD) |
Expected Result after Compile
- Compile button shows GREEN checkmark
- Variables panel shows all 4 variables with correct types
Step 7.4: Score Manager Initialization
1. From Event BeginPlay
a) Create HUD Widget
- Right-click →
Create Widget - Class: Select WBP_HUD (or use HUDWidgetClass variable)
- Owning Player: Get Player Controller (index 0)
b) Store widget reference
- Set HUDWidget to the created widget
c) Add to viewport
- Right-click →
Add to Viewport - Connect widget reference as target
Expected Result after Compile
- Compile button shows GREEN checkmark
- BeginPlay event connected to Create Widget → Add to Viewport
Expected Result in Play mode
- HUD appears immediately when game starts
- HUD displays in top-left corner of screen
- Text is visible and readable (white on game background)
Step 7.5: Score Manager Functions
1. CREATE "RegisterGameStart" FUNCTION
Inputs:
InitialLives(Integer)Duration(Float)
Inside:
- Set Score = 0
- Set CurrentLives = InitialLives
- Update all UI labels
2. CREATE "AddScore" FUNCTION
Input: Amount (Integer)
Inside:
- Add Amount to Score
- Update Score label in HUD:
- Get HUDWidget
- Cast to WBP_HUD
- Get "ScoreText" widget
- Set Text to "Score: " + Score
3. CREATE "SetLives" FUNCTION
Input: Lives (Integer)
Inside:
- Set CurrentLives = Lives
- Update Lives label in HUD
4. CREATE "UpdateTimer" FUNCTION
Input: TimeRemaining (Float)
Inside:
-
Convert to minutes:seconds format:
Minutes = Floor(TimeRemaining / 60) Seconds = Floor(TimeRemaining mod 60) -
Format string: "Time: MM:SS"
-
Update Timer label
5. CREATE "HandleGameOver" FUNCTION
Inside:
- Set Timer text to "Game Over"
6. CREATE "HandleGameClear" FUNCTION
Inside:
- Set Timer text to "Mission Complete"
Expected Result after Compile
- Compile button shows GREEN checkmark
- All 6 functions appear under Functions panel
Expected Result in Play mode
- Score updates instantly when enemies are killed (+50 each)
- Lives display updates when player is hit
- Timer counts down in MM:SS format
- "Game Over" or "Mission Complete" replaces timer at game end
← Previous: Part 6 - Game Director | Back to Index | Next: Part 8 - Game Mode and Level →