Compare commits
9
Commits
c27897802a
...
bf9ef34bf8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf9ef34bf8 | ||
|
|
504c8f2191 | ||
|
|
6480ea585a | ||
|
|
1946458807 | ||
|
|
c043487079 | ||
|
|
d8799c1f58 | ||
|
|
9ed562735e | ||
|
|
8d24093585 | ||
|
|
a31e1c3b98 |
@@ -40,6 +40,7 @@
|
|||||||
- Wind that creates a force on the player
|
- Wind that creates a force on the player
|
||||||
- Reverse fall (fall on the side or up rather than down, maybe invert the controls)
|
- Reverse fall (fall on the side or up rather than down, maybe invert the controls)
|
||||||
- 3D moment ??
|
- 3D moment ??
|
||||||
|
- Magnets wall (mandatory to be against a wall)
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
- Camera adapts to screen...
|
- Camera adapts to screen...
|
||||||
|
|||||||
Binary file not shown.
+4
-4
@@ -6,9 +6,9 @@ pub const SCREEN_HEIGHT: f32 = 1080.0;
|
|||||||
pub const SCREEN_ASPECT: f32 = SCREEN_WIDTH / SCREEN_HEIGHT; // 2:3
|
pub const SCREEN_ASPECT: f32 = SCREEN_WIDTH / SCREEN_HEIGHT; // 2:3
|
||||||
|
|
||||||
// Grid
|
// Grid
|
||||||
pub const CELL_SIZE: f32 = 32.0;
|
pub const CELL_SIZE: f32 = 16.0;
|
||||||
pub const TERRAIN_COLS: i32 = 21;
|
pub const TERRAIN_COLS: i32 = 45;
|
||||||
pub const CHUNK_ROWS: i32 = 32;
|
pub const CHUNK_ROWS: i32 = 64;
|
||||||
|
|
||||||
pub const TERRAIN_WIDTH: f32 = CELL_SIZE * TERRAIN_COLS as f32;
|
pub const TERRAIN_WIDTH: f32 = CELL_SIZE * TERRAIN_COLS as f32;
|
||||||
pub const HALF_TERRAIN_WIDTH: f32 = TERRAIN_WIDTH / 2.0;
|
pub const HALF_TERRAIN_WIDTH: f32 = TERRAIN_WIDTH / 2.0;
|
||||||
@@ -19,7 +19,7 @@ pub const MARGIN_ABOVE: f32 = 400.0;
|
|||||||
pub const MARGIN_BELLOW: f32 = 400.0;
|
pub const MARGIN_BELLOW: f32 = 400.0;
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
pub const PLAYER_HITBOX: Vec2 = Vec2::new(20.0, 40.0);
|
pub const PLAYER_HITBOX: Vec2 = Vec2::new(16.0, 32.0);
|
||||||
pub const FALL_SPEED: f32 = 500.0;
|
pub const FALL_SPEED: f32 = 500.0;
|
||||||
pub const DIVE_SPEED: f32 = 2000.0;
|
pub const DIVE_SPEED: f32 = 2000.0;
|
||||||
pub const HORIZONTAL_SPEED: f32 = 400.0;
|
pub const HORIZONTAL_SPEED: f32 = 400.0;
|
||||||
|
|||||||
+120
-104
@@ -8,10 +8,12 @@ use crate::{
|
|||||||
config::{SCREEN_HEIGHT, SCREEN_WIDTH},
|
config::{SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||||
gameplay::{
|
gameplay::{
|
||||||
camera::MainCamera,
|
camera::MainCamera,
|
||||||
player::{MoveSettings, Player},
|
player::{FallStarted, MoveSettings, Player, Velocity, spawn_player},
|
||||||
|
score::Depth,
|
||||||
},
|
},
|
||||||
|
screen::DisplayImage,
|
||||||
states::GameState,
|
states::GameState,
|
||||||
world::RunSeed,
|
world::{Chunk, RunSeed},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@@ -20,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,
|
||||||
@@ -30,6 +29,7 @@ fn spawn_debug_camera(mut commands: Commands) {
|
|||||||
Camera2d,
|
Camera2d,
|
||||||
Camera {
|
Camera {
|
||||||
is_active: false,
|
is_active: false,
|
||||||
|
order: 2,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
@@ -42,13 +42,17 @@ fn setup_debug_camera(mut camera: Single<&mut Projection, With<DebugCamera>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_debug_camera(
|
fn toggle_debug_camera(
|
||||||
input: Res<ButtonInput<KeyCode>>,
|
|
||||||
mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
||||||
mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||||
|
mut display_image: Single<&mut Visibility, With<DisplayImage>>,
|
||||||
) {
|
) {
|
||||||
if input.just_pressed(KeyCode::Tab) {
|
|
||||||
main_camera.is_active = !main_camera.is_active;
|
main_camera.is_active = !main_camera.is_active;
|
||||||
debug_camera.is_active = !debug_camera.is_active;
|
debug_camera.is_active = !debug_camera.is_active;
|
||||||
|
|
||||||
|
if debug_camera.is_active {
|
||||||
|
**display_image = Visibility::Hidden;
|
||||||
|
} else {
|
||||||
|
**display_image = Visibility::Visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,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(
|
||||||
@@ -227,10 +145,116 @@ fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettin
|
|||||||
ui.add(
|
ui.add(
|
||||||
egui::Slider::new(&mut settings.vertical_rate, 0.0..=10000.0).text("Vertical rate"),
|
egui::Slider::new(&mut settings.vertical_rate, 0.0..=10000.0).text("Vertical rate"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
if ui.button("Reset").clicked() {
|
||||||
|
*settings = MoveSettings::default();
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
let export_text = format!(
|
||||||
|
"pub const FALL_SPEED: f32 = {:.0};\npub const DIVE_SPEED: f32 = {:.0};\npub const HORIZONTAL_SPEED: f32 = {:.0};\npub const HORIZONTAL_ACCEL: f32 = {:.0};\npub const HORIZONTAL_FRICTION: f32 = {:.0};\npub const VERTICAL_RATE: f32 = {:.0};",
|
||||||
|
settings.fall_speed,
|
||||||
|
settings.dive_speed,
|
||||||
|
settings.horizontal_speed,
|
||||||
|
settings.horizontal_accel,
|
||||||
|
settings.horizontal_friction,
|
||||||
|
settings.vertical_rate,
|
||||||
|
);
|
||||||
|
// ui.monospace(&export_text);
|
||||||
|
if ui.button("Copy -> config.rs").clicked() {
|
||||||
|
ui.ctx().copy_text(export_text);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn debug_panel(
|
||||||
|
mut contexts: EguiContexts,
|
||||||
|
store: Res<DiagnosticsStore>,
|
||||||
|
mut run_seed: ResMut<RunSeed>,
|
||||||
|
player: Single<(Entity, &Transform, &Velocity), With<Player>>,
|
||||||
|
chunk: Query<Entity, With<Chunk>>,
|
||||||
|
main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
||||||
|
debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||||
|
mut commands: Commands,
|
||||||
|
mut fall_started: ResMut<FallStarted>,
|
||||||
|
mut depth: ResMut<Depth>,
|
||||||
|
display_image: Single<&mut Visibility, With<DisplayImage>>,
|
||||||
|
) {
|
||||||
|
egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| {
|
||||||
|
// Fps
|
||||||
|
let fps = store
|
||||||
|
.get(&FrameTimeDiagnosticsPlugin::FPS)
|
||||||
|
.and_then(|diagnostic| diagnostic.smoothed());
|
||||||
|
|
||||||
|
match fps {
|
||||||
|
Some(fps) => ui.label(format!("FPS: {fps:.0}")),
|
||||||
|
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}"));
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
let state = if debug_camera.is_active { "ON" } else { "OFF" };
|
||||||
|
if ui.button(format!("Debug camera: {state}")).clicked() {
|
||||||
|
toggle_debug_camera(main_camera, debug_camera, display_image);
|
||||||
|
}
|
||||||
|
|
||||||
|
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::<u64>();
|
||||||
|
}
|
||||||
|
fall_started.0 = false;
|
||||||
|
depth.0 = 0.0;
|
||||||
|
|
||||||
|
commands.entity(player_entity).despawn();
|
||||||
|
|
||||||
|
spawn_player(commands);
|
||||||
|
}
|
||||||
|
// TODO: Add colidbox On/Off button
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
@@ -241,24 +265,16 @@ 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,
|
|
||||||
toggle_debug_camera,
|
|
||||||
update_seed_debug_text,
|
|
||||||
update_fps_debug_text,
|
|
||||||
update_view_debug_text,
|
|
||||||
)
|
|
||||||
.run_if(in_state(GameState::InGame)),
|
|
||||||
)
|
)
|
||||||
|
// Egui debug
|
||||||
.add_systems(
|
.add_systems(
|
||||||
EguiPrimaryContextPass,
|
EguiPrimaryContextPass,
|
||||||
move_tuning_panel.run_if(in_state(GameState::InGame)),
|
(move_tuning_panel, debug_panel).run_if(in_state(GameState::InGame)),
|
||||||
)
|
)
|
||||||
.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
||||||
.add_systems(OnExit(GameState::InGame), cleanup_debug);
|
.add_systems(OnExit(GameState::InGame), cleanup_debug);
|
||||||
|
|||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
use bevy::{asset::AssetApp, prelude::*, text::Font};
|
||||||
|
|
||||||
|
const COZETTE_BYTES: &[u8] = include_bytes!("../assets/fonts/CozetteVector.ttf");
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub struct GameFont(pub Handle<Font>);
|
||||||
|
|
||||||
|
pub struct FontPlugin;
|
||||||
|
|
||||||
|
impl Plugin for FontPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.init_asset::<Font>();
|
||||||
|
|
||||||
|
let handle = {
|
||||||
|
let mut fonts = app.world_mut().resource_mut::<Assets<Font>>();
|
||||||
|
fonts.add(Font::from_bytes(COZETTE_BYTES.to_vec()))
|
||||||
|
};
|
||||||
|
|
||||||
|
app.insert_resource(GameFont(handle));
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-2
@@ -2,7 +2,10 @@ use bevy::prelude::*;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::HALF_TERRAIN_WIDTH,
|
config::HALF_TERRAIN_WIDTH,
|
||||||
gameplay::{collision::Collider, player::Player},
|
gameplay::{
|
||||||
|
collision::Collider,
|
||||||
|
player::{Player, move_player},
|
||||||
|
},
|
||||||
states::GameState,
|
states::GameState,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -18,6 +21,11 @@ pub struct BoundsPlugin;
|
|||||||
|
|
||||||
impl Plugin for BoundsPlugin {
|
impl Plugin for BoundsPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Update, constrain_player.run_if(in_state(GameState::InGame)));
|
app.add_systems(
|
||||||
|
Update,
|
||||||
|
constrain_player
|
||||||
|
.after(move_player)
|
||||||
|
.run_if(in_state(GameState::InGame)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
+3
-34
@@ -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
|
||||||
@@ -18,14 +17,14 @@ pub struct Player;
|
|||||||
|
|
||||||
// Speed of the player
|
// Speed of the player
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct Velocity(Vec2);
|
pub struct Velocity(pub Vec2);
|
||||||
|
|
||||||
// Falling bool
|
// Falling bool
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
pub struct FallStarted(pub bool);
|
pub struct FallStarted(pub bool);
|
||||||
|
|
||||||
// Spawn entity player
|
// Spawn entity player
|
||||||
fn spawn_player(mut commands: Commands) {
|
pub fn spawn_player(mut commands: Commands) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Player,
|
Player,
|
||||||
Collider {
|
Collider {
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use bevy::prelude::*;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::START_POSITION,
|
config::START_POSITION,
|
||||||
|
font::GameFont,
|
||||||
gameplay::player::{Player, move_player},
|
gameplay::player::{Player, move_player},
|
||||||
states::GameState,
|
states::GameState,
|
||||||
};
|
};
|
||||||
@@ -18,11 +19,12 @@ fn update_depth(mut depth: ResMut<Depth>, player: Single<&Transform, With<Player
|
|||||||
pub struct DepthText;
|
pub struct DepthText;
|
||||||
|
|
||||||
// Display the initial text of the depth (Score)
|
// Display the initial text of the depth (Score)
|
||||||
fn spawn_depth_text(mut commands: Commands) {
|
fn spawn_depth_text(mut commands: Commands, game_font: Res<GameFont>) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Text::new("0"),
|
Text::new(""),
|
||||||
TextFont {
|
TextFont {
|
||||||
font_size: FontSize::Px(50.0),
|
font: FontSource::Handle(game_font.0.clone()),
|
||||||
|
font_size: FontSize::Px(60.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor(Color::WHITE),
|
TextColor(Color::WHITE),
|
||||||
@@ -39,7 +41,7 @@ fn spawn_depth_text(mut commands: Commands) {
|
|||||||
// Update depth score texts
|
// Update depth score texts
|
||||||
fn update_depth_text(depth: Res<Depth>, texts: Query<&mut Text, With<DepthText>>) {
|
fn update_depth_text(depth: Res<Depth>, texts: Query<&mut Text, With<DepthText>>) {
|
||||||
for mut text in texts {
|
for mut text in texts {
|
||||||
text.0 = format!("Score: {}", (depth.0 / 100.0).floor());
|
text.0 = format!("{}", (depth.0 / 100.0).floor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use bevy_egui::{EguiGlobalSettings, EguiPlugin};
|
|||||||
|
|
||||||
use crate::config::{SCREEN_HEIGHT, SCREEN_WIDTH};
|
use crate::config::{SCREEN_HEIGHT, SCREEN_WIDTH};
|
||||||
use crate::debug::DebugPlugin;
|
use crate::debug::DebugPlugin;
|
||||||
|
use crate::font::FontPlugin;
|
||||||
use crate::gameplay::bounds::BoundsPlugin;
|
use crate::gameplay::bounds::BoundsPlugin;
|
||||||
use crate::gameplay::camera::CameraPlugin;
|
use crate::gameplay::camera::CameraPlugin;
|
||||||
use crate::gameplay::collision::CollisionPlugin;
|
use crate::gameplay::collision::CollisionPlugin;
|
||||||
@@ -17,6 +18,7 @@ use crate::world::WorldPlugin;
|
|||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod debug;
|
mod debug;
|
||||||
|
mod font;
|
||||||
mod gameplay;
|
mod gameplay;
|
||||||
mod screen;
|
mod screen;
|
||||||
mod states;
|
mod states;
|
||||||
@@ -38,6 +40,7 @@ fn main() {
|
|||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
}))
|
}))
|
||||||
|
.add_plugins(FontPlugin) // Font
|
||||||
.add_plugins(PlayerPlugin) // Player
|
.add_plugins(PlayerPlugin) // Player
|
||||||
.add_plugins(ScreenPlugin) // Virtual screen
|
.add_plugins(ScreenPlugin) // Virtual screen
|
||||||
.add_plugins(CameraPlugin) // Camera
|
.add_plugins(CameraPlugin) // Camera
|
||||||
@@ -48,6 +51,7 @@ fn main() {
|
|||||||
.add_plugins(GameStatePlugin) // Game states
|
.add_plugins(GameStatePlugin) // Game states
|
||||||
.add_plugins(MainMenuPlugin) // Main Menu
|
.add_plugins(MainMenuPlugin) // Main Menu
|
||||||
.add_plugins(GameOverPlugin) // GameOver
|
.add_plugins(GameOverPlugin) // GameOver
|
||||||
|
// Debug UI
|
||||||
.insert_resource(EguiGlobalSettings {
|
.insert_resource(EguiGlobalSettings {
|
||||||
auto_create_primary_context: false,
|
auto_create_primary_context: false,
|
||||||
..default()
|
..default()
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ fn spawn_virtual_screen(mut commands: Commands, mut images: ResMut<Assets<Image>
|
|||||||
DisplayImage,
|
DisplayImage,
|
||||||
Sprite::from_image(game_image),
|
Sprite::from_image(game_image),
|
||||||
Transform::default(),
|
Transform::default(),
|
||||||
|
Visibility::Visible,
|
||||||
RenderLayers::layer(1),
|
RenderLayers::layer(1),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
+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;
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{gameplay::camera::MainCamera, states::GameState, world::RunSeed};
|
use crate::{font::GameFont, gameplay::camera::MainCamera, states::GameState, world::RunSeed};
|
||||||
|
|
||||||
// To delete game over's components
|
// To delete game over's components
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct GameOver;
|
pub struct GameOver;
|
||||||
|
|
||||||
fn game_over(mut commands: Commands, mut main_camera: Single<&mut Camera, With<MainCamera>>) {
|
fn game_over(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut main_camera: Single<&mut Camera, With<MainCamera>>,
|
||||||
|
game_font: Res<GameFont>,
|
||||||
|
) {
|
||||||
main_camera.is_active = true;
|
main_camera.is_active = true;
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
@@ -27,6 +31,7 @@ fn game_over(mut commands: Commands, mut main_camera: Single<&mut Camera, With<M
|
|||||||
(
|
(
|
||||||
Text::new("GAME OVER"),
|
Text::new("GAME OVER"),
|
||||||
TextFont {
|
TextFont {
|
||||||
|
font: FontSource::Handle(game_font.0.clone()),
|
||||||
font_size: FontSize::Px(120.0),
|
font_size: FontSize::Px(120.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
@@ -34,6 +39,7 @@ fn game_over(mut commands: Commands, mut main_camera: Single<&mut Camera, With<M
|
|||||||
(
|
(
|
||||||
Text::new("N new map | R restart | T main menu"),
|
Text::new("N new map | R restart | T main menu"),
|
||||||
TextFont {
|
TextFont {
|
||||||
|
font: FontSource::Handle(game_font.0.clone()),
|
||||||
font_size: FontSize::Px(40.0),
|
font_size: FontSize::Px(40.0),
|
||||||
..default()
|
..default()
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-7
@@ -1,12 +1,12 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{gameplay::camera::MainCamera, states::GameState};
|
use crate::{font::GameFont, gameplay::camera::MainCamera, states::GameState};
|
||||||
|
|
||||||
// To delete menu's components
|
// To delete menu's components
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct MainMenu;
|
pub struct MainMenu;
|
||||||
|
|
||||||
fn main_menu(mut commands: Commands) {
|
fn main_menu(mut commands: Commands, game_font: Res<GameFont>) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
MainMenu,
|
MainMenu,
|
||||||
Node {
|
Node {
|
||||||
@@ -23,19 +23,62 @@ fn main_menu(mut commands: Commands) {
|
|||||||
// Texts
|
// Texts
|
||||||
children![
|
children![
|
||||||
(
|
(
|
||||||
Text::new("DOWN INTO THE VOID"),
|
Text::new("DOWN INTO"),
|
||||||
TextFont {
|
TextFont {
|
||||||
font_size: FontSize::Px(120.0),
|
font: FontSource::Handle(game_font.0.clone()),
|
||||||
|
font_size: FontSize::Px(100.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
Node {
|
||||||
|
margin: UiRect::bottom(Val::Px(-30.0)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Text::new("Press Enter to fall into the void"),
|
Text::new("THE VOID"),
|
||||||
TextFont {
|
TextFont {
|
||||||
|
font: FontSource::Handle(game_font.0.clone()),
|
||||||
|
font_size: FontSize::Px(100.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
Node {
|
||||||
|
margin: UiRect::bottom(Val::Px(40.0)),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Node {
|
||||||
|
flex_direction: FlexDirection::Row,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
children![
|
||||||
|
(
|
||||||
|
Text::new("Press "),
|
||||||
|
TextFont {
|
||||||
|
font: FontSource::Handle(game_font.0.clone()),
|
||||||
font_size: FontSize::Px(40.0),
|
font_size: FontSize::Px(40.0),
|
||||||
..default()
|
..default()
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
|
(
|
||||||
|
Text::new("Enter"),
|
||||||
|
TextFont {
|
||||||
|
font: FontSource::Handle(game_font.0.clone()),
|
||||||
|
font_size: FontSize::Px(40.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
TextColor(Color::srgb(1.0, 1.0, 0.0)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Text::new(" to fall"),
|
||||||
|
TextFont {
|
||||||
|
font: FontSource::Handle(game_font.0.clone()),
|
||||||
|
font_size: FontSize::Px(40.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
+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)]
|
||||||
|
|||||||
+51
-20
@@ -1,36 +1,67 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{CHUNK_ROWS, TERRAIN_COLS},
|
config::{
|
||||||
world::{
|
CELL_SIZE, CHUNK_HEIGHT, CHUNK_ROWS, HALF_TERRAIN_WIDTH, TERRAIN_COLS, TERRAIN_WIDTH,
|
||||||
Chunk,
|
|
||||||
grid::{GridRect, grid_to_world},
|
|
||||||
},
|
},
|
||||||
|
world::Chunk,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Test checkboard background
|
const GRID_COLOR: Color = Color::srgb(0.22, 0.25, 0.30);
|
||||||
|
const EDGE_COLOR: Color = Color::srgb(0.40, 0.45, 0.55);
|
||||||
|
|
||||||
const COLOR_A: Color = Color::srgb(0.0, 0.0, 0.0);
|
const LINE_THICKNESS: f32 = 1.0;
|
||||||
const COLOR_B: Color = Color::srgb(0.6, 0.2, 0.8);
|
const CHUNK_BORDER_THICKNESS: f32 = 3.0;
|
||||||
|
|
||||||
pub fn spawn_background_chunk(commands: &mut Commands, id: i64) {
|
|
||||||
for row in 0..CHUNK_ROWS {
|
|
||||||
for col in 0..TERRAIN_COLS {
|
|
||||||
let global_row = id * CHUNK_ROWS as i64 + row as i64;
|
|
||||||
|
|
||||||
let color = if (global_row + col as i64) % 2 == 0 {
|
|
||||||
COLOR_A
|
|
||||||
} else {
|
|
||||||
COLOR_B
|
|
||||||
};
|
|
||||||
|
|
||||||
let (center, size) = grid_to_world(id, GridRect::cell(col, row));
|
|
||||||
|
|
||||||
|
// Thin line sprite
|
||||||
|
fn spawn_line(commands: &mut Commands, id: i64, center: Vec2, size: Vec2, color: Color) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Chunk { id },
|
Chunk { id },
|
||||||
Sprite::from_color(color, size),
|
Sprite::from_color(color, size),
|
||||||
Transform::from_xyz(center.x, center.y, 0.0),
|
Transform::from_xyz(center.x, center.y, 0.0),
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grid lines background
|
||||||
|
pub fn spawn_background_chunk(commands: &mut Commands, id: i64) {
|
||||||
|
let y0 = CHUNK_HEIGHT * id as f32;
|
||||||
|
let x0 = -HALF_TERRAIN_WIDTH;
|
||||||
|
|
||||||
|
// Horizontal lines
|
||||||
|
for row in 0..=CHUNK_ROWS {
|
||||||
|
let is_edge = row == 0 || row == CHUNK_ROWS;
|
||||||
|
spawn_line(
|
||||||
|
commands,
|
||||||
|
id,
|
||||||
|
Vec2::new(0.0, y0 + row as f32 * CELL_SIZE),
|
||||||
|
Vec2::new(
|
||||||
|
TERRAIN_WIDTH,
|
||||||
|
if is_edge {
|
||||||
|
CHUNK_BORDER_THICKNESS
|
||||||
|
} else {
|
||||||
|
LINE_THICKNESS
|
||||||
|
},
|
||||||
|
),
|
||||||
|
if is_edge { EDGE_COLOR } else { GRID_COLOR },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vertical lines
|
||||||
|
for col in 0..=TERRAIN_COLS {
|
||||||
|
let is_edge = col == 0 || col == TERRAIN_COLS;
|
||||||
|
spawn_line(
|
||||||
|
commands,
|
||||||
|
id,
|
||||||
|
Vec2::new(x0 + col as f32 * CELL_SIZE, y0 + CHUNK_HEIGHT / 2.0),
|
||||||
|
Vec2::new(
|
||||||
|
if is_edge {
|
||||||
|
CHUNK_BORDER_THICKNESS
|
||||||
|
} else {
|
||||||
|
LINE_THICKNESS
|
||||||
|
},
|
||||||
|
CHUNK_HEIGHT,
|
||||||
|
),
|
||||||
|
if is_edge { EDGE_COLOR } else { GRID_COLOR },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+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
-29
@@ -1,16 +1,7 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
|
||||||
gameplay::collision::Collider,
|
|
||||||
world::{
|
|
||||||
Chunk,
|
|
||||||
generator::generate_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;
|
||||||
@@ -19,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