Split title screen into it's own mod & Plugin
Some checks failed
Basic checks / Basic build-and-test supertask (push) Failing after 28s
Some checks failed
Basic checks / Basic build-and-test supertask (push) Failing after 28s
This commit is contained in:
34
src/lib.rs
34
src/lib.rs
@@ -1,4 +1,5 @@
|
|||||||
pub mod config;
|
pub mod config;
|
||||||
|
mod title_screen;
|
||||||
|
|
||||||
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};
|
||||||
|
|
||||||
@@ -9,7 +10,8 @@ pub struct AsteroidPlugin;
|
|||||||
|
|
||||||
impl Plugin for AsteroidPlugin {
|
impl Plugin for AsteroidPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, (spawn_camera, spawn_player, spawn_ui))
|
app.add_plugins(title_screen::GameMenuPlugin)
|
||||||
|
.add_systems(Startup, (spawn_camera, spawn_player, spawn_ui))
|
||||||
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
||||||
.insert_resource(WorldSize {
|
.insert_resource(WorldSize {
|
||||||
width: WINDOW_SIZE.x,
|
width: WINDOW_SIZE.x,
|
||||||
@@ -26,9 +28,7 @@ impl Plugin for AsteroidPlugin {
|
|||||||
FixedPostUpdate,
|
FixedPostUpdate,
|
||||||
(integrate_velocity, update_positions, apply_rotation_to_mesh)
|
(integrate_velocity, update_positions, apply_rotation_to_mesh)
|
||||||
.run_if(in_state(GameState::Playing)),
|
.run_if(in_state(GameState::Playing)),
|
||||||
)
|
);
|
||||||
.add_systems(OnEnter(GameState::TitleScreen), start_screen);
|
|
||||||
|
|
||||||
app.insert_state(GameState::TitleScreen);
|
app.insert_state(GameState::TitleScreen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,11 +83,6 @@ struct WorldSize {
|
|||||||
height: f32,
|
height: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marker component for the title screen UI entity.
|
|
||||||
// This way, a query for the TitleUI can be used to despawn the title screen
|
|
||||||
#[derive(Component)]
|
|
||||||
struct TitleUI;
|
|
||||||
|
|
||||||
fn spawn_camera(mut commands: Commands) {
|
fn spawn_camera(mut commands: Commands) {
|
||||||
commands.spawn(Camera2d);
|
commands.spawn(Camera2d);
|
||||||
}
|
}
|
||||||
@@ -232,24 +227,3 @@ fn spawn_ui(mut commands: Commands, score: Res<Score>, lives: Res<Lives>) {
|
|||||||
TextFont::from_font_size(25.0),
|
TextFont::from_font_size(25.0),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_screen(mut commands: Commands) {
|
|
||||||
commands
|
|
||||||
.spawn((
|
|
||||||
TitleUI,
|
|
||||||
Node {
|
|
||||||
flex_direction: FlexDirection::Column,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.with_children(|cmds| {
|
|
||||||
cmds.spawn((
|
|
||||||
Text::new("Robert's Bad Asteroids Game"),
|
|
||||||
TextFont::from_font_size(50.0),
|
|
||||||
));
|
|
||||||
cmds.spawn((
|
|
||||||
Text::new("Press space to begin"),
|
|
||||||
TextFont::from_font_size(40.0),
|
|
||||||
));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
44
src/title_screen.rs
Normal file
44
src/title_screen.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use crate::GameState;
|
||||||
|
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
pub struct GameMenuPlugin;
|
||||||
|
|
||||||
|
impl Plugin for GameMenuPlugin {
|
||||||
|
fn build(&self, app: &mut App){
|
||||||
|
app
|
||||||
|
.add_systems(OnEnter(GameState::TitleScreen), spawn_menu)
|
||||||
|
.add_systems(OnExit(GameState::TitleScreen), despawn_menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Marker component for the title screen UI entity.
|
||||||
|
// This way, a query for the TitleUI can be used to despawn the title screen
|
||||||
|
#[derive(Component)]
|
||||||
|
struct TitleUI;
|
||||||
|
|
||||||
|
fn spawn_menu(mut commands: Commands) {
|
||||||
|
commands.spawn(Camera2d);
|
||||||
|
commands
|
||||||
|
.spawn((
|
||||||
|
TitleUI,
|
||||||
|
Node {
|
||||||
|
flex_direction: FlexDirection::Column,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.with_children(|cmds| {
|
||||||
|
cmds.spawn((
|
||||||
|
Text::new("Robert's Bad Asteroids Game"),
|
||||||
|
TextFont::from_font_size(50.0),
|
||||||
|
));
|
||||||
|
cmds.spawn((
|
||||||
|
Text::new("Press space to begin"),
|
||||||
|
TextFont::from_font_size(40.0),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn despawn_menu() {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user