start con_text
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 720 B |
+3
-3
@@ -158,13 +158,13 @@ fn setup_tilemap(commands: &mut Commands, asset_server: &Res<AssetServer>) {
|
|||||||
// Spawn appropriate fixture based on floor type above
|
// Spawn appropriate fixture based on floor type above
|
||||||
match *above_floor_type {
|
match *above_floor_type {
|
||||||
"dirt" => {
|
"dirt" => {
|
||||||
commands.spawn(FixtureTilePrefab::dirt(fixture_position, asset_server));
|
commands.spawn(FixtureTilePrefab::dirt_wall(fixture_position, asset_server));
|
||||||
}
|
}
|
||||||
"rock" => {
|
"rock" => {
|
||||||
commands.spawn(FixtureTilePrefab::rock(fixture_position, asset_server));
|
commands.spawn(FixtureTilePrefab::rock_wall(fixture_position, asset_server));
|
||||||
}
|
}
|
||||||
"bedrock" => {
|
"bedrock" => {
|
||||||
commands.spawn(FixtureTilePrefab::bedrock(fixture_position, asset_server));
|
commands.spawn(FixtureTilePrefab::bedrock_wall(fixture_position, asset_server));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-5
@@ -44,6 +44,11 @@ impl Default for FixtureTile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component, Clone)]
|
||||||
|
pub struct ConnectedTexture {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
pub struct CameraMoved(pub bool);
|
pub struct CameraMoved(pub bool);
|
||||||
|
|
||||||
@@ -77,10 +82,9 @@ pub fn tile_sprite_generate_occlusion_map(
|
|||||||
)>,
|
)>,
|
||||||
) {
|
) {
|
||||||
// Create the tile map using floor query
|
// 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();
|
let mut map = HashMap::new();
|
||||||
|
|
||||||
// Add floor tiles
|
|
||||||
query_set.p0().iter().for_each(|(transform, tile)| {
|
query_set.p0().iter().for_each(|(transform, tile)| {
|
||||||
map.insert(
|
map.insert(
|
||||||
(
|
(
|
||||||
@@ -88,7 +92,23 @@ pub fn tile_sprite_generate_occlusion_map(
|
|||||||
transform.translation.y as i32,
|
transform.translation.y as i32,
|
||||||
transform.translation.z 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
|
map
|
||||||
@@ -168,7 +188,7 @@ pub fn tile_sprite_generate_occlusion_map(
|
|||||||
transform.translation.y as i32,
|
transform.translation.y as i32,
|
||||||
transform.translation.z 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
|
// Update fixture tiles
|
||||||
@@ -181,7 +201,7 @@ pub fn tile_sprite_generate_occlusion_map(
|
|||||||
transform.translation.y as i32,
|
transform.translation.y as i32,
|
||||||
transform.translation.z as i32 - 1,
|
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(
|
pub fn tile_item_sprite_update(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut query_tile: Query<(Entity, &Children, &mut TileState)>,
|
mut query_tile: Query<(Entity, &Children, &mut TileState)>,
|
||||||
|
|||||||
+5
-5
@@ -89,7 +89,7 @@ pub struct FixtureTilePrefab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FixtureTilePrefab {
|
impl FixtureTilePrefab {
|
||||||
pub fn dirt(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
pub fn dirt_wall(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
||||||
FixtureTilePrefab {
|
FixtureTilePrefab {
|
||||||
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
@@ -103,7 +103,7 @@ impl FixtureTilePrefab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rock(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
pub fn rock_wall(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
||||||
FixtureTilePrefab {
|
FixtureTilePrefab {
|
||||||
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
@@ -111,13 +111,13 @@ impl FixtureTilePrefab {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
tile: FixtureTile {
|
tile: FixtureTile {
|
||||||
id: 3,
|
id: 2,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bedrock(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
pub fn bedrock_wall(position: Vec3, asset_server: &Res<AssetServer>) -> Self {
|
||||||
FixtureTilePrefab {
|
FixtureTilePrefab {
|
||||||
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
@@ -125,7 +125,7 @@ impl FixtureTilePrefab {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
tile: FixtureTile {
|
tile: FixtureTile {
|
||||||
id: 4,
|
id: 0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user