2 Commits

Author SHA1 Message Date
eee039339e 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"
2025-07-29 13:26:41 -05:00
04f192b62a Drop never-used import
Thanks, VSCode. I really like when you import things I'm not actually
trying to use. SMH my head.
2025-07-29 13:17:01 -05:00

View File

@@ -2,7 +2,7 @@ use std::time::Duration;
/// This is the module containing all the rock-related things /// This is the module containing all the rock-related things
/// not... not the whole game. /// not... not the whole game.
use bevy::{math::VectorSpace, prelude::*}; use bevy::prelude::*;
use crate::{GameAssets, Position, Rotation, Velocity}; use crate::{GameAssets, Position, Rotation, Velocity};
@@ -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),
)); ));
} }
} }