cleanup
This commit is contained in:
+10
-103
@@ -1,7 +1,5 @@
|
|||||||
use bevy::{
|
use bevy::{
|
||||||
asset::uuid::timestamp::context,
|
|
||||||
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
||||||
math::curve::cores::ChunkedUnevenCoreError,
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use bevy_egui::{EguiContexts, EguiPrimaryContextPass, egui};
|
use bevy_egui::{EguiContexts, EguiPrimaryContextPass, egui};
|
||||||
@@ -24,9 +22,6 @@ pub struct Debug;
|
|||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct DebugCamera;
|
pub struct DebugCamera;
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
struct ViewDebugText;
|
|
||||||
|
|
||||||
fn spawn_debug_camera(mut commands: Commands) {
|
fn spawn_debug_camera(mut commands: Commands) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Debug,
|
Debug,
|
||||||
@@ -129,92 +124,6 @@ fn draw_view_frame(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
struct SeedDebugText;
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
struct FpsDebugText;
|
|
||||||
|
|
||||||
// Debug information on screen
|
|
||||||
fn spawn_debug_texts(mut commands: Commands) {
|
|
||||||
commands.spawn((
|
|
||||||
Debug,
|
|
||||||
Node {
|
|
||||||
position_type: PositionType::Absolute,
|
|
||||||
right: Val::Px(0.0),
|
|
||||||
top: Val::Px(0.0),
|
|
||||||
width: Val::Percent(17.0),
|
|
||||||
height: Val::Percent(10.0),
|
|
||||||
flex_direction: FlexDirection::Column,
|
|
||||||
row_gap: Val::Px(5.0),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
// Black background
|
|
||||||
BackgroundColor(Color::srgba(0.0, 1.0, 0.0, 0.1)),
|
|
||||||
// Texts
|
|
||||||
children![
|
|
||||||
// Seed display
|
|
||||||
(
|
|
||||||
Text::new(""),
|
|
||||||
TextFont {
|
|
||||||
font_size: FontSize::Px(20.0),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
TextColor(Color::srgb(1.0, 1.0, 0.0)),
|
|
||||||
SeedDebugText,
|
|
||||||
),
|
|
||||||
(
|
|
||||||
Text::new(""),
|
|
||||||
TextFont {
|
|
||||||
font_size: FontSize::Px(20.0),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
TextColor(Color::srgb(1.0, 1.0, 0.0)),
|
|
||||||
FpsDebugText,
|
|
||||||
),
|
|
||||||
(
|
|
||||||
Text::new(""),
|
|
||||||
TextFont {
|
|
||||||
font_size: FontSize::Px(20.0),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
TextColor(Color::srgb(1.0, 1.0, 0.0)),
|
|
||||||
ViewDebugText,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update depth score texts
|
|
||||||
fn update_seed_debug_text(
|
|
||||||
run_seed: Res<RunSeed>,
|
|
||||||
mut run_seed_debug_text: Single<&mut Text, With<SeedDebugText>>,
|
|
||||||
) {
|
|
||||||
run_seed_debug_text.0 = format!("Seed: {}", run_seed.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_fps_debug_text(
|
|
||||||
store: Res<DiagnosticsStore>,
|
|
||||||
mut fps_debug_text: Single<&mut Text, With<FpsDebugText>>,
|
|
||||||
) {
|
|
||||||
if let Some(fps) = store.get(&FrameTimeDiagnosticsPlugin::FPS) {
|
|
||||||
if let Some(value) = fps.smoothed() {
|
|
||||||
fps_debug_text.0 = format!("FPS: {:.0}", value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cleanup_debug(mut commands: Commands, entities: Query<Entity, With<Debug>>) {
|
|
||||||
for entity in entities {
|
|
||||||
commands.entity(entity).despawn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show the world rect the game camera renders
|
|
||||||
fn update_view_debug_text(mut text: Single<&mut Text, With<ViewDebugText>>) {
|
|
||||||
text.0 = format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Real time tuning movement & inertia sliders
|
// Real time tuning movement & inertia sliders
|
||||||
fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettings>) {
|
fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettings>) {
|
||||||
egui::Window::new("Movement / Inertia ").show(
|
egui::Window::new("Movement / Inertia ").show(
|
||||||
@@ -268,12 +177,12 @@ fn debug_panel(
|
|||||||
mut run_seed: ResMut<RunSeed>,
|
mut run_seed: ResMut<RunSeed>,
|
||||||
player: Single<(Entity, &Transform, &Velocity), With<Player>>,
|
player: Single<(Entity, &Transform, &Velocity), With<Player>>,
|
||||||
chunk: Query<Entity, With<Chunk>>,
|
chunk: Query<Entity, With<Chunk>>,
|
||||||
mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
||||||
mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut fall_started: ResMut<FallStarted>,
|
mut fall_started: ResMut<FallStarted>,
|
||||||
mut depth: ResMut<Depth>,
|
mut depth: ResMut<Depth>,
|
||||||
mut display_image: Single<&mut Visibility, With<DisplayImage>>,
|
display_image: Single<&mut Visibility, With<DisplayImage>>,
|
||||||
) {
|
) {
|
||||||
egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| {
|
egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| {
|
||||||
// Fps
|
// Fps
|
||||||
@@ -340,6 +249,12 @@ fn debug_panel(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cleanup_debug(mut commands: Commands, entities: Query<Entity, With<Debug>>) {
|
||||||
|
for entity in entities {
|
||||||
|
commands.entity(entity).despawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct DebugPlugin;
|
pub struct DebugPlugin;
|
||||||
|
|
||||||
impl Plugin for DebugPlugin {
|
impl Plugin for DebugPlugin {
|
||||||
@@ -350,19 +265,11 @@ impl Plugin for DebugPlugin {
|
|||||||
spawn_debug_camera,
|
spawn_debug_camera,
|
||||||
setup_debug_camera.after(spawn_debug_camera),
|
setup_debug_camera.after(spawn_debug_camera),
|
||||||
spawn_debug_frame,
|
spawn_debug_frame,
|
||||||
// spawn_debug_texts,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(
|
(draw_view_frame, follow_player_debug).run_if(in_state(GameState::InGame)),
|
||||||
draw_view_frame,
|
|
||||||
follow_player_debug,
|
|
||||||
// update_seed_debug_text,
|
|
||||||
// update_fps_debug_text,
|
|
||||||
// update_view_debug_text,
|
|
||||||
)
|
|
||||||
.run_if(in_state(GameState::InGame)),
|
|
||||||
)
|
)
|
||||||
// Egui debug
|
// Egui debug
|
||||||
.add_systems(
|
.add_systems(
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ pub struct Collider {
|
|||||||
|
|
||||||
// Check collision with Player
|
// Check collision with Player
|
||||||
pub fn check_collision_with_player(
|
pub fn check_collision_with_player(
|
||||||
player: Single<(&Transform, &Collider, &mut Sprite), With<Player>>,
|
player: Single<(&Transform, &Collider), With<Player>>,
|
||||||
obstacle: Query<(&Transform, &Collider), With<Obstacle>>,
|
obstacle: Query<(&Transform, &Collider), With<Obstacle>>,
|
||||||
mut next_state: ResMut<NextState<GameState>>,
|
mut next_state: ResMut<NextState<GameState>>,
|
||||||
) {
|
) {
|
||||||
let (player_transform, player_collider, mut _player_sprite) = player.into_inner();
|
let (player_transform, player_collider) = player.into_inner();
|
||||||
|
|
||||||
// Check whether or not each obstacles overlap the player
|
// Check whether or not each obstacles overlap the player
|
||||||
for (collider_transform, collider_collider) in obstacle {
|
for (collider_transform, collider_collider) in obstacle {
|
||||||
|
|||||||
+1
-32
@@ -9,7 +9,6 @@ use crate::config::PLAYER_HITBOX;
|
|||||||
use crate::config::START_POSITION;
|
use crate::config::START_POSITION;
|
||||||
use crate::config::VERTICAL_RATE;
|
use crate::config::VERTICAL_RATE;
|
||||||
use crate::gameplay::collision::Collider;
|
use crate::gameplay::collision::Collider;
|
||||||
use crate::gameplay::collision::check_collision_with_player;
|
|
||||||
use crate::states::GameState;
|
use crate::states::GameState;
|
||||||
|
|
||||||
// The player
|
// The player
|
||||||
@@ -126,27 +125,6 @@ pub(crate) fn move_player(
|
|||||||
transform.translation += velocity.0.extend(0.0) * dt;
|
transform.translation += velocity.0.extend(0.0) * dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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>,
|
|
||||||
mut next_state: ResMut<NextState<GameState>>, // For debug gameover state
|
|
||||||
) {
|
|
||||||
// let (mut transform, mut velocity, mut sprite) = player.into_inner();
|
|
||||||
|
|
||||||
// R key for reset or player has collider
|
|
||||||
if input.just_pressed(KeyCode::KeyG) {
|
|
||||||
// transform.translation = Vec3::new(START_POSITION.x, START_POSITION.y, START_POSITION.z);
|
|
||||||
// velocity.0 = Vec2::ZERO;
|
|
||||||
// sprite.color = Color::WHITE;
|
|
||||||
|
|
||||||
fall_started.0 = false;
|
|
||||||
next_state.set(GameState::GameOver);
|
|
||||||
// TODO: uncomment when obstacle chunk logic is implemented
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// To freeze player at the begining of the Ingame
|
// To freeze player at the begining of the Ingame
|
||||||
fn start_run(mut fall_started: ResMut<FallStarted>) {
|
fn start_run(mut fall_started: ResMut<FallStarted>) {
|
||||||
fall_started.0 = false;
|
fall_started.0 = false;
|
||||||
@@ -163,16 +141,7 @@ impl Plugin for PlayerPlugin {
|
|||||||
app.add_systems(OnEnter(GameState::InGame), (spawn_player, start_run))
|
app.add_systems(OnEnter(GameState::InGame), (spawn_player, start_run))
|
||||||
.init_resource::<FallStarted>()
|
.init_resource::<FallStarted>()
|
||||||
.init_resource::<MoveSettings>()
|
.init_resource::<MoveSettings>()
|
||||||
.add_systems(
|
.add_systems(Update, (move_player,).run_if(in_state(GameState::InGame)))
|
||||||
Update,
|
|
||||||
(
|
|
||||||
move_player,
|
|
||||||
debug_game_over
|
|
||||||
.after(move_player)
|
|
||||||
.after(check_collision_with_player),
|
|
||||||
)
|
|
||||||
.run_if(in_state(GameState::InGame)),
|
|
||||||
)
|
|
||||||
.add_systems(OnExit(GameState::InGame), cleanup_player);
|
.add_systems(OnExit(GameState::InGame), cleanup_player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use std::time::UNIX_EPOCH;
|
|
||||||
|
|
||||||
use bevy::{prelude::*, window::PresentMode};
|
use bevy::{prelude::*, window::PresentMode};
|
||||||
|
|
||||||
use bevy_egui::{EguiGlobalSettings, EguiPlugin};
|
use bevy_egui::{EguiGlobalSettings, EguiPlugin};
|
||||||
|
|||||||
+2
-2
@@ -8,9 +8,9 @@ pub enum GameState {
|
|||||||
#[default]
|
#[default]
|
||||||
MainMenu,
|
MainMenu,
|
||||||
InGame,
|
InGame,
|
||||||
// SettingsMenu,
|
|
||||||
GameOver,
|
GameOver,
|
||||||
// EscMenu
|
_SettingsMenu,
|
||||||
|
_EscMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GameStatePlugin;
|
pub struct GameStatePlugin;
|
||||||
|
|||||||
+2
-5
@@ -1,10 +1,8 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{
|
config::{CAMERAE_OFFSET, CHUNK_HEIGHT, MARGIN_ABOVE, MARGIN_BELLOW, SCREEN_HEIGHT},
|
||||||
CAMERAE_OFFSET, CHUNK_HEIGHT, MARGIN_ABOVE, MARGIN_BELLOW, SCREEN_HEIGHT, SCREEN_WIDTH,
|
gameplay::player::Player,
|
||||||
},
|
|
||||||
gameplay::{camera::MainCamera, player::Player},
|
|
||||||
states::GameState,
|
states::GameState,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -13,7 +11,6 @@ pub mod doors;
|
|||||||
pub mod generator;
|
pub mod generator;
|
||||||
pub mod grid;
|
pub mod grid;
|
||||||
pub mod obstacle;
|
pub mod obstacle;
|
||||||
pub mod rng;
|
|
||||||
pub mod validator;
|
pub mod validator;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
|
|||||||
+7
-7
@@ -1,4 +1,6 @@
|
|||||||
use crate::{config::TERRAIN_COLS, world::rng::SplitMix64, world::rng::derive};
|
use rand::{RngExt, SeedableRng, rngs::StdRng};
|
||||||
|
|
||||||
|
use crate::config::TERRAIN_COLS;
|
||||||
|
|
||||||
const SALT_DOOR: u64 = 1;
|
const SALT_DOOR: u64 = 1;
|
||||||
|
|
||||||
@@ -31,15 +33,13 @@ pub fn door(seed: u64, k: i64) -> Option<Door> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut rng = SplitMix64::new(derive(seed, k, SALT_DOOR));
|
let mut rng = StdRng::seed_from_u64(seed ^ (k as u64).wrapping_mul(SALT_DOOR));
|
||||||
|
|
||||||
// Random width
|
// Random width
|
||||||
let width = DOOR_MIN_WIDTH
|
let width = DOOR_MIN_WIDTH + rng.random_range(0..(2 * DOOR_HALF_WIDTH - DOOR_MIN_WIDTH + 1));
|
||||||
+ (rng.next_u64() % (2 * DOOR_HALF_WIDTH as u64 - DOOR_MIN_WIDTH as u64 + 1)) as i32;
|
|
||||||
|
|
||||||
// DOor stay in terrain
|
// Door stays in terrain
|
||||||
let center =
|
let center = DOOR_HALF_WIDTH + rng.random_range(0..(TERRAIN_COLS - 2 * DOOR_HALF_WIDTH));
|
||||||
DOOR_HALF_WIDTH + (rng.next_u64() % (TERRAIN_COLS - 2 * DOOR_HALF_WIDTH) as u64) as i32;
|
|
||||||
|
|
||||||
let min_col = (center - width / 2).clamp(1, TERRAIN_COLS - 1 - width);
|
let min_col = (center - width / 2).clamp(1, TERRAIN_COLS - 1 - width);
|
||||||
Some(Door {
|
Some(Door {
|
||||||
|
|||||||
+1
-28
@@ -1,15 +1,7 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
|
||||||
gameplay::collision::Collider,
|
|
||||||
world::{
|
|
||||||
Chunk,
|
|
||||||
grid::{GridRect, grid_to_world},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// const OBSTACLE_COLOR: Color = Color::srgb(0.1, 0.7, 0.3);
|
// const OBSTACLE_COLOR: Color = Color::srgb(0.1, 0.7, 0.3);
|
||||||
const DEBUG_OBSTACLE_COLOR: Color = Color::srgba(0.0, 1.0, 0.0, 1.0);
|
const _DEBUG_OBSTACLE_COLOR: Color = Color::srgba(0.0, 1.0, 0.0, 1.0);
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct Obstacle;
|
pub struct Obstacle;
|
||||||
@@ -18,23 +10,4 @@ pub fn spawn_obstacle_chunk(commands: &mut Commands, id: i64, run_seed: u64) {
|
|||||||
if id >= -1 {
|
if id >= -1 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let depth = -id;
|
|
||||||
|
|
||||||
// let data = generate_chunk(run_seed, depth);
|
|
||||||
|
|
||||||
// for rect in data.rects {
|
|
||||||
// spawn_rect(commands, id, rect);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn spawn_rect(commands: &mut Commands, id: i64, rect: GridRect) {
|
|
||||||
let (center, size) = grid_to_world(id, rect);
|
|
||||||
commands.spawn((
|
|
||||||
Chunk { id },
|
|
||||||
Obstacle,
|
|
||||||
// Collider { size },
|
|
||||||
Sprite::from_color(DEBUG_OBSTACLE_COLOR, size),
|
|
||||||
Transform::from_xyz(center.x, center.y, 0.5),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
// Pseudo random generator SplitMix64
|
|
||||||
|
|
||||||
pub const GENERATOR_VERSION: u32 = 1;
|
|
||||||
|
|
||||||
const MIX_GAMMA: u64 = 0x9E37_79B9_7F4A_7C15;
|
|
||||||
const MIX_1: u64 = 0xBF58_476D_1CE4_E5B9;
|
|
||||||
const MIX_2: u64 = 0x94D0_49BB_1331_11EB;
|
|
||||||
|
|
||||||
fn splitmix64_mix(mut z: u64) -> u64 {
|
|
||||||
z = (z ^ (z >> 30)).wrapping_mul(MIX_1);
|
|
||||||
z = (z ^ (z >> 27)).wrapping_mul(MIX_2);
|
|
||||||
z ^ (z >> 31)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SplitMix64 {
|
|
||||||
state: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SplitMix64 {
|
|
||||||
pub fn new(seed: u64) -> Self {
|
|
||||||
Self { state: seed }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_u64(&mut self) -> u64 {
|
|
||||||
self.state = self.state.wrapping_add(MIX_GAMMA);
|
|
||||||
splitmix64_mix(self.state)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn derive(seed: u64, index: i64, salt: u64) -> u64 {
|
|
||||||
splitmix64_mix(seed ^ (index as u64).wrapping_mul(MIX_GAMMA) ^ salt.rotate_left(32))
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user