partial a*

This commit is contained in:
StephenAdamson
2025-01-17 20:05:08 +00:00
parent 7b8142afd2
commit 0af88c213d
5 changed files with 288 additions and 45 deletions
+27 -14
View File
@@ -76,7 +76,7 @@ pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
let mut visible_range = [0u32; 8];
for mut camera_z in -150..100 {
for mut camera_z in -15..5 {
camera_z *= tile_size;
let mut is_visible = false;
@@ -89,7 +89,7 @@ pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
'vertical_check: for z_offset in 1..=35 {
let above_pos = IVec3::new(pos.x, pos.y, pos.z + (z_offset * tile_size));
if above_pos.z <= camera_z {
if let Some(&(_, opaque, _, _, _)) = tilemap.floors.get(&above_pos) {
if let Some(&(_, opaque, _, _, _)) = tilemap.floor_tiles.get(&above_pos) {
if opaque {
is_occluded = true;
break 'vertical_check;
@@ -118,7 +118,7 @@ pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
pos.z + z_offset * tile_size,
);
if let Some(&(id, _, _, _, _)) = tilemap.floors.get(&neighbor_pos) {
if let Some(&(id, _, _, _, _)) = tilemap.floor_tiles.get(&neighbor_pos) {
if id == 0 {
is_visible = true;
break 'neighbor_check;
@@ -196,7 +196,7 @@ fn handle_chunk_loading(
);
// Spawn tiles and add them to tilemap
for z in -150..50 {
for z in -15..5 {
let position = Vec3::new(
(world_x as f32 * TILE_SIZE).round(),
(world_y as f32 * TILE_SIZE).round(),
@@ -212,17 +212,21 @@ fn handle_chunk_loading(
]);
if noise_value < -0.5 {
FloorTilePrefab::air(position, &asset_server).spawn(&mut commands);
tilemap.floors.insert(pos_ivec, (0, false, true, 1, [0; 8])); // Air tile
tilemap
.floor_tiles
.insert(pos_ivec, (0, false, true, 0, [0; 8])); // Air tile
floor_positions.push((position, "air"));
} else if noise_value < 0.8 {
FloorTilePrefab::rock(position, &asset_server).spawn(&mut commands);
tilemap
.floors
.insert(pos_ivec, (2, true, false, 255, [0; 8])); // Rock tile
.floor_tiles
.insert(pos_ivec, (2, true, false, 50, [0; 8])); // Rock tile
floor_positions.push((position, "rock"));
} else {
FloorTilePrefab::dirt(position, &asset_server).spawn(&mut commands);
tilemap.floors.insert(pos_ivec, (1, true, true, 1, [0; 8])); // Dirt tile
tilemap
.floor_tiles
.insert(pos_ivec, (1, true, true, 85, [0; 8])); // Dirt tile
floor_positions.push((position, "dirt"));
}
} else if noise_position.z > position.z {
@@ -230,16 +234,22 @@ fn handle_chunk_loading(
<= position.z + TILE_SIZE
{
FloorTilePrefab::grass(position, &asset_server).spawn(&mut commands);
tilemap.floors.insert(pos_ivec, (1, true, true, 1, [0; 8])); // Dirt tile (grass)
tilemap
.floor_tiles
.insert(pos_ivec, (1, true, true, 100, [0; 8])); // Dirt tile (grass)
floor_positions.push((position, "dirt"));
} else {
FloorTilePrefab::dirt(position, &asset_server).spawn(&mut commands);
tilemap.floors.insert(pos_ivec, (1, true, true, 1, [0; 8])); // Dirt tile
tilemap
.floor_tiles
.insert(pos_ivec, (1, true, true, 85, [0; 8])); // Dirt tile
floor_positions.push((position, "dirt"));
}
} else {
FloorTilePrefab::air(position, &asset_server).spawn(&mut commands);
tilemap.floors.insert(pos_ivec, (0, false, true, 1, [0; 8])); // Air tile
tilemap
.floor_tiles
.insert(pos_ivec, (0, false, true, 0, [0; 8])); // Air tile
floor_positions.push((position, "air"));
}
}
@@ -254,15 +264,18 @@ fn handle_chunk_loading(
match *floor_type {
"dirt" => {
FixtureTilePrefab::dirt_wall(above_pos, &asset_server).spawn(&mut commands);
tilemap.fixtures.insert(above_ivec, (1, true, [0; 8])); // Dirt wall
tilemap.fixture_tiles.insert(above_ivec, (1, true, [0; 8]));
// Dirt wall
}
"rock" => {
FixtureTilePrefab::rock_wall(above_pos, &asset_server).spawn(&mut commands);
tilemap.fixtures.insert(above_ivec, (2, true, [0; 8])); // Rock wall
tilemap.fixture_tiles.insert(above_ivec, (2, true, [0; 8]));
// Rock wall
}
"bedrock" => {
FixtureTilePrefab::bedrock_wall(above_pos, &asset_server).spawn(&mut commands);
tilemap.fixtures.insert(above_ivec, (3, true, [0; 8])); // Bedrock wall
tilemap.fixture_tiles.insert(above_ivec, (3, true, [0; 8]));
// Bedrock wall
}
_ => {}
}