diff --git a/src/game/debug/terrain.rs b/src/game/debug/terrain.rs index ee5cd13..62ee70c 100644 --- a/src/game/debug/terrain.rs +++ b/src/game/debug/terrain.rs @@ -20,7 +20,7 @@ struct TerrainBrush2D { impl Default for TerrainBrush2D { fn default() -> Self { - TerrainBrush2D { radius: 7, tile: 3 } + TerrainBrush2D { radius: 5, tile: 4 } } } @@ -35,7 +35,8 @@ fn debug_painter( mut mouse_wheel: EventReader, camera_query: Query<(&Camera, &GlobalTransform), With>, ) { - let allow_painting = key_input.pressed(KeyCode::LControl); + // let allow_painting = key_input.pressed(KeyCode::LControl); + let allow_painting = true; // Change brush for event in mouse_wheel.iter() { diff --git a/src/terrain2d.rs b/src/terrain2d.rs index d00053b..67b19eb 100644 --- a/src/terrain2d.rs +++ b/src/terrain2d.rs @@ -77,7 +77,7 @@ fn terrain_simulation(mut terrain: ResMut, frame_counter: Res, frame_counter: Res { // Check if there is space below @@ -160,6 +161,41 @@ fn terrain_simulation(mut terrain: ResMut, frame_counter: Res { + // Check if there is space above + { + let above_pos = global + Vector2I::UP; + if terrain + .get_texel(&above_pos) + .map_or(true, |texel| TexelBehaviour2D::is_empty(&texel.id)) + { + let above_id = + terrain.get_texel(&above_pos).map_or(0, |texel| texel.id); + terrain.set_texel(&above_pos, texel.id, Some(simulation_frame)); + terrain.set_texel(&global, above_id, Some(simulation_frame)); + continue; + } + } + + // Check if there is space to the side + let mut dirs = vec![Vector2I::RIGHT, Vector2I::LEFT]; + if ((frame_counter.frame / 73) % 2) as i32 == global.y % 2 { + dirs.reverse(); + } + for dir in dirs.iter() { + let side_pos = global + *dir; + if terrain + .get_texel(&side_pos) + .map_or(true, |texel| TexelBehaviour2D::is_empty(&texel.id)) + { + let side_id = + terrain.get_texel(&side_pos).map_or(0, |texel| texel.id); + terrain.set_texel(&side_pos, texel.id, Some(simulation_frame)); + terrain.set_texel(&global, side_id, Some(simulation_frame)); + continue 'texel_loop; + }; + } + } _ => (), } }