Learn Python in 30 Days — Day 29 – Final Project Build (Part 2): Movement, Encounters & Combat
Day 29 – Final Project Build (Part 2): Movement, Encounters & Combat
Yesterday, in Day 28, you built the world generators that produced the data:
- world.json
- villages.json
creatures.json
Today, RetroRealm stops being data and becomes a game.
By the end of this post you will have:
- A fully modular project folder
- A working player class
- Movement that respects true blocking tiles (mountains/rivers = impassable, always)
- Region-to-region transitions
- Random encounters based on danger level
- A working turn-based combat engine
Project Structure
The project structure should look like this:
Today we fill in:
- player.py
- world_data.py
- map_engine.py
- combat.py
main.py
Day 30 will fill in:
- NPCs
- Villages
- Shops
- Saving & Loading
Creating the Player Class
Before we can move, fight, or gain XP, we need an actual player character.
Inside your retrorealm/ folder, create a new file called player.py and add the following code:
This class is used everywhere: movement, combat, shops, villages, saving/loading.
Loading Game Data
world_data.py and add the following code:
Movement & Map Logic (NEW FILE)
Next create the file map_engine.py this will enforce blocking terrain and safe region transitions so that:
- You cannot enter mountain, river, or water tiles
- You can’t “slip” off the edge of the map into negative coordinates
- Region-to-region travel only happens via defined
exits
Helper Functions
Movement Description
To make the game interactive we want to display
information about the players location.
Strict Tile Blocking
We need to make sure the following tiles are always impassable:
"mountain""river""water"(for lakes, rivers, seas, etc.)
Even if the generator accidentally gives them movement directions, the map engine overrides that.
Add this helper function to map_engine.py:
World Movement
The movement handler checks for all the following conditions:
- Respects each tile’s
directions(north/south/east/west) - Handles region edge transitions via
exits - Checks the destination tile before committing movement
- Never lets you walk into water/mountain/river or off the map
- Only north, south, east, west are valid directions.
We’ll accept single-letter
commands: n, s, e, w.
With this the player should never be able to step onto mountain/river/water tiles, and only cross map edges where exits are defined.
Encounter System
In this file we are going to handle the random appearance of a creature based upon the danger level of the tile.
Combat Engine
Utility Helpers
Main Game Loop
What You’ve Built on Day 29
In this post we have used alot of the different things we have learnt over the past 29 days and completed a large amount of the games behaviours:
- Split the engine into modular Python files
- Created a player system with stats and inventory
- Implemented movement with strict blocking rules
- Ensured mountains and rivers are completely impassable
- Added region edge transitions
- Added a danger-based random encounter system
- Built a working turn-based combat loop
Whilst RetroRealm is not completely finished, it is now a playable text exploration RPG.
You can download ALL DAY 29 FILES
Next up (Day 30): – Final Project Build (Part 2)
In the final day of the series we will undertake the remaining parts to build the game:
🎒 Enter and explore villages
🗣 Talk to NPCs
🛒 Use shops
🧪 Improve combat with spells, items & levelling
💾 Add saving & loading
🏁 Final polish & completion of the series
All example files for this series are available on my GitHub: Learn-Python-in-30-Days
You can see the full series here Learn Python in 30 Days series!
You can see the full series here Learn Python in 30 Days series!

Comments
Post a Comment