diff --git a/assets/natural walls/rock/example.png b/assets/natural walls/rock/example.png new file mode 100644 index 0000000..33c80b0 Binary files /dev/null and b/assets/natural walls/rock/example.png differ diff --git a/assets/natural walls/rock/template.png b/assets/natural walls/rock/template.png new file mode 100644 index 0000000..0d4b0f0 Binary files /dev/null and b/assets/natural walls/rock/template.png differ diff --git a/assets/natural walls/rock/tube.png b/assets/natural walls/rock/tube.png new file mode 100644 index 0000000..1f300db Binary files /dev/null and b/assets/natural walls/rock/tube.png differ diff --git a/src/game.rs b/src/game.rs index ca34edc..12585f3 100644 --- a/src/game.rs +++ b/src/game.rs @@ -158,13 +158,13 @@ fn setup_tilemap(commands: &mut Commands, asset_server: &Res) { // Spawn appropriate fixture based on floor type above match *above_floor_type { "dirt" => { - commands.spawn(FixtureTilePrefab::dirt(fixture_position, asset_server)); + commands.spawn(FixtureTilePrefab::dirt_wall(fixture_position, asset_server)); } "rock" => { - commands.spawn(FixtureTilePrefab::rock(fixture_position, asset_server)); + commands.spawn(FixtureTilePrefab::rock_wall(fixture_position, asset_server)); } "bedrock" => { - commands.spawn(FixtureTilePrefab::bedrock(fixture_position, asset_server)); + commands.spawn(FixtureTilePrefab::bedrock_wall(fixture_position, asset_server)); } _ => {} } diff --git a/src/tile.rs b/src/tile.rs index f676d41..6ae9f22 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -44,6 +44,11 @@ impl Default for FixtureTile { } } +#[derive(Component, Clone)] +pub struct ConnectedTexture { + +} + #[derive(Resource, Default)] pub struct CameraMoved(pub bool); @@ -77,10 +82,9 @@ pub fn tile_sprite_generate_occlusion_map( )>, ) { // Create the tile map using floor query - let tile_map: HashMap<(i32, i32, i32), (bool, u32)> = { + let floor_tile_map: HashMap<(i32, i32, i32), (bool, u32)> = { let mut map = HashMap::new(); - // Add floor tiles query_set.p0().iter().for_each(|(transform, tile)| { map.insert( ( @@ -88,7 +92,23 @@ pub fn tile_sprite_generate_occlusion_map( transform.translation.y as i32, transform.translation.z as i32, ), - (tile.opaque, tile.id), // false indicates floor + (tile.opaque, tile.id), + ); + }); + map + }; + // Create the tile map using fixture query + let fixture_tile_map: HashMap<(i32, i32, i32), (bool, u32)> = { + let mut map = HashMap::new(); + + query_set.p1().iter().for_each(|(transform, tile)| { + map.insert( + ( + transform.translation.x as i32, + transform.translation.y as i32, + transform.translation.z as i32, + ), + (tile.solid, tile.id), ); }); map @@ -168,7 +188,7 @@ pub fn tile_sprite_generate_occlusion_map( transform.translation.y as i32, transform.translation.z as i32, ); - tile.visible_range = calculate_visibility(pos, &tile_map); + tile.visible_range = calculate_visibility(pos, &floor_tile_map); }); // Update fixture tiles @@ -181,7 +201,7 @@ pub fn tile_sprite_generate_occlusion_map( transform.translation.y as i32, transform.translation.z as i32 - 1, ); - fixture.visible_range = calculate_visibility(pos, &tile_map); + fixture.visible_range = calculate_visibility(pos, &fixture_tile_map); }); } @@ -222,6 +242,41 @@ pub fn update_tile_visibility( }); } +fn calculate_connected_texture(floor_tiles: &HashMap<(i32, i32, i32), (bool, u32)>) -> Vec { + let mut textures = vec![]; + + for ((x, y, z), (is_floor, tile_id)) in floor_tiles.iter() { + let mut is_wall = false; + + for x_offset in -1..=1 { + for y_offset in -1..=1 { + for z_offset in 0..=1 { + if x_offset == 0 && y_offset == 0 && z_offset == 0 { + continue; + } + + let neighbor_pos = (x + x_offset, y + y_offset, z + z_offset); + + if let Some((_, neighbor_id)) = floor_tiles.get(&neighbor_pos) { + if *neighbor_id > 0 { // assuming wall IDs are greater than 0 + is_wall = true; + break; + } + } + } + } + } + + match (is_floor, is_wall) { + (true, false) => textures.push("floor".to_string()), // or some other floor texture + (false, true) => textures.push("wall".to_string()), // or some other wall texture + _ => panic!("Unexpected tile state"), + } + } + + textures +} + pub fn tile_item_sprite_update( time: Res