...

/

Managing the Player

Managing the Player

Learn how the player flaps its wings.

In Flappy Dragon, the player battles gravity while trying to avoid obstacles and stay alive. To keep the dragon in flight, the player needs to press the spacebar to flap the dragon’s wings and gain upward momentum. For this to work, we need to store the current game attributes of the dragon. Add a new struct to our main.rs file, after the enum declaration:

Press + to interact
struct Player {
x: i32,
y: i32,
velocity: f32,
}
  • Line 2: This is the x position of the player. This is a world-space position specified in terminal characters. The player will always render on the left side of the screen. x represents progress through the level.

  • Line 3: This is the vertical position of the player in screen space.

  • Line 4 ...