diff --git a/src/world.rs b/src/world.rs index 8676403..a16c7af 100644 --- a/src/world.rs +++ b/src/world.rs @@ -70,6 +70,8 @@ impl Plugin for WorldPlugin { #[derive(Resource)] struct AsteroidUpdateTimer(Timer); #[derive(Resource)] struct AsteroidDatabase(Vec); #[derive(Resource)] struct ActiveAsteroids(HashMap); +#[derive(Resource)] struct AsteroidModel1(Handle); +#[derive(Resource)] struct AsteroidModel2(Handle); #[derive(Component)] struct Asteroid; #[derive(Component)] pub struct DespawnOnPlayerDeath; @@ -112,7 +114,12 @@ pub fn setup( mut meshes: ResMut>, mut materials: ResMut>, mut materials_custom: ResMut>, + asset_server: Res, ) { + // Load assets + commands.insert_resource(AsteroidModel1(asset_server.load(ASSET_ASTEROID1))); + commands.insert_resource(AsteroidModel2(asset_server.load(ASSET_ASTEROID2))); + // Generate starmap let sphere_handle = meshes.add(Sphere::new(1.0)); let mut starcount = 0; @@ -186,7 +193,8 @@ fn spawn_despawn_asteroids( q_player: Query<&Position, With>, mut ew_despawn: EventWriter, mut db: ResMut, - asset_server: Res, + asteroid1_handle: Res, + asteroid2_handle: Res, mut q_asteroid: Query<(Entity, &SceneInstance), With>, mut last_player_cell: Local, ) { @@ -316,12 +324,12 @@ fn spawn_despawn_asteroids( Position::new(pos), Asteroid, )); - let asset = match class { - 0 => ASSET_ASTEROID1, - _ => ASSET_ASTEROID2, + let model = match class { + 0 => asteroid1_handle.0.clone(), + _ => asteroid2_handle.0.clone(), }; entity_commands.insert(SceneBundle { - scene: asset_server.load(asset), + scene: model, transform: Transform { scale: Vec3::splat(size), ..default()