From caac4b1d169425ad7dda15fe8fceca9c5a95400b Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 12 Dec 2022 20:12:38 +0100 Subject: testing --- .vscode/launch.json | 2 +- Makefile | 3 +-- build/zombies.exe | Bin 1711747 -> 1711747 bytes include/game.h | 1 + include/players.h | 1 + src/game.c | 14 ++++++++------ src/players.c | 3 +-- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e20587a..d3fc5c5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "request": "launch", "name": "Launch(gdb)", "program": "build/zombies.exe ", - "programArgs": "-ip 172.27.176.1 -port 27015", + "programArgs": "-ip 84.104.98.153 -port 27015", "cwd": "${workspaceRoot}" } ] diff --git a/Makefile b/Makefile index 0a6794a..709f5cd 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,5 @@ main: rm -rf "build/" mkdir -p "build/" gcc -m64 -g -DMODE_DEBUG main.c -o build/zombies.exe -lprojectbase-debug -Llibs/ -lSDL2 -lSDL2_mixer -lWs2_32 - ./build/zombies.exe -ip 127.0.0.1 -port 27015 & - ./build/zombies.exe -ip 172.27.176.1 -port 27015 + ./build/zombies.exe -ip 127.0.0.1 -port 27015 diff --git a/build/zombies.exe b/build/zombies.exe index a413c47..7f0e1e0 100644 Binary files a/build/zombies.exe and b/build/zombies.exe differ diff --git a/include/game.h b/include/game.h index 944a831..ffab7b7 100644 --- a/include/game.h +++ b/include/game.h @@ -4,6 +4,7 @@ #include #include "../include/protocol.h" +#include "../include/game.h" typedef enum t_game_state { GAMESTATE_IDLE, diff --git a/include/players.h b/include/players.h index ea12a96..abe4a37 100644 --- a/include/players.h +++ b/include/players.h @@ -27,6 +27,7 @@ player players[10] = {0}; player* get_player_by_id(u32 id); void draw_players_at_tile(platform_window* window, int x, int y); void draw_bullets(platform_window* window); +object check_if_player_collided_with_object(platform_window* window, player p); float get_player_size(platform_window* window); #endif \ No newline at end of file diff --git a/src/game.c b/src/game.c index d3ec30b..00f7bbb 100644 --- a/src/game.c +++ b/src/game.c @@ -158,8 +158,8 @@ void update_server(platform_window* window) { broadcast_to_clients(create_protocol_user_list()); - if (update_timer > 0.05f) { - broadcast_to_clients(create_protocol_zombie_list()); + if (update_timer > 0.2f) { + //broadcast_to_clients(create_protocol_zombie_list()); update_timer = 0.0f; } @@ -173,6 +173,7 @@ void update_client(platform_window* window) { switch (msg->type) { case MESSAGE_GET_ID_DOWNSTREAM: { + if (global_state.network_state == CONNECTED) break; protocol_get_id_downstream* msg_id = (protocol_get_id_downstream*)msg; my_id = msg_id->id; global_state.network_state = CONNECTED; @@ -198,10 +199,6 @@ void update_client(platform_window* window) { array_remove_at(&messages_received_on_client, i); i--; } - - if (!global_state.server) { - update_zombies_client(window); - } } void update_game(platform_window* window) { @@ -211,6 +208,11 @@ void update_game(platform_window* window) { } if (global_state.network_state == CONNECTED) { + if (!global_state.server) { + update_zombies_client(window); + } + take_player_input(window); + draw_grid(window); draw_spawners(window); } diff --git a/src/players.c b/src/players.c index 82804d1..c168eb5 100644 --- a/src/players.c +++ b/src/players.c @@ -1,4 +1,5 @@ #include "../include/players.h" +#include "../include/game.h" float get_bullet_size_in_tile(platform_window* window) { return 1 / 8.0f; @@ -106,8 +107,6 @@ void draw_players_at_tile(platform_window* window, int x, int y) { if (!players[i].active) continue; if ((int)players[i].playerx != x || (int)(players[i].playery+get_player_size_in_tile()) != y) continue; - if (players[i].id == my_id) take_player_input(window); - players[i].sec_since_last_shot += update_delta; float bullets_per_sec = 10; float time_between_bullets = 1.0f/bullets_per_sec; -- cgit v1.2.3-70-g09d2