In Episode 1 we built a basic 3D scene with stackable blocks. This time we take a huge leap forward and implement the core game mechanics by adding animated block movement, placement logic and a simple win/loss system.
This is where it truly starts to feel like a game.
What We Covered
- Introduced a
GameStateenum to manage play flow - Added a moving block that alternates between X and Z axes
- Enabled player input to place the block at the right time
- Implemented stacking logic with trimming and snapping
- Checked for perfect placements and block misses
- Introduced placeholder UI for Start/Game Score/Game Over overlays
Design Insights
The Core Loop
At the heart of Tower Blocks is the challenge of timing your placement. That means we need:
- A block that moves back and forth
- A way to freeze it in place when the player hits space or clicks
- Logic to check how well it aligns with the block below
This episode introduces all of that, laying the groundwork for later polish like animations, lighting and sound.
Alternating Axis = Instant Variety
By alternating between X and Z axis movement we make each block a bit trickier to align. A small detail with a big impact on gameplay feel.
Implementation Highlights
Movement Struct
We defined a Movement struct to encapsulate axis, direction and speed:
typedef struct Movement;
Each moving block gets a direction (FORWARD or BACKWARD) and axis (X or Z), and moves between set bounds.
Placement Logic
When the player places a block:
- If it overlaps enough, we trim or snap it.
- If it completely misses, it’s game over.
bool
Basic UI Overlays
We introduced READY_STATE, PLAYING_STATE and GAME_OVER_STATE and use them to:
- Show a static “START GAME” title
- Show a placeholder game score
- Show “GAME OVER” on failure
- Let the player restart cleanly
What’s Next?
In Episode 3 we will focus on polish:
- Animate game overlays (start game, game over, game score)
- Move camera smoothly instead of snapping to the next position
- Start to build out the feel of the game through motion
This is where the project goes from working to fun.
Project Code
You will find the complete source code here: tower-blocks