Designing Data-Driven Dungeons
Learn how to create the data that describes our dungeon denizens using data-driven design.
We'll cover the following...
Our game’s entities have much in common. For example, they all have a name, starting position, render information, and game stats. Rather than use a custom spawn function for every entity in the game, we’ll instead create a common spawn function that reads the game’s data file and adds components using the values found in that file. First, we need a data file and an appropriate format.
This course will use Rusty Object Notation (RON) files to store our game definition. RON is similar to JSON and other structured data formats, but it’s designed to look like Rust.
Create a new file named resources/template.ron
and add the following game definition to it:
Templates(entities : [Template(entity_type: Item,name : "Healing Potion", glyph : '!', levels : [ 0, 1, 2 ],provides: Some([ ("Healing", 6) ]),frequency: 2),Template(entity_type: Item,name : "Weak Healing Potion", glyph : '!', levels : [ 0, 1, 2 ],provides: Some([ ("Healing", 2) ]),frequency: 2),Template(entity_type: Item,name : "Dungeon Map", glyph : '{', levels : [ 0, 1, 2 ],provides: Some([ ("MagicMap", 0) ]),frequency: 1),Template(entity_type: Enemy,name : "Goblin", glyph : 'g', levels : [ 0, 1, 2 ],hp : Some(1),frequency: 3),Template(entity_type: Enemy,name : "Orc", glyph : 'o', levels : [ 0, 1, 2 ],hp : Some(2),frequency: 2),],)
The contents of this template file should look familiar because it’s the same list of monsters and items we’ve been using. There’s some new information that includes varying health levels, however. The format should also look familiar because the RON format is similar to Rust.
Entries follow a name : value
format, or a name : [ .. ]
format for collections of data. The data file contains definitions of entity templates, collected in an array named entities. Each entry is of the Template
type, and the contents are listed like a Rust structure. Each entity has the following ...