Skip to content

Commit

Permalink
undo examples
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB committed Sep 8, 2024
1 parent 05da221 commit eef1d1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
10 changes: 7 additions & 3 deletions examples/games/alien_cake_addict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ fn focus_camera(
fn spawn_bonus(
time: Res<Time>,
mut timer: ResMut<BonusSpawnTimer>,
mut next_state: ResMut<NextState<GameState>>,
mut commands: Commands,
mut game: ResMut<Game>,
mut rng: ResMut<Random>,
Expand All @@ -330,7 +331,7 @@ fn spawn_bonus(
commands.entity(entity).despawn_recursive();
game.bonus.entity = None;
if game.score <= -5 {
commands.set_state(GameState::GameOver);
next_state.set(GameState::GameOver);
return;
}
}
Expand Down Expand Up @@ -388,9 +389,12 @@ fn scoreboard_system(game: Res<Game>, mut query: Query<&mut Text>) {
}

// restart the game when pressing spacebar
fn gameover_keyboard(mut commands: Commands, keyboard_input: Res<ButtonInput<KeyCode>>) {
fn gameover_keyboard(
mut next_state: ResMut<NextState<GameState>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
commands.set_state(GameState::Playing);
next_state.set(GameState::Playing);
}
}

Expand Down
37 changes: 23 additions & 14 deletions examples/games/game_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ mod splash {
}

// Tick the timer, and change state when finished
fn countdown(mut commands: Commands, time: Res<Time>, mut timer: ResMut<SplashTimer>) {
fn countdown(
mut game_state: ResMut<NextState<GameState>>,
time: Res<Time>,
mut timer: ResMut<SplashTimer>,
) {
if timer.tick(time.delta()).finished() {
commands.set_state(GameState::Menu);
game_state.set(GameState::Menu);
}
}
}
Expand Down Expand Up @@ -224,9 +228,13 @@ mod game {
}

// Tick the timer, and change state when finished
fn game(time: Res<Time>, mut commands: Commands, mut timer: ResMut<GameTimer>) {
fn game(
time: Res<Time>,
mut game_state: ResMut<NextState<GameState>>,
mut timer: ResMut<GameTimer>,
) {
if timer.tick(time.delta()).finished() {
commands.set_state(GameState::Menu);
game_state.set(GameState::Menu);
}
}
}
Expand Down Expand Up @@ -370,8 +378,8 @@ mod menu {
}
}

fn menu_setup(mut commands: Commands) {
commands.set_state(MenuState::Main);
fn menu_setup(mut menu_state: ResMut<NextState<MenuState>>) {
menu_state.set(MenuState::Main);
}

fn main_menu_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down Expand Up @@ -769,12 +777,13 @@ mod menu {
}

fn menu_action(
mut commands: Commands,
interaction_query: Query<
(&Interaction, &MenuButtonAction),
(Changed<Interaction>, With<Button>),
>,
mut app_exit_events: EventWriter<AppExit>,
mut menu_state: ResMut<NextState<MenuState>>,
mut game_state: ResMut<NextState<GameState>>,
) {
for (interaction, menu_button_action) in &interaction_query {
if *interaction == Interaction::Pressed {
Expand All @@ -783,19 +792,19 @@ mod menu {
app_exit_events.send(AppExit::Success);
}
MenuButtonAction::Play => {
commands.set_state(GameState::Game);
commands.set_state(MenuState::Disabled);
game_state.set(GameState::Game);
menu_state.set(MenuState::Disabled);
}
MenuButtonAction::Settings => commands.set_state(MenuState::Settings),
MenuButtonAction::Settings => menu_state.set(MenuState::Settings),
MenuButtonAction::SettingsDisplay => {
commands.set_state(MenuState::SettingsDisplay);
menu_state.set(MenuState::SettingsDisplay);
}
MenuButtonAction::SettingsSound => {
commands.set_state(MenuState::SettingsSound);
menu_state.set(MenuState::SettingsSound);
}
MenuButtonAction::BackToMainMenu => commands.set_state(MenuState::Main),
MenuButtonAction::BackToMainMenu => menu_state.set(MenuState::Main),
MenuButtonAction::BackToSettings => {
commands.set_state(MenuState::Settings);
menu_state.set(MenuState::Settings);
}
}
}
Expand Down

0 comments on commit eef1d1f

Please sign in to comment.