Fixed targeting for citizen movement

This commit is contained in:
2025-01-19 22:13:24 +00:00
parent 594131a372
commit 53b95f452f
5 changed files with 40 additions and 23 deletions
+14 -5
View File
@@ -1,5 +1,5 @@
use crate::constants::TILE_SIZE;
use crate::tile::{FixtureTile, FloorTile, NeedsOccluded, TileMap};
use crate::tile::{self, FixtureTile, FloorTile, NeedsOccluded, TileMap};
use crate::tiles::{FixtureTilePrefab, FloorTilePrefab};
use bevy::prelude::*;
use noise::{NoiseFn, Perlin};
@@ -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 -15..5 {
for mut camera_z in -15..=5 {
camera_z *= tile_size;
let mut is_visible = false;
@@ -196,7 +196,7 @@ fn handle_chunk_loading(
);
// Spawn tiles and add them to tilemap
for z in -15..5 {
for z in -15..=5 {
let position = Vec3::new(
(world_x as f32 * TILE_SIZE).round(),
(world_y as f32 * TILE_SIZE).round(),
@@ -285,8 +285,8 @@ fn handle_chunk_loading(
fn setup_initial_chunks(mut event_writer: EventWriter<LoadChunkEvent>) {
println!("setup_initial_chunks");
for x in -5..=5 {
for y in -5..=5 {
for x in -8..=8 {
for y in -8..=8 {
event_writer.send(LoadChunkEvent {
chunk_position: IVec2::new(x, y),
});
@@ -301,6 +301,15 @@ impl Plugin for TilemapPlugin {
app.init_resource::<ChunkMap>()
.add_event::<LoadChunkEvent>()
.add_systems(Startup, (setup_chunk_system, setup_initial_chunks))
.add_systems(
PostStartup,
(
handle_chunk_loading,
handle_tile_occlusion_updates,
tile::update_tile_visibility,
)
.chain(),
)
.add_systems(
FixedUpdate,
(handle_chunk_loading, handle_tile_occlusion_updates).chain(),