diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-11 20:00:21 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-11 20:00:21 +0100 |
| commit | f29d35faf7cc574a1a8c109f2f609db9d3d4b5ef (patch) | |
| tree | dfd2fcbf20f3d37ffe1f19be3d0a9afb7fd24d86 /zombies.c | |
| parent | 24af775b5041cbed67dfc84f3a0d67850a4b6a1b (diff) | |
bazinga
Diffstat (limited to 'zombies.c')
| -rw-r--r-- | zombies.c | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -35,7 +35,8 @@ void spawn_zombie(int x, int y) { zombies[i].position = (vec3f){x,y, 0}; zombies[i].size = (vec3f){0.4, 0.4, 1}; zombies[i].time_since_last_path = 0.0f; - + zombies[i].request.mutex = mutex_create(); + player closest_player = get_closest_player_to_tile(x, y); make_pathfinding_request((vec2f){x,y}, (vec2f){closest_player.playerx, closest_player.playery}, &zombies[i].path, &zombies[i].request); @@ -46,7 +47,7 @@ void spawn_zombie(int x, int y) { void draw_spawners(platform_window* window) { map_info info = get_map_info(window); - for (int x = 0; x < 2; x++) { + for (int x = 0; x < 1; x++) { spawner spawner = spawner_tiles[x]; int render_x = (info.tile_width * spawner.position.x) + (info.px_incline * spawner.position.y); int render_y = info.tile_height * spawner.position.y; @@ -60,7 +61,7 @@ void draw_spawners(platform_window* window) { rgb(100, 150, 50)); spawner_tiles[x].sec_since_last_spawn += update_delta; - if (spawner_tiles[x].sec_since_last_spawn >= 3.0f) { + if (spawner_tiles[x].sec_since_last_spawn >= 2.0f) { spawn_zombie(spawner.position.x, spawner.position.y); spawner_tiles[x].sec_since_last_spawn = 0; } @@ -132,7 +133,7 @@ void draw_zombies_at_tile(platform_window* window, int x, int y) { if ((int)o.position.x != x || (int)ceil(o.position.y) != y) continue; zombies[i].time_since_last_path += update_delta; - if (zombies[i].time_since_last_path > 0.1f) { + if (zombies[i].time_since_last_path > 0.05f) { player closest_player = get_closest_player_to_tile(x, y); make_pathfinding_request((vec2f){o.position.x,o.position.y}, (vec2f){closest_player.playerx, closest_player.playery + get_player_size_in_tile()}, @@ -140,11 +141,15 @@ void draw_zombies_at_tile(platform_window* window, int x, int y) { zombies[i].time_since_last_path = 0; } else { - if (zombies[i].request.done) { - zombies[i].path = zombies[i].next_path; - array_clear(&zombies[i].next_path); - zombies[i].request.done = false; + if (mutex_trylock(&zombies[i].request.mutex)) + { + if (zombies[i].request.to_fill->length) { + array_destroy(&zombies[i].path); + zombies[i].path = array_copy(&zombies[i].next_path); + array_clear(&zombies[i].next_path); + } } + mutex_unlock(&zombies[i].request.mutex); } vec2f dir = get_direction_to_next_tile(o); |
