Fix visibility & add constructors, program builds
All checks were successful
Basic checks / Basic build-and-test supertask (push) Successful in 6m29s
All checks were successful
Basic checks / Basic build-and-test supertask (push) Successful in 6m29s
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
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::prelude::*;
|
use bevy::prelude::*;
|
||||||
@@ -5,16 +7,16 @@ use bevy::prelude::*;
|
|||||||
use crate::{GameAssets, Position, Rotation, Velocity};
|
use crate::{GameAssets, Position, Rotation, Velocity};
|
||||||
|
|
||||||
#[derive(Component, Deref, DerefMut)]
|
#[derive(Component, Deref, DerefMut)]
|
||||||
struct Asteroid(AsteroidSize);
|
pub struct Asteroid(AsteroidSize);
|
||||||
|
|
||||||
enum AsteroidSize {
|
pub enum AsteroidSize {
|
||||||
SMALL,
|
SMALL,
|
||||||
MEDIUM,
|
MEDIUM,
|
||||||
LARGE,
|
LARGE,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct AsteroidSpawner {
|
pub struct AsteroidSpawner {
|
||||||
timer: Timer,
|
timer: Timer,
|
||||||
// TODO: Configurables?
|
// TODO: Configurables?
|
||||||
// - interval
|
// - interval
|
||||||
@@ -22,9 +24,17 @@ struct AsteroidSpawner {
|
|||||||
// - size distribution
|
// - size distribution
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsteroidSpawner {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
timer: Timer::new(Duration::from_secs(3), TimerMode::Repeating),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Update the asteroid spawn timer and spawn any asteroids
|
/// Update the asteroid spawn timer and spawn any asteroids
|
||||||
/// that are due this frame.
|
/// that are due this frame.
|
||||||
fn tick_asteroid_manager(
|
pub fn tick_asteroid_manager(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut spawner: ResMut<AsteroidSpawner>,
|
mut spawner: ResMut<AsteroidSpawner>,
|
||||||
game_assets: Res<GameAssets>,
|
game_assets: Res<GameAssets>,
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ pub mod config;
|
|||||||
mod preparation_widget;
|
mod preparation_widget;
|
||||||
mod title_screen;
|
mod title_screen;
|
||||||
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use crate::config::{BACKGROUND_COLOR, PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, WINDOW_SIZE};
|
use crate::config::{BACKGROUND_COLOR, PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, WINDOW_SIZE};
|
||||||
|
|
||||||
|
use asteroids::AsteroidSpawner;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_inspector_egui::prelude::ReflectInspectorOptions;
|
use bevy_inspector_egui::prelude::ReflectInspectorOptions;
|
||||||
use bevy_inspector_egui::InspectorOptions;
|
use bevy_inspector_egui::InspectorOptions;
|
||||||
@@ -29,9 +28,7 @@ impl Plugin for AsteroidPlugin {
|
|||||||
.insert_resource(Lives(3))
|
.insert_resource(Lives(3))
|
||||||
.register_type::<Lives>()
|
.register_type::<Lives>()
|
||||||
.insert_resource(Score(0))
|
.insert_resource(Score(0))
|
||||||
.insert_resource(AsteroidSpawner {
|
.insert_resource(AsteroidSpawner::new())
|
||||||
timer: Timer::new(Duration::from_secs(3), TimerMode::Repeating),
|
|
||||||
})
|
|
||||||
.init_resource::<GameAssets>()
|
.init_resource::<GameAssets>()
|
||||||
.add_systems(Startup, spawn_camera)
|
.add_systems(Startup, spawn_camera)
|
||||||
.add_systems(OnEnter(GameState::Playing), (spawn_player, spawn_ui))
|
.add_systems(OnEnter(GameState::Playing), (spawn_player, spawn_ui))
|
||||||
@@ -41,7 +38,7 @@ impl Plugin for AsteroidPlugin {
|
|||||||
input_ship_thruster,
|
input_ship_thruster,
|
||||||
input_ship_rotation,
|
input_ship_rotation,
|
||||||
wrap_entities,
|
wrap_entities,
|
||||||
tick_asteroid_manager,
|
asteroids::tick_asteroid_manager,
|
||||||
)
|
)
|
||||||
.run_if(in_state(GameState::Playing)),
|
.run_if(in_state(GameState::Playing)),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user