Managing animation
We'll create our state machine to manage the different animations. Specifically, when RHB isn't moving, he's Idle
, but when he's moving, he's Running
. When he jumps, he's Jumping
. You get the idea.
Those different RHB states correspond to the different animations managed using a state machine. We'll first create the RHB with a state machine and then integrate it into our current application. We'll implement this top-down, starting with a struct that represents RHB and letting the compiler errors drive further development. This is sometimes called Compiler-Driven Development although it's not a formalized approach such as Test-Driven Development. It can work extremely well in a language with a robust type system and great compiler errors, such as Rust. Let's start with how we'll represent RHB.
The RedHatBoy
struct will contain the state machine, the sprite sheet, and the image because eventually, it will...