create_entities: Remove from MainScene struct
This commit is contained in:
parent
51a3f812fe
commit
5d4048d9a7
1 changed files with 49 additions and 52 deletions
|
@ -138,7 +138,7 @@ impl AsScene for MainScene {
|
|||
.chain(),
|
||||
);
|
||||
world.insert_resource(Timer::new());
|
||||
Self::create_entities(world, 100, 10.0, 10.0);
|
||||
create_entities(world, 100, 10.0, 10.0);
|
||||
|
||||
self.state = Some(MainSceneState {
|
||||
square,
|
||||
|
@ -370,67 +370,64 @@ impl AsScene for MainScene {
|
|||
}
|
||||
}
|
||||
|
||||
impl MainScene {
|
||||
// Function to create entities in the ECS world
|
||||
fn create_entities(
|
||||
world: &mut World,
|
||||
num_instances: u32,
|
||||
instance_size: f32,
|
||||
instance_spacing: f32,
|
||||
) {
|
||||
let num_instances_per_row = (num_instances as f32 / instance_spacing).ceil() as u32;
|
||||
fn create_entities(
|
||||
world: &mut World,
|
||||
num_instances: u32,
|
||||
instance_size: f32,
|
||||
instance_spacing: f32,
|
||||
) {
|
||||
let num_instances_per_row = (num_instances as f32 / instance_spacing).ceil() as u32;
|
||||
|
||||
let square_instances = (0..num_instances)
|
||||
.map(|i| {
|
||||
let x_index = i % num_instances_per_row;
|
||||
let z_index = i / num_instances_per_row;
|
||||
let square_instances = (0..num_instances)
|
||||
.map(|i| {
|
||||
let x_index = i % num_instances_per_row;
|
||||
let z_index = i / num_instances_per_row;
|
||||
|
||||
let transform = Transform::new(
|
||||
Vec3::new(
|
||||
x_index as f32 * (instance_spacing + instance_size),
|
||||
0.0,
|
||||
z_index as f32 * (instance_spacing + instance_size),
|
||||
),
|
||||
Quat::from_euler(EulerRot::XYZ, 0.0, rand::random_range(0.0..=360.0), 0.0),
|
||||
Vec3::new(instance_size, instance_size, instance_size),
|
||||
);
|
||||
let transform = Transform::new(
|
||||
Vec3::new(
|
||||
x_index as f32 * (instance_spacing + instance_size),
|
||||
0.0,
|
||||
z_index as f32 * (instance_spacing + instance_size),
|
||||
),
|
||||
Quat::from_euler(EulerRot::XYZ, 0.0, rand::random_range(0.0..=360.0), 0.0),
|
||||
Vec3::new(instance_size, instance_size, instance_size),
|
||||
);
|
||||
|
||||
let velocity = Velocity::new(Vec3::ZERO, Vec3::new(0.0, x_index as f32, 0.0));
|
||||
let velocity = Velocity::new(Vec3::ZERO, Vec3::new(0.0, x_index as f32, 0.0));
|
||||
|
||||
(Square, transform, velocity)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
(Square, transform, velocity)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
world.spawn_batch(square_instances);
|
||||
world.spawn_batch(square_instances);
|
||||
|
||||
let cube_instances = (0..num_instances)
|
||||
.map(|i| {
|
||||
let x_index = i % num_instances_per_row;
|
||||
let z_index = i / num_instances_per_row;
|
||||
let cube_instances = (0..num_instances)
|
||||
.map(|i| {
|
||||
let x_index = i % num_instances_per_row;
|
||||
let z_index = i / num_instances_per_row;
|
||||
|
||||
let transform = Transform::new(
|
||||
Vec3::new(
|
||||
x_index as f32 * (instance_spacing + instance_size),
|
||||
0.0,
|
||||
z_index as f32 * (instance_spacing + instance_size) * -1.0
|
||||
- instance_spacing * 2.0,
|
||||
),
|
||||
Quat::from_euler(EulerRot::XYZ, 0.0, rand::random_range(0.0..=360.0), 0.0),
|
||||
Vec3::new(
|
||||
instance_size * 0.5,
|
||||
instance_size * 0.5,
|
||||
instance_size * 0.5,
|
||||
),
|
||||
);
|
||||
let transform = Transform::new(
|
||||
Vec3::new(
|
||||
x_index as f32 * (instance_spacing + instance_size),
|
||||
0.0,
|
||||
z_index as f32 * (instance_spacing + instance_size) * -1.0
|
||||
- instance_spacing * 2.0,
|
||||
),
|
||||
Quat::from_euler(EulerRot::XYZ, 0.0, rand::random_range(0.0..=360.0), 0.0),
|
||||
Vec3::new(
|
||||
instance_size * 0.5,
|
||||
instance_size * 0.5,
|
||||
instance_size * 0.5,
|
||||
),
|
||||
);
|
||||
|
||||
let velocity = Velocity::new(Vec3::ZERO, Vec3::new(0.0, x_index as f32, 0.0));
|
||||
let velocity = Velocity::new(Vec3::ZERO, Vec3::new(0.0, x_index as f32, 0.0));
|
||||
|
||||
(Cube, transform, velocity)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
(Cube, transform, velocity)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
world.spawn_batch(cube_instances);
|
||||
}
|
||||
world.spawn_batch(cube_instances);
|
||||
}
|
||||
|
||||
fn update_velocity_system(mut query: Query<(&mut Transform, &Velocity)>, time: Res<Timer>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue