Theming Your Dungeon
Now that you know how to use traits to make replaceable components, let’s give the game a bit more visual flair by substituting different map themes at runtime. Your dungeon could become a forest—or anything else you can draw. Alongside varied map design, this also helps to keep players interested.
Open map_builder/mod.rs, and add a new trait defining a map theme:
| pub trait MapTheme : Sync + Send { |
| fn tile_to_render(&self, tile_type: TileType) -> FontCharType; |
| } |
The required function signature should make sense: given a tile type, you return a character to render from the map font. Sync+Send is new.[61] Rust emphasizes “fearless concurrency,” which means you can write ...
Get Hands-on Rust now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.