fix flow a little bit
This commit is contained in:
@@ -13,7 +13,6 @@ mod main_menu;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.init_state::<GameState>()
|
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
DefaultPlugins,
|
DefaultPlugins,
|
||||||
asset_loading::plugin,
|
asset_loading::plugin,
|
||||||
@@ -22,7 +21,8 @@ fn main() {
|
|||||||
level_instantiation::map_plugin,
|
level_instantiation::map_plugin,
|
||||||
main_menu::plugin
|
main_menu::plugin
|
||||||
))
|
))
|
||||||
.add_systems(Startup, setup)
|
.init_state::<GameState>()
|
||||||
|
.add_systems(OnEnter(GameState::Playing), setup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ struct OnMainMenuScreen;
|
|||||||
pub fn plugin(app: &mut App) {
|
pub fn plugin(app: &mut App) {
|
||||||
app
|
app
|
||||||
.add_systems(OnEnter(GameState::Menu), setup_main_menu)
|
.add_systems(OnEnter(GameState::Menu), setup_main_menu)
|
||||||
.add_systems(OnExit(GameState::Menu), despawn_screen::<OnMainMenuScreen>)
|
.add_systems(OnExit(GameState::Menu), (
|
||||||
|
remove_camera_2d,
|
||||||
|
despawn_screen::<OnMainMenuScreen>
|
||||||
|
))
|
||||||
.add_systems(Update, button_system.run_if(in_state(GameState::Menu)));
|
.add_systems(Update, button_system.run_if(in_state(GameState::Menu)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,6 +33,8 @@ const HOVERED_PRESSED_BUTTON: Color = Color::srgb(0.25, 0.65, 0.25);
|
|||||||
const PRESSED_BUTTON: Color = Color::srgb(0.35, 0.75, 0.35);
|
const PRESSED_BUTTON: Color = Color::srgb(0.35, 0.75, 0.35);
|
||||||
|
|
||||||
fn setup_main_menu(mut commands: Commands) {
|
fn setup_main_menu(mut commands: Commands) {
|
||||||
|
commands.spawn(Camera2d);
|
||||||
|
|
||||||
let button_node = Node {
|
let button_node = Node {
|
||||||
width: Val::Px(300.0),
|
width: Val::Px(300.0),
|
||||||
height: Val::Px(65.0),
|
height: Val::Px(65.0),
|
||||||
@@ -135,6 +140,12 @@ fn button_system(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn remove_camera_2d(mut commands: Commands, camera_query: Query<Entity, With<Camera2d>>) {
|
||||||
|
for camera in camera_query.iter() {
|
||||||
|
commands.entity(camera).despawn_recursive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn despawn_screen<T: Component>(to_despawn: Query<Entity, With<T>>, mut commands: Commands) {
|
fn despawn_screen<T: Component>(to_despawn: Query<Entity, With<T>>, mut commands: Commands) {
|
||||||
for entity in &to_despawn {
|
for entity in &to_despawn {
|
||||||
commands.entity(entity).despawn_recursive();
|
commands.entity(entity).despawn_recursive();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use bevy::{prelude::*, render::view::RenderLayers, input::mouse::AccumulatedMouseMotion, pbr::NotShadowCaster};
|
use bevy::{prelude::*, render::view::RenderLayers, input::mouse::AccumulatedMouseMotion, pbr::NotShadowCaster};
|
||||||
use crate::physics_plugin::{AccumulatedInput, Velocity, PhysicalTranslation, PreviousPhysicalTranslation};
|
use crate::{physics_plugin::{AccumulatedInput, PhysicalTranslation, PreviousPhysicalTranslation, Velocity}, GameState};
|
||||||
|
|
||||||
#[derive(Debug, Component)]
|
#[derive(Debug, Component)]
|
||||||
pub struct Player;
|
pub struct Player;
|
||||||
@@ -20,9 +20,9 @@ struct WorldModelCamera;
|
|||||||
pub struct PlayerPlugin;
|
pub struct PlayerPlugin;
|
||||||
impl Plugin for PlayerPlugin {
|
impl Plugin for PlayerPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, init_player)
|
app.add_systems(OnEnter(GameState::Playing), init_player)
|
||||||
.add_systems(Update, move_camera)
|
.add_systems(Update, move_camera.run_if(in_state(GameState::Playing)))
|
||||||
.add_systems(RunFixedMainLoop, handle_input.in_set(RunFixedMainLoopSystem::BeforeFixedMainLoop));
|
.add_systems(RunFixedMainLoop, handle_input.in_set(RunFixedMainLoopSystem::BeforeFixedMainLoop).run_if(in_state(GameState::Playing)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ pub fn init_player(
|
|||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
|
||||||
// we use a second layer ("framebuffer") to draw the player's arm on
|
// we use a second layer ("framebuffer") to draw the player's arm on
|
||||||
// there also a second camera that only views this buffer
|
// there also a second camera that only views this buffer
|
||||||
// this makes it easy because the second camera doesn't move with the player
|
// this makes it easy because the second camera doesn't move with the player
|
||||||
@@ -126,8 +126,8 @@ pub fn handle_input(
|
|||||||
let right = transform.right(); // Right direction (x axis)
|
let right = transform.right(); // Right direction (x axis)
|
||||||
|
|
||||||
if keyboard_input.pressed(KeyCode::KeyW) {
|
if keyboard_input.pressed(KeyCode::KeyW) {
|
||||||
input.x += forward.x;
|
input.x += forward.x;
|
||||||
input.z += forward.z;
|
input.z += forward.z;
|
||||||
}
|
}
|
||||||
if keyboard_input.pressed(KeyCode::KeyS) {
|
if keyboard_input.pressed(KeyCode::KeyS) {
|
||||||
input.x -= forward.x;
|
input.x -= forward.x;
|
||||||
@@ -146,5 +146,3 @@ pub fn handle_input(
|
|||||||
velocity.0 = input.normalize_or_zero() * SPEED;
|
velocity.0 = input.normalize_or_zero() * SPEED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user