Search⌘ K
AI Features

Designing Data-Driven Dungeons

Explore how to design data-driven dungeon entities by defining templates in Rusty Object Notation files and loading them with Serde. Learn to create flexible spawn functions, deserialize game data, and extend modules for dynamic gameplay in Rust.

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:

Rust 1.40.0
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 ...