June 2021
Beginner
344 pages
8h 9m
English
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, you need to store the current game attributes of the dragon. Add a new struct to your main.rs file, after the enum declaration:
| | struct Player { |
| ① | x: i32, |
| ② | y: i32, |
| ③ | velocity: f32, |
| | } |
The x position of the player. This is a world-space position—specified in terminal characters. The player will always render on the left of the screen. x represents progress through the level.
The vertical position of the player in screen-space.
Read now
Unlock full access