Asteroid spawner now uses info from event message
Some checks failed
Basic checks / Basic build-and-test supertask (push) Has been cancelled

Closes #4: "Convert asteroid spawning system into an event listener"
This commit is contained in:
2025-07-29 13:25:31 -05:00
parent 04f192b62a
commit eee039339e

View File

@@ -50,7 +50,7 @@ pub fn tick_asteroid_manager(
if spawner.timer.just_finished() { if spawner.timer.just_finished() {
events.write(SpawnAsteroid { events.write(SpawnAsteroid {
pos: Vec2::ZERO, pos: Vec2::ZERO,
vel: Vec2::ZERO, vel: Vec2::new(0.0, 40.0),
size: AsteroidSize::Small, size: AsteroidSize::Small,
}); });
} }
@@ -65,14 +65,18 @@ pub fn spawn_asteroid(
game_assets: Res<GameAssets>, game_assets: Res<GameAssets>,
) { ) {
for spawn in events.read() { for spawn in events.read() {
// TODO: Use the asteroid properties defined in the event to spawn the entity let (mesh, material) = match spawn.size {
AsteroidSize::Small => game_assets.asteroid_small(),
AsteroidSize::Medium => game_assets.asteroid_medium(),
AsteroidSize::Large => game_assets.asteroid_large(),
};
commands.spawn(( commands.spawn((
Asteroid(AsteroidSize::Small), Asteroid(AsteroidSize::Small),
Position(Vec2::new(40.0, 40.0)), Position(spawn.pos),
Velocity(Vec2::new(10.0, 0.0)), Velocity(spawn.vel),
Rotation(0.0), Rotation(0.0),
Mesh2d(game_assets.asteroid_small().0), Mesh2d(mesh),
MeshMaterial2d(game_assets.asteroid_small().1), MeshMaterial2d(material),
)); ));
} }
} }