summaryrefslogtreecommitdiff
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
parent2b23a7efd6cc4d55e10e01c978a3614e7b97c93c (diff)
rounds
-rw-r--r--build/zombies.exebin2004349 -> 2006675 bytes
-rw-r--r--include/rounds.h27
-rw-r--r--include/zombie_chunk.h2
-rw-r--r--include/zombies.h1
-rw-r--r--main.c2
-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
9 files changed, 84 insertions, 4 deletions
diff --git a/build/zombies.exe b/build/zombies.exe
index 0505694..49f843c 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/include/rounds.h b/include/rounds.h
new file mode 100644
index 0000000..832cc1d
--- /dev/null
+++ b/include/rounds.h
@@ -0,0 +1,27 @@
+#ifndef INCLUDE_ROUNDS
+#define INCLUDE_ROUNDS
+
+#include <projectbase/project_base.h>
+
+#define ROUND_SWITCH_TIME 6.0f
+
+typedef enum t_round_state {
+ ROUND_SPAWNING,
+ ROUND_SWITCHING,
+} round_state;
+
+typedef struct t_zombie_round {
+ u32 round_nr;
+ u32 zombies;
+ round_state state;
+ float round_timer;
+} zombie_round;
+
+zombie_round _current_round = {.round_nr = 0, .zombies = 0, .state = ROUND_SWITCHING};
+
+bool current_round_is_done();
+void start_next_round();
+int zombies_left_in_current_round();
+void update_round_server();
+
+#endif \ No newline at end of file
diff --git a/include/zombie_chunk.h b/include/zombie_chunk.h
index d774026..7beb14c 100644
--- a/include/zombie_chunk.h
+++ b/include/zombie_chunk.h
@@ -35,6 +35,6 @@ zombie_chunk zombie_chunks[MAX_ZOMBIE_CHUNKS] = {0};
void draw_zombie_chunks(platform_window* window);
void spawn_zombie_chunk(vec3f center);
void spawn_zombie_splatter(vec3f center);
-void update_zombie_chunks();
+void update_zombie_chunks_server();
#endif \ No newline at end of file
diff --git a/include/zombies.h b/include/zombies.h
index b2aeb2a..9c1b68d 100644
--- a/include/zombies.h
+++ b/include/zombies.h
@@ -44,5 +44,6 @@ void create_spawner(vec2 position);
void draw_spawners(platform_window* window);
void draw_zombies(platform_window* window);
void spawn_zombie(int x, int y);
+u32 number_of_zombies_active();
#endif \ No newline at end of file
diff --git a/main.c b/main.c
index 6288233..f1f1842 100644
--- a/main.c
+++ b/main.c
@@ -11,6 +11,7 @@
#include "include/objects.h"
#include "include/map.h"
#include "include/audio.h"
+#include "include/rounds.h"
#include "include/zombies.h"
#include "include/math_helper.h"
#include "include/bullets.h"
@@ -33,6 +34,7 @@
#include "src/players.c"
#include "src/objects.c"
#include "src/audio.c"
+#include "src/rounds.c"
#include "src/zombies.c"
#include "src/bullets.c"
#include "src/throwables.c"
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;
}