Skip to content

Commit

Permalink
only in CI
Browse files Browse the repository at this point in the history
Co-Authored-By: Rob Parrett <robparrett@gmail.com>
  • Loading branch information
mockersf and rparrett committed Mar 16, 2024
1 parent befaa91 commit 4b594d0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions examples/games/alien_cake_addict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct Game {
}

#[derive(Resource, Deref, DerefMut)]
struct SeededRng(StdRng);
struct Random(StdRng);

const BOARD_SIZE_I: usize = 14;
const BOARD_SIZE_J: usize = 21;
Expand All @@ -108,7 +108,12 @@ fn setup_cameras(mut commands: Commands, mut game: ResMut<Game>) {
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMut<Game>) {
let mut seeded_rng = StdRng::seed_from_u64(19878367467713);
let mut rng = if std::env::var("GITHUB_ACTIONS") == Ok("true".to_string()) {
// Make the game play out the same way every time, this is useful for testing purposes.
StdRng::seed_from_u64(19878367467713)
} else {
StdRng::from_entropy()
};

// reset the game state
game.cake_eaten = 0;
Expand All @@ -134,7 +139,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMu
.map(|j| {
(0..BOARD_SIZE_I)
.map(|i| {
let height = seeded_rng.gen_range(-0.1..0.1);
let height = rng.gen_range(-0.1..0.1);
commands.spawn(SceneBundle {
transform: Transform::from_xyz(i as f32, height - 0.2, j as f32),
scene: cell_scene.clone(),
Expand Down Expand Up @@ -186,7 +191,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMu
}),
);

commands.insert_resource(SeededRng(seeded_rng));
commands.insert_resource(Random(rng));
}

// remove all entities that are not a camera or window
Expand Down Expand Up @@ -312,7 +317,7 @@ fn spawn_bonus(
mut next_state: ResMut<NextState<GameState>>,
mut commands: Commands,
mut game: ResMut<Game>,
mut rng: ResMut<SeededRng>,
mut rng: ResMut<Random>,
) {
// make sure we wait enough time before spawning the next cake
if !timer.0.tick(time.delta()).finished() {
Expand Down

0 comments on commit 4b594d0

Please sign in to comment.