Newer
Older
use crate::entities::{BoxSize, EntitySpawner};
use bevy::prelude::{Component, Query, Transform, Vec2, With};
#[derive(Component)]
pub struct Background;
// TODO: No Magic Numbers!
pub const BACKGROUND_WIDTH: f32 = 2110.0;
pub const BACKGROUND_HEIGHT: f32 = 300.0;
pub fn spawn_backgrounds(mut spawner: EntitySpawner) {
let bounds = window_bounds();
spawner.spawn_background_at(Vec2::new(BACKGROUND_WIDTH / 2.0, bounds.height() / 2.0));
spawner.spawn_background_at(Vec2::new(
(BACKGROUND_WIDTH / 2.0) + BACKGROUND_WIDTH,
bounds.height() / 2.0,
));
}
pub fn cycle_background_positions(
mut background_query: Query<(&mut Transform, &BoxSize), With<Background>>,
) {
for (mut transform, size) in &mut background_query {
if transform.translation.x <= -(size.x / 2.0) {
transform.translation.x = size.x + (size.x / 2.0);
}
}
}