start con_text

This commit is contained in:
2024-12-29 19:03:26 +00:00
parent 3aadb8bb78
commit a4342c9aa0
6 changed files with 68 additions and 13 deletions
+60 -5
View File
@@ -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<String> {
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<Time>,
mut query_tile: Query<(Entity, &Children, &mut TileState)>,