June 2021
Beginner
344 pages
8h 9m
English
The other key part of Flappy Dragon is dodging obstacles. Let’s add walls to the game, with gaps through which the dragon may fly. Add another struct to your program:
| | struct Obstacle { |
| | x: i32, |
| | gap_y: i32, |
| | size: i32 |
| | } |
Obstacles have an x value, defining their position in world-space (to match the player’s world-space x value). The gap_y variable defines the center of the gap through which the dragon may pass. size defines the length of the gap in the obstacle.
You’ll need to define a constructor for the obstacle:
| | impl Obstacle { |
| | fn new(x: i32, score: i32) -> Self { |
| | let mut random = RandomNumberGenerator ... |
Read now
Unlock full access