Adding the Player
Explore how to add a player instance to your Rust game state and manage its behavior using frame timing and constants. Understand resetting game states, user input handling, and basic game physics to build a functional player mechanic within your game.
We'll cover the following...
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.
The restart function needs to run whenever a new game starts, resetting the game state and indicating that the game is in progress. Modify the restart function to reset the player when the game restarts:
Constants
Magic numbers are often considered a code smell (meaning a ...