diff --git a/src/debug.rs b/src/debug.rs index cecabeb..3161b6b 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -1,6 +1,7 @@ use bevy::{ asset::uuid::timestamp::context, diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, + math::curve::cores::ChunkedUnevenCoreError, prelude::*, }; use bevy_egui::{EguiContexts, EguiPrimaryContextPass, egui}; @@ -9,10 +10,11 @@ use crate::{ config::{SCREEN_HEIGHT, SCREEN_WIDTH}, gameplay::{ camera::MainCamera, - player::{MoveSettings, Player}, + player::{FallStarted, MoveSettings, Player, Velocity, spawn_player}, + score::Depth, }, states::GameState, - world::RunSeed, + world::{Chunk, RunSeed}, }; #[derive(Component)] @@ -210,9 +212,14 @@ fn update_view_debug_text(mut text: Single<&mut Text, With>) { fn debug_panel( mut contexts: EguiContexts, store: Res, - run_seed: Res, + mut run_seed: ResMut, + player: Single<(Entity, &Transform, &Velocity), With>, + chunk: Query>, mut main_camera: Single<&mut Camera, (With, Without)>, mut debug_camera: Single<&mut Camera, (With, Without)>, + mut commands: Commands, + mut fall_started: ResMut, + mut depth: ResMut, ) { egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| { // Fps @@ -225,8 +232,28 @@ fn debug_panel( None => ui.label("FPS: -"), }; + // Frame time in ms + match store + .get(&FrameTimeDiagnosticsPlugin::FRAME_TIME) + .and_then(|d| d.smoothed()) + { + Some(ms) => ui.label(format!("Frame: {ms:.2} ms")), + None => ui.label("Frame : - ms"), + }; + // Run seed ui.label(format!("Seed: {}", run_seed.0)); + + let (player_entity, transform, velocity) = *player; + ui.label(format!( + "Position: ({:.0}, {:.0})", + transform.translation.x, transform.translation.y + )); + ui.label(format!( + "Velocity: ({:.0},{:.0})", + velocity.0.x, velocity.0.y + )); + // Resolution ui.label(format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}")); @@ -237,6 +264,25 @@ fn debug_panel( main_camera.is_active = !main_camera.is_active; debug_camera.is_active = !debug_camera.is_active; } + + ui.separator(); + + let restart = ui.button("Restart (same seed)").clicked(); + let new_map = ui.button("Restart (new map)").clicked(); + if restart || new_map { + for entity in chunk.iter() { + commands.entity(entity).despawn(); + } + if new_map { + run_seed.0 = rand::random::(); + } + fall_started.0 = false; + depth.0 = 0.0; + + commands.entity(player_entity).despawn(); + + spawn_player(commands); + } }); } @@ -267,6 +313,22 @@ fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut config.rs").clicked() { + ui.ctx().copy_text(export_text); + } }, ); } diff --git a/src/gameplay/player.rs b/src/gameplay/player.rs index 1a51429..118c6b9 100644 --- a/src/gameplay/player.rs +++ b/src/gameplay/player.rs @@ -18,14 +18,14 @@ pub struct Player; // Speed of the player #[derive(Component)] -pub struct Velocity(Vec2); +pub struct Velocity(pub Vec2); // Falling bool #[derive(Resource, Default)] pub struct FallStarted(pub bool); // Spawn entity player -fn spawn_player(mut commands: Commands) { +pub fn spawn_player(mut commands: Commands) { commands.spawn(( Player, Collider {