Adding the Player

Learn how the player can move up and down by flapping its wings.

Activating the player

Now that the player is defined in the previous lesson, we need to add an instance of the Player to our game’s state and initialize them in the constructor. We also need a variable named frame_time (an f32). This tracks the time accumulated between frames to control the game’s speed.

Press + to interact
struct State {
player: Player,
frame_time: f32,
mode: GameMode,
}
impl State {
fn new() -> Self {
State {
player: Player::new(5, 25),
frame_time: 0.0,
mode: GameMode::Menu,
}
}

The restart function needs to run whenever a new game starts, resetting the game state and indicating that the game is in ...