States, I guess. Now to do the others

Game states are named and used to toggle behavior. Now to rewrite those
things to do the *right* behavior.
This commit is contained in:
2024-11-29 16:45:52 -06:00
parent f114203665
commit c86cd0d642

View File

@@ -11,7 +11,7 @@ impl Plugin for AsteroidPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems( app.add_systems(
Startup, Startup,
(spawn_camera, spawn_player, spawn_ui, start_screen), (spawn_camera, spawn_player, spawn_ui),
) )
.insert_resource(ClearColor(BACKGROUND_COLOR)) .insert_resource(ClearColor(BACKGROUND_COLOR))
.insert_resource(WorldSize { .insert_resource(WorldSize {
@@ -22,15 +22,29 @@ impl Plugin for AsteroidPlugin {
.insert_resource(Score(0)) .insert_resource(Score(0))
.add_systems( .add_systems(
FixedUpdate, FixedUpdate,
(input_ship_thruster, input_ship_rotation, wrap_entities), (input_ship_thruster, input_ship_rotation, wrap_entities).run_if(in_state(GameState::Playing)),
) )
.add_systems( .add_systems(
FixedPostUpdate, FixedPostUpdate,
(integrate_velocity, update_positions, apply_rotation_to_mesh), (integrate_velocity, update_positions, apply_rotation_to_mesh).run_if(in_state(GameState::Playing)),
)
.add_systems(
OnEnter(GameState::TitleScreen),
start_screen
); );
app.insert_state(GameState::TitleScreen);
} }
} }
#[derive(Clone, Debug, Eq, Hash, PartialEq, States)]
enum GameState {
TitleScreen, // Program is started. Present title screen and await user start
GetReady, // Short timer to let the player get ready after pressing start
Playing, // Player has started the game. Run the main loop
GameOver, // Game has ended. Present game over dialogue and await user restart
}
#[derive(Component)] #[derive(Component)]
struct Position(bevy::math::Vec2); struct Position(bevy::math::Vec2);