mirror of
https://github.com/kristoferssolo/maze-ascension.git
synced 2025-10-21 19:20:34 +00:00
fix(floor): issue #29
This commit is contained in:
parent
95b173c504
commit
4d37a547ff
@ -32,11 +32,7 @@ pub fn spawn_floor(
|
|||||||
|
|
||||||
commands.queue(SpawnMaze {
|
commands.queue(SpawnMaze {
|
||||||
floor: target_floor,
|
floor: target_floor,
|
||||||
config: MazeConfig {
|
config: MazeConfig::from_self(config),
|
||||||
start_pos: config.end_pos,
|
|
||||||
radius: config.radius + 1,
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,20 +52,12 @@ impl MazeConfig {
|
|||||||
global_config: &GlobalMazeConfig,
|
global_config: &GlobalMazeConfig,
|
||||||
start_pos: Option<Hex>,
|
start_pos: Option<Hex>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let seed = seed.unwrap_or_else(|| thread_rng().gen());
|
let (seed, mut rng) = setup_rng(seed);
|
||||||
let mut rng = StdRng::seed_from_u64(seed);
|
|
||||||
|
|
||||||
let start_pos = start_pos.unwrap_or_else(|| generate_pos(radius, &mut rng));
|
let start_pos = start_pos.unwrap_or_else(|| generate_pos(radius, &mut rng));
|
||||||
|
|
||||||
// Generate end position ensuring start and end are different
|
// Generate end position ensuring start and end are different
|
||||||
let mut end_pos;
|
let end_pos = generate_end_pos(radius, start_pos, &mut rng);
|
||||||
loop {
|
|
||||||
end_pos = generate_pos(radius, &mut rng);
|
|
||||||
if start_pos != end_pos {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dbg!(seed, start_pos, end_pos);
|
|
||||||
|
|
||||||
let layout = HexLayout {
|
let layout = HexLayout {
|
||||||
orientation,
|
orientation,
|
||||||
@ -82,12 +74,35 @@ impl MazeConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_self(config: &Self) -> Self {
|
||||||
|
let start_pos = config.end_pos;
|
||||||
|
let (seed, mut rng) = setup_rng(None);
|
||||||
|
|
||||||
|
let end_pos = generate_end_pos(config.radius, start_pos, &mut rng);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
radius: config.radius + 1,
|
||||||
|
start_pos,
|
||||||
|
end_pos,
|
||||||
|
seed,
|
||||||
|
layout: config.layout.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Updates the maze configuration with new global settings.
|
/// Updates the maze configuration with new global settings.
|
||||||
pub fn update(&mut self, global_conig: &GlobalMazeConfig) {
|
pub fn update(&mut self, global_conig: &GlobalMazeConfig) {
|
||||||
self.layout.hex_size = Vec2::splat(global_conig.hex_size);
|
self.layout.hex_size = Vec2::splat(global_conig.hex_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TO
|
||||||
|
// 3928551514041614914
|
||||||
|
// (4, 0)
|
||||||
|
|
||||||
|
// FROM
|
||||||
|
// 7365371276044996661
|
||||||
|
// ()
|
||||||
|
|
||||||
impl Default for MazeConfig {
|
impl Default for MazeConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
@ -100,6 +115,22 @@ impl Default for MazeConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn setup_rng(seed: Option<u64>) -> (u64, StdRng) {
|
||||||
|
let seed = seed.unwrap_or_else(|| thread_rng().gen());
|
||||||
|
let rng = StdRng::seed_from_u64(seed);
|
||||||
|
(seed, rng)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_end_pos<R: Rng>(radius: u16, start_pos: Hex, rng: &mut R) -> Hex {
|
||||||
|
let mut end_pos;
|
||||||
|
loop {
|
||||||
|
end_pos = generate_pos(radius, rng);
|
||||||
|
if start_pos != end_pos {
|
||||||
|
return end_pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Generates a random position within a hexagonal radius.
|
/// Generates a random position within a hexagonal radius.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
|
|||||||
@ -68,6 +68,7 @@ pub fn spawn_maze(
|
|||||||
.id();
|
.id();
|
||||||
|
|
||||||
let assets = MazeAssets::new(&mut meshes, &mut materials, &global_config);
|
let assets = MazeAssets::new(&mut meshes, &mut materials, &global_config);
|
||||||
|
|
||||||
spawn_maze_tiles(
|
spawn_maze_tiles(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
entity,
|
entity,
|
||||||
|
|||||||
@ -16,7 +16,7 @@ pub struct MovementSpeed(pub f32);
|
|||||||
|
|
||||||
impl Default for MovementSpeed {
|
impl Default for MovementSpeed {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self(100.)
|
Self(200.)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user