Rendering With Themes
Explore how to create and apply different map themes in your Rust game development project. Understand struct initialization, random theme selection, and integrating themes with Legion resources. This lesson guides you to enhance your game's environment, enabling diverse and engaging map designs.
The MapBuilder needs to know what theme we’re associating with our newly designed map.
Add a theme to the MapBuilder in map_builer/mod.rs:
Rust requires that we initialize every field in a struct on creation because uninitialized fields are a common source of bugs in other languages. Add the following line to the initialization of each MapBuilder (automata.rs, drunkard.rs, empty.rs, and rooms.rs):
Creating a new theme object is a little wasteful because we’re creating a theme and never using it. We could wrap it in an Option and use None and Some(x) if we prefer. Map rendering happens so infrequently that it isn’t worth worrying about a tiny bit of overhead when the map is generated.