-
Notifications
You must be signed in to change notification settings - Fork 218
Open
Description
I'm using generate_hexagon
to select tiles that are in range for player to see. But this is what I get:
It's supposed to be just a hexagon, but every other row below the center is shifted!
Here are code snippets of the project:
fn chart_map(
player: Query<(&MapPos, &ChartRange), With<PlayerVehicle>>,
mut tiles: Query<(&mut TileVisibility, &TilePos, &TilemapId)>,
chunks: Query<&Chunk>,
) {
let (player_pos, chart_range) = player.single();
let tiles_in_chart_range: Vec<RowEvenPos> =
generate_hexagon(player_pos.pos.into(), chart_range.0)
.into_iter()
.map(Into::into)
.collect();
for (mut tile_vis, tile_pos, tilemap_id) in tiles.iter_mut() {
let chunk = chunks.get(tilemap_id.0).unwrap();
let global_tile_pos = global_from_chunk_and_local(chunk.pos, *tile_pos);
if tiles_in_chart_range.contains(&global_tile_pos) {
*tile_vis = TileVisibility::Visible
} else if matches!(*tile_vis, TileVisibility::Visible) {
*tile_vis = TileVisibility::Charted
}
}
}
pub fn global_from_chunk_and_local(chunk: IVec2, local: TilePos) -> RowEvenPos {
RowEvenPos {
q: chunk.x * TILEMAP_CHUNK_SIZE.x as i32 + local.x as i32,
r: chunk.y * TILEMAP_CHUNK_SIZE.y as i32 + local.y as i32,
}
}
And also the project is on github: https://github.com/JohnTheCoolingFan/sands_of_merkhyl/tree/b69881fde365a79716ed8cb02999443350f8a832
Metadata
Metadata
Assignees
Labels
No labels