@@ 23,13 23,13 @@ pub const MID_STARFIELD_SIZE: f32 = 384.0;
pub const FRONT_STARFIELD_SIZE: f32 = 512.0;
pub fn starfield_plugin(app: &mut App) {
- app.add_systems(Startup, setup_starfield)
+ app.add_systems(Startup, set_up_starfield)
.add_systems(Update, fix_starfield)
.add_systems(Update, resize_starfield)
.add_systems(Update, update_starfield);
}
-pub fn setup_starfield(
+pub fn set_up_starfield(
mut commands: Commands,
asset_server: Res<AssetServer>,
window: Query<&Window>,
@@ 183,6 183,13 @@ pub fn resize_starfield(
}
}
+macro_rules! fix_negative_field_translations {
+ ($field:ident, $size:expr) => {
+ if $field.translation.y < $size { $field.translation.y -= $size; }
+ if $field.translation.x < $size { $field.translation.x -= $size; }
+ };
+}
+
pub fn update_starfield(
mut starfield_back: Query<
&mut Transform,
@@ 240,7 247,7 @@ pub fn update_starfield(
) * camera.scale.z
/ 2.0)
% BACK_STARFIELD_SIZE
- //+ Vec3::new(0.0, BACK_STARFIELD_SIZE, 0.0)
+ + Vec3::new(0.0, BACK_STARFIELD_SIZE, 0.0)
- Vec3::new(0.0, 0.0, 5.0);
starfield_mid_pos.translation = player.translation
+ (-player.translation / 2.5) % MID_STARFIELD_SIZE
@@ 251,7 258,7 @@ pub fn update_starfield(
) * camera.scale.z
/ 2.0)
% MID_STARFIELD_SIZE
- //+ Vec3::new(0.0, MID_STARFIELD_SIZE, 0.0)
+ + Vec3::new(0.0, MID_STARFIELD_SIZE, 0.0)
- Vec3::new(0.0, 0.0, 4.5);
starfield_front_pos.translation = player.translation
+ (-player.translation / 2.0) % FRONT_STARFIELD_SIZE
@@ 262,6 269,10 @@ pub fn update_starfield(
) * camera.scale.z
/ 2.0)
% FRONT_STARFIELD_SIZE
- //+ Vec3::new(0.0, FRONT_STARFIELD_SIZE, 0.0)
+ + Vec3::new(0.0, FRONT_STARFIELD_SIZE, 0.0)
- Vec3::new(0.0, 0.0, 4.0);
+
+ fix_negative_field_translations!(starfield_back_pos, BACK_STARFIELD_SIZE);
+ fix_negative_field_translations!(starfield_mid_pos, MID_STARFIELD_SIZE);
+ fix_negative_field_translations!(starfield_front_pos, FRONT_STARFIELD_SIZE);
}