Summary
This chapter covered one topic, but one of the most important topics in game development. State machines are everywhere in games, which we saw when we implemented a small one to manage the Loaded
and Loading
states of the WalkTheDog
enum
itself. They are a particularly nice way to implement animation states that must correspond with what the player is doing, and Rust has great ways to implement this pattern. We used two: the simple one for WalkTheDog
, and the much more complex RedHatBoyStateMachine
that uses the typestate pattern. The typestate pattern is a commonly used pattern in Rust, both inside and outside of game development, so you can expect to see it in many Rust projects.
We also used the compiler to drive development, over and over again. It's an incredibly useful technique, where you can start with what you want the code to look like and use the compiler's error messages to help you fill in the rest of the implementation. The code becomes like a paint...