Building an RPG Engine from Scratch
Over the past few months, I've been working on something that's been on my bucket list for years: a traditional turn-based RPG engine. Not just a simple battle system, but a complete framework with party management, dialogue, inventory, shops, and all the systems you'd expect from a classic RPG.
Why GameMaker Studio 2?
While many developers reach for Unity or Godot for RPG projects, I chose GameMaker Studio 2 for a few key reasons:
- GML is Perfect for Rapid Prototyping: GameMaker Language lets me iterate quickly on gameplay mechanics without getting bogged down in boilerplate code.
- Built-in 2D Tools: The sprite and animation systems are excellent for traditional 2D RPGs.
- Data Structures: GameMaker's ds_map and ds_list make managing game flags and inventory straightforward.
Core Systems Overview
The DN RPG Engine includes several interconnected systems:
Battle System
The heart of any RPG is its combat. I implemented a turn-based system with:
- Agility-based turn order calculation
- Multiple party members (Hero, Shapeshifter, Scientist, Trickster)
- Status effects (poison, regeneration, stun, silence, curse, blindness)
- Defense mechanics and resource management (HP, MP, TP)
- Item system with multiple targeting options (single, all allies/enemies, everyone)
// Example: Status effect application in battle
function apply_status_effect(target, effect_type, duration) {
if (!target.status_effects[effect_type]) {
target.status_effects[effect_type] = duration;
// Visual feedback and audio cue
play_sfx(snd_status_applied);
}
}
Controller Pattern Architecture
Rather than scattering logic across individual objects, I use specialized controller objects:
- objController: Master game controller managing global state
- objBattleController: Handles turn-based combat flow
- objDialogueController: NPC dialogue display and interactions
- objInventoryMenuController: Inventory UI and item management
This pattern keeps the codebase organized and makes debugging much easier.
Challenges and Solutions
Save/Load System
Implementing a proper save system was trickier than expected. I had to persist:
- Player stats and party composition
- Inventory contents
- Game flags (quest progress, story events)
- Current room and position
The solution was creating a centralized save data structure that gets serialized to JSON and written to disk.
Localization Support
From the beginning, I wanted to support multiple languages. The solution was a JSON-based translation system that loads language files at runtime. All text strings reference keys like "battle_victory" or "item_health_potion" that get resolved based on the current language setting.
What's Next?
The engine is functional but there's still work to do:
- Equipment system with permanent gear and slots
- More complex AI for enemy behaviors
- Crafting system for items
- Additional status effects and abilities
Building this engine has been incredibly educational. It's one thing to play RPGs and appreciate their systems, but implementing them yourself gives you a whole new level of respect for the developers who create these experiences. If you're interested in RPG development, I highly recommend starting with a simple battle system and building up from there.