summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-11-05 11:08:16 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2023-11-05 11:08:16 +0100
commit075335d187f45de7d002e3f44f6ec93b30abed78 (patch)
tree0326b8ef2b4b779f4a1eee10a62b1a803c6e19ba /src
parent2b23a7efd6cc4d55e10e01c978a3614e7b97c93c (diff)
rounds
Diffstat (limited to 'src')
-rw-r--r--src/game.c3
-rw-r--r--src/rounds.c35
-rw-r--r--src/zombie_chunk.c2
-rw-r--r--src/zombies.c16
4 files changed, 53 insertions, 3 deletions
diff --git a/src/game.c b/src/game.c
index 3a39f76..deadec1 100644
--- a/src/game.c
+++ b/src/game.c
@@ -216,7 +216,8 @@ void update_server(platform_window* window) {
update_drops_server();
update_wallitems_server();
update_throwables_server();
- update_zombie_chunks();
+ update_zombie_chunks_server();
+ update_round_server();
broadcast_players = platform_get_time(TIME_FULL, TIME_NS);
update_players_server();
diff --git a/src/rounds.c b/src/rounds.c
new file mode 100644
index 0000000..8db9ae8
--- /dev/null
+++ b/src/rounds.c
@@ -0,0 +1,35 @@
+
+bool current_round_is_done()
+{
+ return _current_round.zombies == 0 && number_of_zombies_active() == 0;
+}
+
+void start_next_round()
+{
+ _current_round.round_nr++;
+ _current_round.zombies = 6;
+ _current_round.state = ROUND_SWITCHING;
+ _current_round.round_timer = 0.0f;
+
+ log_infox("Next round: %d", _current_round.round_nr);
+}
+
+int zombies_left_in_current_round()
+{
+ if (_current_round.state != ROUND_SPAWNING) return 0;
+ return _current_round.zombies;
+}
+
+void update_round_server()
+{
+ _current_round.round_timer += SERVER_TICK_RATE;
+ if (_current_round.state == ROUND_SWITCHING) {
+ if (_current_round.round_timer >= ROUND_SWITCH_TIME) {
+ _current_round.state = ROUND_SPAWNING;
+ }
+ }
+
+ if (current_round_is_done()) {
+ start_next_round();
+ }
+} \ No newline at end of file
diff --git a/src/zombie_chunk.c b/src/zombie_chunk.c
index 02e7027..7073b37 100644
--- a/src/zombie_chunk.c
+++ b/src/zombie_chunk.c
@@ -62,7 +62,7 @@ void spawn_zombie_chunk(vec3f center) {
}
}
-void update_zombie_chunks() {
+void update_zombie_chunks_server() {
for (int i = 0; i < MAX_ZOMBIE_CHUNKS; i++)
{
if (!zombie_chunks[i].active) continue;
diff --git a/src/zombies.c b/src/zombies.c
index 28c3d62..a3fad4c 100644
--- a/src/zombies.c
+++ b/src/zombies.c
@@ -62,6 +62,17 @@ bool hit_zombie(int index, int damage) {
return false;
}
+u32 number_of_zombies_active()
+{
+ u32 res = 0;
+ for (int i = 0; i < SERVER_MAX_ZOMBIES; i++) {
+ zombie o = zombies[i];
+ if (!o.alive) continue;
+ res++;
+ }
+ return res;
+}
+
void spawn_zombie(int x, int y) {
for (int i = 0; i < SERVER_MAX_ZOMBIES; i++) {
zombie o = zombies[i];
@@ -77,6 +88,8 @@ void spawn_zombie(int x, int y) {
zombies[i].time_since_last_path = 0.0f;
zombies[i].request.to_fill = &zombies[i].next_path;
zombies[i].request.mutex = mutex_create();
+
+ _current_round.zombies--;
player closest_player = get_closest_player_to_tile(x, y);
@@ -89,9 +102,10 @@ void update_spawners_server() {
for (int x = 0; x < MAX_SPAWNERS; x++) {
spawner spawner = spawner_tiles[x];
if (!spawner.active) continue;
+ if (zombies_left_in_current_round() <= 0) continue;
update_sprite(&spawner_tiles[x].sprite);
spawner_tiles[x].sec_since_last_spawn += SERVER_TICK_RATE;
- if (spawner_tiles[x].sec_since_last_spawn >= 2.0f) {
+ if (spawner_tiles[x].sec_since_last_spawn >= 1.0f) {
spawn_zombie(spawner.position.x, spawner.position.y);
spawner_tiles[x].sec_since_last_spawn = 0;
}