game states cleanup
This commit is contained in:
+12
-6
@@ -22,15 +22,21 @@ fn follow_player(
|
||||
// + (player.translation.y - camera.translation.y) * 3.0 * time.delta_secs(); // with delay
|
||||
}
|
||||
|
||||
fn reset_camera(mut main_camera: Single<&mut Camera, With<MainCamera>>) {
|
||||
main_camera.is_active = true;
|
||||
}
|
||||
|
||||
pub struct CameraPlugin;
|
||||
|
||||
impl Plugin for CameraPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_main_camera).add_systems(
|
||||
Update,
|
||||
follow_player
|
||||
.run_if(in_state(GameState::InGame))
|
||||
.after(move_player),
|
||||
);
|
||||
app.add_systems(Startup, spawn_main_camera)
|
||||
.add_systems(OnEnter(GameState::InGame), reset_camera)
|
||||
.add_systems(
|
||||
Update,
|
||||
follow_player
|
||||
.run_if(in_state(GameState::InGame))
|
||||
.after(move_player),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ fn game_over(mut commands: Commands) {
|
||||
},
|
||||
),
|
||||
(
|
||||
Text::new("| N new map | R restart | T main menu | "),
|
||||
Text::new("N new map | R restart | T main menu"),
|
||||
TextFont {
|
||||
font_size: FontSize::Px(40.0),
|
||||
..default()
|
||||
|
||||
+5
-2
@@ -1,6 +1,6 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::game_state::GameState;
|
||||
use crate::{camera::MainCamera, game_state::GameState};
|
||||
|
||||
// To delete menu's components
|
||||
#[derive(Component)]
|
||||
@@ -53,12 +53,15 @@ fn cleanup_menu(mut commands: Commands, menu: Query<Entity, With<MainMenu>>) {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
fn reset_camera(mut main_camera: Single<&mut Camera, With<MainCamera>>) {
|
||||
main_camera.is_active = true;
|
||||
}
|
||||
|
||||
pub struct MainMenuPlugin;
|
||||
|
||||
impl Plugin for MainMenuPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::MainMenu), main_menu)
|
||||
app.add_systems(OnEnter(GameState::MainMenu), (main_menu, reset_camera))
|
||||
.add_systems(Update, menu_input.run_if(in_state(GameState::MainMenu)))
|
||||
.add_systems(OnExit(GameState::MainMenu), cleanup_menu);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use crate::{collision::Collider, player::reset_player};
|
||||
use crate::{collision::Collider, player::debug_game_over};
|
||||
use bevy::prelude::*;
|
||||
use rand::RngExt;
|
||||
use rand::SeedableRng;
|
||||
|
||||
+3
-3
@@ -84,8 +84,8 @@ pub(crate) fn move_player(
|
||||
transform.translation += velocity.0.extend(0.0) * time.delta_secs();
|
||||
}
|
||||
|
||||
// Reset
|
||||
pub fn reset_player(
|
||||
// Debug
|
||||
pub fn debug_game_over(
|
||||
// player: Single<(&mut Transform, &mut Velocity, &mut Sprite), With<Player>>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
mut fall_started: ResMut<FallStarted>,
|
||||
@@ -124,7 +124,7 @@ impl Plugin for PlayerPlugin {
|
||||
Update,
|
||||
(
|
||||
move_player,
|
||||
reset_player
|
||||
debug_game_over
|
||||
.after(move_player)
|
||||
.after(check_collision_with_player),
|
||||
)
|
||||
|
||||
+7
-3
@@ -35,10 +35,14 @@ fn spawn_depth_text(mut commands: Commands) {
|
||||
));
|
||||
}
|
||||
|
||||
// Update depth score texts
|
||||
fn update_depth_text(depth: Res<Depth>, texts: Query<&mut Text, With<DepthText>>) {
|
||||
// Update depth score text
|
||||
fn update_depth_text(
|
||||
mut commands: Commands,
|
||||
depth: Res<Depth>,
|
||||
texts: Query<&mut Text, With<DepthText>>,
|
||||
) {
|
||||
for mut text in texts {
|
||||
text.0 = format!("Score: {}", (depth.0 / 100.0).floor());
|
||||
text.0 = format!("Score: {}", depth.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user