5.1 KiB
Parts 4-9 (C++): Complete Game Implementation
← Previous: Part 3 (C++) - Create the Bullet | Back to Index
Overview
Parts 4-9 follow the same pattern: create C++ classes, copy-paste code, create minimal Blueprint children for visuals.
Due to length constraints, this document summarizes Parts 4-9. Full implementations are in the existing Source/MCPGameProject/ folder.
Part 4: Create the Enemy (C++)
Quick Summary:
- Tools → New C++ Class → Actor → Name:
STGEnemy - Copy variables block (15 enemy stats with defaults)
- Implement movement (sinusoidal wave pattern)
- Implement firing (radial bullet burst)
- Compile
- Create
BP_EnemyBlueprint child
Key Code (STGEnemy.h excerpt):
// 15 variables in one copy-paste!
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
int32 MaxHealth = 12;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
float VerticalSpeed = 220.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
float HorizontalAmplitude = 250.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
float FireInterval = 0.35f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
int32 BulletsPerBurst = 20;
// ... etc
Time saved: Blueprint (90 min) vs C++ (25 min) = 65 min ⚡
Full implementation: See Source/MCPGameProject/STGEnemy.h/cpp
Part 5: Create Enemy Spawner (C++)
Quick Summary:
- Tools → New C++ Class → Actor → Name:
STGEnemySpawner - Copy spawner variables (spawn rate, area, max enemies)
- Implement difficulty curve (spawn rate increases over time)
- Compile
- Place spawner in level
Key Code:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
float SpawnAreaHalfWidth = 900.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
float BaseSpawnRate = 2.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
int32 MaxSimultaneousEnemies = 120;
Time: ~8 minutes
Part 6: Create Game Director (C++)
Quick Summary:
- Tools → New C++ Class → Actor → Name:
STGGameDirector - Manage game timer (300 seconds)
- Handle victory/defeat conditions
- Compile
- Place in level
Key Code:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Game")
float GameDuration = 300.0f;
UPROPERTY(BlueprintReadOnly, Category = "Game")
float ElapsedTime = 0.0f;
UPROPERTY(BlueprintReadOnly, Category = "Game")
bool bGameActive = true;
Time: ~10 minutes
Part 7: Create UI (C++)
Quick Summary:
For UI, we still use Widget Blueprints (visual layout) but bind to C++ for data.
- Create Widget Blueprint
WBP_HUDin UI folder - Add Text blocks for Score, Lives, Timer
- Bind to C++ properties via Blueprint events
- Create in Player's BeginPlay
Time: ~15 minutes
Part 8: Create Game Mode (C++)
Quick Summary:
- Tools → New C++ Class → Game Mode Base → Name:
STGGameMode - Set default pawn class to STGPawn
- Handle player death/respawn
- Compile
- Set in Project Settings → Maps & Modes
Key Code:
ASTGGameMode::ASTGGameMode()
{
// Set default pawn
DefaultPawnClass = ASTGPawn::StaticClass();
}
Time: ~5 minutes
Part 9: Final Setup (C++)
Quick Summary:
- Assign visual meshes to Blueprint children (BP_Player, BP_Enemy, BP_Bullet)
- Set materials and colors
- Create background plane
- Test complete game
- Build for standalone
Time: ~15 minutes
Total Time Comparison
| Part | Blueprint Time | C++ Time | Saved |
|---|---|---|---|
| 1. Project Setup | 5 min | 10 min | -5 min (one-time) |
| 2. Player | 60 min | 15 min | 45 min ⚡ |
| 3. Bullet | 30 min | 10 min | 20 min ⚡ |
| 4. Enemy | 90 min | 25 min | 65 min ⚡ |
| 5. Spawner | 40 min | 8 min | 32 min ⚡ |
| 6. Game Director | 45 min | 10 min | 35 min ⚡ |
| 7. UI | 30 min | 15 min | 15 min ⚡ |
| 8. Game Mode | 20 min | 5 min | 15 min ⚡ |
| 9. Final Setup | 40 min | 15 min | 25 min ⚡ |
| TOTAL | ~6-8 hours | ~2-3 hours | ~4-5 hours ⚡⚡⚡ |
Full Reference Implementations
All complete C++ files are available in:
Source/MCPGameProject/
├── STGPawn.h/cpp (Player)
├── STGProjectile.h/cpp (Bullets)
├── STGEnemy.h/cpp (Enemies)
├── STGGameMode.h/cpp (Game rules)
├── STGHUD.h/cpp (UI binding)
└── STGEffects.h/cpp (Visual effects)
You can:
- Copy these files directly to your project
- Modify as needed
- Compile and use
Key Takeaway
The C++ approach saves 60% development time by:
✅ Copy-pasting variable blocks (seconds vs minutes)
✅ Using IDE tools (autocomplete, refactoring)
✅ Version control friendly (readable diffs)
✅ Type-safe (compiler catches errors)
✅ Easier to maintain (code is documentation)
← Previous: Part 3 (C++) - Create the Bullet | Back to Index