Managing the Player
Explore how to represent and update player attributes such as position and velocity in Rust. Understand rendering a character on screen, applying gravity effects, and simulating movement like flapping wings for smooth gameplay in your Rust-based game.
We'll cover the following...
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:
-
Line 2: This is the
xposition 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.xrepresents progress through the level. -
Line 3: This is the vertical position of the player in screen space.
-
Line 4: The player’s vertical
velocityis an f32, a floating-point number. ...