Move asteroid bits to another module
Now to fix the visibility issues and make the program compile again...
This commit is contained in:
51
src/asteroids.rs
Normal file
51
src/asteroids.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
/// This is the module containing all the rock-related things
|
||||
/// not... not the whole game.
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{GameAssets, Position, Rotation, Velocity};
|
||||
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
struct Asteroid(AsteroidSize);
|
||||
|
||||
enum AsteroidSize {
|
||||
SMALL,
|
||||
MEDIUM,
|
||||
LARGE,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct AsteroidSpawner {
|
||||
timer: Timer,
|
||||
// TODO: Configurables?
|
||||
// - interval
|
||||
// - density
|
||||
// - size distribution
|
||||
}
|
||||
|
||||
/// Update the asteroid spawn timer and spawn any asteroids
|
||||
/// that are due this frame.
|
||||
fn tick_asteroid_manager(
|
||||
mut commands: Commands,
|
||||
mut spawner: ResMut<AsteroidSpawner>,
|
||||
game_assets: Res<GameAssets>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
spawner.timer.tick(time.delta());
|
||||
if spawner.timer.just_finished() {
|
||||
commands.spawn((
|
||||
Asteroid(AsteroidSize::SMALL),
|
||||
Position(Vec2::new(40.0, 40.0)),
|
||||
Velocity(Vec2::new(10.0, 0.0)),
|
||||
Rotation(0.0),
|
||||
Mesh2d(game_assets.asteroid_small().0),
|
||||
MeshMaterial2d(game_assets.asteroid_small().1),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Utility function to spawn a single asteroid of a given type
|
||||
/// TODO: convert to an event listener monitoring for "spawn asteroid" events
|
||||
/// from the `fn tick_asteroid_manager(...)` system.
|
||||
fn spawn_asteroid(mut commands: Commands) {
|
||||
todo!();
|
||||
}
|
||||
47
src/lib.rs
47
src/lib.rs
@@ -1,3 +1,4 @@
|
||||
mod asteroids;
|
||||
pub mod config;
|
||||
mod preparation_widget;
|
||||
mod title_screen;
|
||||
@@ -73,24 +74,6 @@ struct Rotation(f32);
|
||||
#[derive(Component)]
|
||||
struct Ship;
|
||||
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
struct Asteroid(AsteroidSize);
|
||||
|
||||
enum AsteroidSize {
|
||||
SMALL,
|
||||
MEDIUM,
|
||||
LARGE,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct AsteroidSpawner {
|
||||
timer: Timer,
|
||||
// TODO: Configurables?
|
||||
// - interval
|
||||
// - density
|
||||
// - size distribution
|
||||
}
|
||||
|
||||
/// Marker for any entity that should wrap on screen edges
|
||||
#[derive(Component)]
|
||||
struct Wrapping;
|
||||
@@ -212,34 +195,6 @@ fn spawn_player(mut commands: Commands, game_assets: Res<GameAssets>) {
|
||||
));
|
||||
}
|
||||
|
||||
/// Update the asteroid spawn timer and spawn any asteroids
|
||||
/// that are due this frame.
|
||||
fn tick_asteroid_manager(
|
||||
mut commands: Commands,
|
||||
mut spawner: ResMut<AsteroidSpawner>,
|
||||
game_assets: Res<GameAssets>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
spawner.timer.tick(time.delta());
|
||||
if spawner.timer.just_finished() {
|
||||
commands.spawn((
|
||||
Asteroid(AsteroidSize::SMALL),
|
||||
Position(Vec2::new(40.0, 40.0)),
|
||||
Velocity(Vec2::new(10.0, 0.0)),
|
||||
Rotation(0.0),
|
||||
Mesh2d(game_assets.asteroid_small().0),
|
||||
MeshMaterial2d(game_assets.asteroid_small().1),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Utility function to spawn a single asteroid of a given type
|
||||
/// TODO: convert to an event listener monitoring for "spawn asteroid" events
|
||||
/// from the `fn tick_asteroid_manager(...)` system.
|
||||
fn spawn_asteroid(mut commands: Commands) {
|
||||
todo!();
|
||||
}
|
||||
|
||||
/*
|
||||
Checks if "W" is pressed and increases velocity accordingly.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user