From d6e4c06d7e27d6ea66fe53d0f429cc6407a05bb2 Mon Sep 17 00:00:00 2001 From: zefad Date: Sat, 19 Sep 2026 21:44:14 +0200 Subject: [PATCH] lots of adds --- src/config.rs | 20 ++- src/debug.rs | 27 +++- src/gameplay/camera.rs | 17 +- src/main.rs | 11 +- src/screen.rs | 81 ++++++++++ src/states/game_over.rs | 1 - src/world.rs | 29 ++-- src/world/doors.rs | 4 +- src/world/generator.rs | 335 ++++++++++++++++++++++++++++++++++++++++ src/world/obstacle.rs | 37 +++++ src/world/rng.rs | 2 +- src/world/validator.rs | 105 +++++++++++++ 12 files changed, 630 insertions(+), 39 deletions(-) create mode 100644 src/screen.rs create mode 100644 src/world/generator.rs create mode 100644 src/world/validator.rs diff --git a/src/config.rs b/src/config.rs index 2bf01f2..cffbcbb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,13 @@ use bevy::prelude::*; +// Fixed game screen +pub const SCREEN_WIDTH: f32 = 720.0; +pub const SCREEN_HEIGHT: f32 = 1080.0; +pub const SCREEN_ASPECT: f32 = SCREEN_WIDTH / SCREEN_HEIGHT; // 2:3 + // Grid pub const CELL_SIZE: f32 = 32.0; -pub const TERRAIN_COLS: i32 = 60; +pub const TERRAIN_COLS: i32 = 21; pub const CHUNK_ROWS: i32 = 32; pub const TERRAIN_WIDTH: f32 = CELL_SIZE * TERRAIN_COLS as f32; @@ -15,7 +20,14 @@ pub const MARGIN_BELLOW: f32 = 400.0; // Player pub const PLAYER_HITBOX: Vec2 = Vec2::new(20.0, 40.0); -pub const FALL_SPEED: f32 = 600.0; -pub const DIVE_SPEED: f32 = 1000.0; -pub const HORIZONTAL_SPEED: f32 = 500.0; +pub const FALL_SPEED: f32 = 500.0; +pub const DIVE_SPEED: f32 = 2700.0; +pub const HORIZONTAL_SPEED: f32 = 450.0; pub const START_POSITION: Vec3 = Vec3::new(0.0, 0.0, 2.0); +pub const CAMERAE_OFFSET: f32 = 280.0; + +// Validator +pub const INERTIA_MARGIN: f32 = 4.0; +pub const DESIGN_LATERAL_SPEED_RATIO: f32 = 0.6; +pub const DESIGN_SLOPE_COLS_PER_ROW: f32 = + HORIZONTAL_SPEED * DESIGN_LATERAL_SPEED_RATIO / FALL_SPEED; diff --git a/src/debug.rs b/src/debug.rs index 646b25d..72caf66 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -4,6 +4,7 @@ use bevy::{ }; use crate::{ + config::{SCREEN_HEIGHT, SCREEN_WIDTH}, gameplay::{camera::MainCamera, player::Player}, states::GameState, world::RunSeed, @@ -15,6 +16,9 @@ pub struct Debug; #[derive(Component)] pub struct DebugCamera; +#[derive(Component)] +struct ViewDebugText; + fn spawn_debug_camera(mut commands: Commands) { commands.spawn(( Debug, @@ -69,8 +73,8 @@ fn spawn_debug_frame(mut commands: Commands) { FrameSide::Right, ] { let size = match side { - FrameSide::Top | FrameSide::Bottom => Vec2::new(1936.0, 8.0), - FrameSide::Left | FrameSide::Right => Vec2::new(8.0, 1096.0), + FrameSide::Top | FrameSide::Bottom => Vec2::new(SCREEN_WIDTH + 16.0, 8.0), + FrameSide::Left | FrameSide::Right => Vec2::new(8.0, SCREEN_HEIGHT + 16.0), }; commands.spawn(( @@ -91,8 +95,8 @@ fn draw_view_frame( >, ) { let center = main_camera.translation; - let half_width = 960.0; - let half_height = 540.0; + let half_width = SCREEN_WIDTH / 2.0; + let half_height = SCREEN_HEIGHT / 2.0; let visible = if debug_camera.is_active { Visibility::Visible @@ -154,6 +158,15 @@ fn spawn_debug_texts(mut commands: Commands) { }, 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, ) ], )); @@ -184,6 +197,11 @@ fn cleanup_debug(mut commands: Commands, entities: Query>) { } } +// Show the world rect the game camera renders +fn update_view_debug_text(mut text: Single<&mut Text, With>) { + text.0 = format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}"); +} + pub struct DebugPlugin; impl Plugin for DebugPlugin { @@ -205,6 +223,7 @@ impl Plugin for DebugPlugin { toggle_debug_camera, update_seed_debug_text, update_fps_debug_text, + update_view_debug_text, ) .run_if(in_state(GameState::InGame)), ) diff --git a/src/gameplay/camera.rs b/src/gameplay/camera.rs index 8323d65..0cb9fcc 100644 --- a/src/gameplay/camera.rs +++ b/src/gameplay/camera.rs @@ -1,24 +1,18 @@ use bevy::prelude::*; -use crate::gameplay::player::Player; -use crate::gameplay::player::move_player; +use crate::config::CAMERAE_OFFSET; +use crate::gameplay::player::{Player, move_player}; use crate::states::GameState; + #[derive(Component)] pub struct MainCamera; -fn spawn_main_camera(mut commands: Commands) { - commands.spawn((Camera2d, MainCamera, IsDefaultUiCamera)); -} - // Follow the player with the camera fn follow_player( player: Single<&Transform, (With, Without)>, mut camera: Single<&mut Transform, (With, Without)>, - // time: Res