diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-15 14:54:55 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-15 14:54:55 +0100 |
| commit | 8c086739e1344fb8789e89074dd962c5719ab030 (patch) | |
| tree | 86ae878cd5f90a82b7fee454e4adae69de542bb4 | |
| parent | 7b956089e6ba5162fb0b667f1c0a60f6ece90c38 (diff) | |
local session id generation, bullet icon drop, refactor
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | build/data/imgs/bullets.png | bin | 0 -> 3650 bytes | |||
| -rw-r--r-- | build/zombies.exe | bin | 1732134 -> 1733868 bytes | |||
| -rw-r--r-- | data/imgs/bullets.png | bin | 0 -> 3650 bytes | |||
| -rw-r--r-- | include/asset_defs.h | 2 | ||||
| -rw-r--r-- | include/bullets.h | 2 | ||||
| -rw-r--r-- | include/objects.h | 8 | ||||
| -rw-r--r-- | include/players.h | 6 | ||||
| -rw-r--r-- | include/protocol.h | 3 | ||||
| -rw-r--r-- | main.c | 3 | ||||
| -rw-r--r-- | project-base.code-workspace | 3 | ||||
| -rw-r--r-- | src/asset_defs.c | 2 | ||||
| -rw-r--r-- | src/bullets.c | 37 | ||||
| -rw-r--r-- | src/drops.c | 36 | ||||
| -rw-r--r-- | src/game.c | 43 | ||||
| -rw-r--r-- | src/map.c | 4 | ||||
| -rw-r--r-- | src/objects.c | 6 | ||||
| -rw-r--r-- | src/overlay.c | 2 | ||||
| -rw-r--r-- | src/players.c | 40 | ||||
| -rw-r--r-- | src/protocol.c | 3 | ||||
| -rw-r--r-- | src/zombies.c | 6 |
21 files changed, 126 insertions, 81 deletions
@@ -1,6 +1,7 @@ main: rm -rf "build/" mkdir -p "build/" + cp -a "data/." "build/data" 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 diff --git a/build/data/imgs/bullets.png b/build/data/imgs/bullets.png Binary files differnew file mode 100644 index 0000000..e05a43c --- /dev/null +++ b/build/data/imgs/bullets.png diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex ed382ca..fc90201 100644 --- a/build/zombies.exe +++ b/build/zombies.exe diff --git a/data/imgs/bullets.png b/data/imgs/bullets.png Binary files differnew file mode 100644 index 0000000..e05a43c --- /dev/null +++ b/data/imgs/bullets.png diff --git a/include/asset_defs.h b/include/asset_defs.h index 9e50895..ee520ea 100644 --- a/include/asset_defs.h +++ b/include/asset_defs.h @@ -6,6 +6,8 @@ font* fnt_24; font* fnt_20; +image* img_icon_bullets; + void load_assets(); #endif
\ No newline at end of file diff --git a/include/bullets.h b/include/bullets.h index a42e6a4..be3f466 100644 --- a/include/bullets.h +++ b/include/bullets.h @@ -9,7 +9,7 @@ #include "guns.h" typedef struct t_bullet { - int player_id; + u32 player_id; bool active; vec3f position; float endx; diff --git a/include/objects.h b/include/objects.h index 04f434b..46d03ff 100644 --- a/include/objects.h +++ b/include/objects.h @@ -17,10 +17,10 @@ typedef struct t_object { } object; typedef struct t_box { - vec2f tl_b; - vec2f tr_b; - vec2f bl_b; - vec2f br_b; + vec2f tl_d; + vec2f tr_d; + vec2f bl_d; + vec2f br_d; vec2f tl_u; vec2f tr_u; diff --git a/include/players.h b/include/players.h index ab8da4c..ce88688 100644 --- a/include/players.h +++ b/include/players.h @@ -10,7 +10,7 @@ #include "guns.h" typedef struct t_player { - int id; + u32 id; bool active; float sec_since_last_shot; float playerx; @@ -29,7 +29,7 @@ typedef struct t_player { #include "protocol.h" -u32 my_id = -1; +u32 player_id = -1; camera _next_camera_pos; @@ -44,6 +44,6 @@ object check_if_player_collided_with_object(platform_window* window, player p); float get_player_size(platform_window* window); void move_user(platform_window* window, u32 id, protocol_move_type move); void update_players_server(); -void spawn_player(int id, network_client client); +void spawn_player(u32 id, network_client client); #endif
\ No newline at end of file diff --git a/include/protocol.h b/include/protocol.h index aec65b4..f02e873 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -30,6 +30,7 @@ typedef struct t_protocol_generic_message typedef struct t_protocol_get_id_upstream { network_message_type type; + u32 id; } protocol_get_id_upstream; typedef struct t_protocol_get_id_downstream @@ -91,7 +92,7 @@ typedef struct t_protocol_user_shoot #define MAX_NETWORK_BUFFER_SIZE 50000 u8 network_buffer[50000]; -network_message create_protocol_get_id_up(); +network_message create_protocol_get_id_up(u32 id); network_message create_protocol_get_id_down(u32 id); network_message create_protocol_user_list(); network_message create_protocol_user_moved(protocol_move_type move, u32 id); @@ -66,9 +66,10 @@ int main(int argc, char **argv) { platform_init(argc, argv, CONFIG_DIRECTORY); - platform_window *window = platform_open_window_ex("Zombies!", 700, 700, 1200, 1000, 500, 500, FLAGS_MINIMIZE, update_func, 0, 0, 0, 0); + platform_window *window = platform_open_window_ex("Zombies!", 1920, 1080, 1920, 1080, 500, 500, FLAGS_MINIMIZE, update_func, 0, 0, 0, 0); settings_set_number("USE_GPU", 1); platform_toggle_vsync(window, true); + //platform_toggle_fullscreen(window, true); init_game(); handle_args(argc, argv); diff --git a/project-base.code-workspace b/project-base.code-workspace index c96785b..095bb87 100644 --- a/project-base.code-workspace +++ b/project-base.code-workspace @@ -64,7 +64,8 @@ "streambuf": "c", "game.h": "c", "bullets.h": "c", - "guns.h": "c" + "guns.h": "c", + "iphlpapi.h": "c" } } }
\ No newline at end of file diff --git a/src/asset_defs.c b/src/asset_defs.c index d7fc6a5..a51dfe8 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -3,4 +3,6 @@ void load_assets() { fnt_24 = assets_load_font(mono_ttf, mono_ttf+mono_ttf_len, 24); fnt_20 = assets_load_font(mono_ttf, mono_ttf+mono_ttf_len, 20); + + img_icon_bullets = assets_load_image_from_file("data/imgs/bullets.png"); }
\ No newline at end of file diff --git a/src/bullets.c b/src/bullets.c index 472808b..69ba22c 100644 --- a/src/bullets.c +++ b/src/bullets.c @@ -81,16 +81,16 @@ bool check_if_bullet_collided_with_object(bullet* b, platform_window* window) { if (b->position.z <= o.h + o.size.z && b->position.z >= o.h) { box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.h}, o.size); vec2f intersect_point; - if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.bl_b, obj_box.br_b, &intersect_point)) { + if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.bl_d, obj_box.br_d, &intersect_point)) { result = true; } - if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_b, obj_box.tr_b, &intersect_point)) { + if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_d, obj_box.tr_d, &intersect_point)) { result = true; } - if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_b, obj_box.bl_b, &intersect_point)) { + if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_d, obj_box.bl_d, &intersect_point)) { result = true; } - if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tr_b, obj_box.br_b, &intersect_point)) { + if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tr_d, obj_box.br_d, &intersect_point)) { result = true; } @@ -123,19 +123,19 @@ bool check_if_bullet_collided_with_zombie(bullet b, platform_window* window, boo vec2f intersect_point; box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.position.z}, o.size); bool this_zombie_collided = false; - if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.bl_b, obj_box.br_b, &intersect_point)) { + if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.bl_d, obj_box.br_d, &intersect_point)) { this_zombie_collided = true; index_of_closest_zombie = i; } - if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_b, obj_box.tr_b, &intersect_point)) { + if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_d, obj_box.tr_d, &intersect_point)) { this_zombie_collided = true; index_of_closest_zombie = i; } - if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_b, obj_box.bl_b, &intersect_point)) { + if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_d, obj_box.bl_d, &intersect_point)) { this_zombie_collided = true; index_of_closest_zombie = i; } - if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tr_b, obj_box.br_b, &intersect_point)) { + if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tr_d, obj_box.br_d, &intersect_point)) { this_zombie_collided = true; index_of_closest_zombie = i; } @@ -178,12 +178,9 @@ static bool check_if_bullet_collided_with_ground(bullet *b, platform_window* win } } return false; -} - -void draw_bullets(platform_window* window) { - float size = get_bullet_size(window); - map_info info = get_map_info(window); +} +void update_bullets(platform_window* window) { for (int i = 0; i < max_bullets; i++) { bullet b = bullets[i]; if (!b.active) continue; @@ -211,7 +208,17 @@ void draw_bullets(platform_window* window) { } bullets[i].alive_time += update_delta; - bullets[i].active = false; + //bullets[i].active = false; + } +} + +void draw_bullets(platform_window* window) { + float size = get_bullet_size(window); + map_info info = get_map_info(window); + + for (int i = 0; i < max_bullets; i++) { + bullet b = bullets[i]; + if (!b.active) continue; if ((int)bullets[i].position.y < (int)bullets[i].endy) { BULLET_RENDER_DEPTH((int)bullets[i].position.y); } else { BULLET_RENDER_DEPTH((int)bullets[i].endy); } @@ -223,5 +230,7 @@ void draw_bullets(platform_window* window) { float bullet_render_y_end = b.endy*info.tile_height - (b.position.z*info.px_raised_per_h); renderer->render_line(bullet_render_x, bullet_render_y, bullet_render_x_end, bullet_render_y_end, 2, rgb(0,255,100)); + + bullets[i].active = false; } }
\ No newline at end of file diff --git a/src/drops.c b/src/drops.c index f5f4fa0..5a8350f 100644 --- a/src/drops.c +++ b/src/drops.c @@ -1,5 +1,6 @@ #include "../include/drops.h" #include "../include/objects.h" +#include "../include/asset_defs.h" void handle_drop_pickup(player* p, drop* d) { if (!d->active) return; @@ -46,21 +47,42 @@ void draw_drops(platform_window* window) { b.position.y += 0.2f; b.position.x -= 0.07f; box shadow_box = get_render_box_of_square(window, b.position, b.size); - render_quad_with_outline(shadow_box.tl_b, shadow_box.tr_b, shadow_box.bl_b, shadow_box.br_b, rgba(0,0,0,120)); + render_quad_with_outline(shadow_box.tl_d, shadow_box.tr_d, shadow_box.bl_d, shadow_box.br_d, rgba(0,0,0,120)); render_quad_with_outline(shadow_box.tl_u, shadow_box.tr_u, shadow_box.bl_u, shadow_box.br_u, rgba(0,0,0,120)); - render_quad_with_outline(shadow_box.tl_u, shadow_box.tl_b, shadow_box.bl_u, shadow_box.bl_b, rgba(0,0,0,120)); - render_quad_with_outline(shadow_box.bl_u, shadow_box.br_u, shadow_box.bl_b, shadow_box.br_b, rgba(0,0,0,120)); + render_quad_with_outline(shadow_box.tl_u, shadow_box.tl_d, shadow_box.bl_u, shadow_box.bl_d, rgba(0,0,0,120)); + render_quad_with_outline(shadow_box.bl_u, shadow_box.br_u, shadow_box.bl_d, shadow_box.br_d, rgba(0,0,0,120)); b = drops[i]; box full_box = get_render_box_of_square(window, b.position, b.size); - render_quad_with_outline(full_box.tl_b, full_box.tr_b, full_box.bl_b, full_box.br_b, rgb(218,112,214)); + render_quad_with_outline(full_box.tl_d, full_box.tr_d, full_box.bl_d, full_box.br_d, rgb(218,112,214)); render_quad_with_outline(full_box.tl_u, full_box.tr_u, full_box.bl_u, full_box.br_u, rgb(218,112,214)); - render_quad_with_outline(full_box.tl_u, full_box.tl_b, full_box.bl_u, full_box.bl_b, rgb(218,112,214)); - render_quad_with_outline(full_box.bl_u, full_box.br_u, full_box.bl_b, full_box.br_b, rgb(218,112,214)); + render_quad_with_outline(full_box.tl_u, full_box.tl_d, full_box.bl_u, full_box.bl_d, rgb(218,112,214)); + render_quad_with_outline(full_box.bl_u, full_box.br_u, full_box.bl_d, full_box.br_d, rgb(218,112,214)); + + int drop_h = full_box.br_d.y - full_box.tr_d.y; + + int icon_size = full_box.tr_d.x - full_box.tl_d.x; + int icon_x = full_box.tl_u.x; + int icon_y = full_box.tl_u.y - icon_size + (drop_h/2); + switch(b.type) { + case DROP_AMMO: { + renderer->render_image(img_icon_bullets, icon_x, icon_y, icon_size, icon_size); + } break; + + default: break; + } } } void spawn_drop(vec3f pos) { + static int drop_percentage = 100; + int val = rand() % (100 + 1); + if (val > drop_percentage) { + drop_percentage += 2; + return; + } + drop_percentage = 100; + for (int i = 0; i < MAX_DROPS; i++) { drop b = drops[i]; if (b.active) continue; @@ -72,7 +94,7 @@ void spawn_drop(vec3f pos) { new_drop.size = (vec3f){0.3f, 0.3f, 0.4f}; new_drop.start_h = pos.z; new_drop.type = DROP_AMMO; - new_drop.data.ammo_count = 10; + new_drop.data.ammo_count = 20; drops[i] = new_drop; break; @@ -1,8 +1,6 @@ #include "../include/game.h" #include "../include/pathfinding.h" -u32 current_id = 0; - static void server_on_client_disconnect(network_client c) { for (int i = 0; i < max_players; i++) { player p = players[i]; @@ -19,7 +17,14 @@ void start_server(char* port) { global_state.server->on_client_disconnect = server_on_client_disconnect; } +static u32 get_session_id() { + u32 time = platform_get_time(TIME_NS, TIME_FULL); + return (((time * 2654435789U) + time) * 2654435789U) + platform_get_processid(); + +} + void connect_to_server(char* ip, char* port) { + player_id = get_session_id(); messages_received_on_client = array_create(sizeof(protocol_generic_message*)); array_reserve(&messages_received_on_client, 100); @@ -27,17 +32,18 @@ void connect_to_server(char* ip, char* port) { global_state.client = network_connect_to_server(ip, port); global_state.client->on_message = client_on_message_received; + log_infox("Session id: %u", player_id); + if (global_state.server) { - my_id = current_id++; - spawn_player(my_id, (network_client){0, false, 0, "Host"}); + player_id = player_id; + spawn_player(player_id, (network_client){0, false, 0, "Host"}); global_state.network_state = CONNECTED; - printf("Server id: %d\n", my_id); } else { if (global_state.client->is_connected) { global_state.network_state = WAITING_FOR_ID; - network_message message = create_protocol_get_id_up(); + network_message message = create_protocol_get_id_up(player_id); network_client_send(global_state.client, message); } } @@ -107,11 +113,6 @@ static void set_ping_for_player(protocol_generic_message* msg) { float update_timer = 0.0f; void update_server(platform_window* window) { - update_spawners(); - update_drops(); - update_players_server(); - update_zombies_server(window); - for (int i = 0; i < messages_received_on_server.length; i++) { protocol_generic_message* msg = *(protocol_generic_message**)array_at(&messages_received_on_server, i); set_ping_for_player(msg); @@ -119,10 +120,9 @@ void update_server(platform_window* window) { switch (msg->message->type) { case MESSAGE_GET_ID_UPSTREAM: { - network_client_send(&msg->client, create_protocol_get_id_down(current_id)); - spawn_player(current_id, msg->client); - - current_id++; + protocol_get_id_upstream* m = (protocol_get_id_upstream*)msg->message; + network_client_send(&msg->client, create_protocol_get_id_down(m->id)); + spawn_player(m->id, msg->client); log_info("Player connected to server"); } break; @@ -151,6 +151,12 @@ void update_server(platform_window* window) { i--; } + update_spawners(); + update_drops(); + update_bullets(window); + update_players_server(); + update_zombies_server(window); + if (update_timer > 0.0f) { broadcast_to_clients(create_protocol_user_list()); broadcast_to_clients(create_protocol_zombie_list()); @@ -162,7 +168,7 @@ void update_server(platform_window* window) { } static void apply_user_list(protocol_user_list* msg_players) { - player* p = get_player_by_id(my_id); + player* p = get_player_by_id(player_id); player copy; if (p) copy = *p; memcpy(players, msg_players->players, sizeof(players)); @@ -185,10 +191,9 @@ void update_client(platform_window* window) { { case MESSAGE_GET_ID_DOWNSTREAM: { protocol_get_id_downstream* msg_id = (protocol_get_id_downstream*)msg; - my_id = msg_id->id; + player_id = msg_id->id; global_state.network_state = CONNECTED; - printf("Received id: %d\n", my_id); - log_info("Id received"); + log_infox("Id received: %d", player_id); } break; case MESSAGE_USER_LIST: { @@ -141,8 +141,8 @@ float get_height_of_tile_under_coords(platform_window* window, float tocheckx, f } inline int get_tile_width(platform_window* window) { - int tile_width = window->height / 14; - if (window->width > window->height) tile_width = window->width / 14; + int tile_width = window->height / 30; + if (window->width > window->height) tile_width = window->width / 30; return tile_width; } diff --git a/src/objects.c b/src/objects.c index c82f27f..350529d 100644 --- a/src/objects.c +++ b/src/objects.c @@ -37,10 +37,10 @@ void draw_objects_at_row(platform_window* window, int row) { if (!o.active) continue; box box = get_box_of_object(window, o); - render_quad_with_outline(box.tl_b, box.tr_b, box.bl_b, box.br_b, rgb(200,200,0)); + render_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgb(200,200,0)); render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgb(200,200,0)); - render_quad_with_outline(box.tl_u, box.tl_b, box.bl_u, box.bl_b, rgb(200,200,0)); - render_quad_with_outline(box.bl_u, box.br_u, box.bl_b, box.br_b, rgb(200,200,0)); + render_quad_with_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, rgb(200,200,0)); + render_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, rgb(200,200,0)); } } diff --git a/src/overlay.c b/src/overlay.c index de84aa7..9be8329 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -6,7 +6,7 @@ #define EDGE_PADDING 10 static void draw_gun_info(platform_window* window) { - player *p = get_player_by_id(my_id); + player *p = get_player_by_id(player_id); if (!p) return; gun g = get_gun_by_type(p->guntype); diff --git a/src/players.c b/src/players.c index 390a30f..5509067 100644 --- a/src/players.c +++ b/src/players.c @@ -26,7 +26,7 @@ int get_player_count() { return count; } -void spawn_player(int id, network_client client) { +void spawn_player(u32 id, network_client client) { for (int i = 0; i < max_players; i++) { if (players[i].active) continue; players[i].active = true; @@ -110,8 +110,8 @@ bool check_if_player_collided_with_box(player p, box o) { box pbox = get_box_of_square((vec3f){p.playerx, p.playery, p.height}, (vec3f){player_size,player_size,0.8f}); // [x1, y1, x2, y2] - bool b1 = min(pbox.br_u.x, o.br_b.x) > max(pbox.tl_u.x, o.tl_u.x); - bool b2 = min(pbox.br_u.y, o.br_b.y) > max(pbox.tl_u.y, o.tl_u.y); + bool b1 = min(pbox.br_u.x, o.br_d.x) > max(pbox.tl_u.x, o.tl_u.x); + bool b2 = min(pbox.br_u.y, o.br_d.y) > max(pbox.tl_u.y, o.tl_u.y); return b1 && b2; } @@ -134,42 +134,42 @@ object check_if_player_collided_with_object(platform_window* window, player p) { int get_my_player_index() { for (int i = 0; i < max_players; i++) { if (!players[i].active) continue; - if (players[i].id == my_id) return i; + if (players[i].id == player_id) return i; } return -1; } void take_player_input(platform_window* window) { - player* p = get_player_by_id(my_id); + player* p = get_player_by_id(player_id); if (!p) return; if (keyboard_is_key_down(KEY_W)) { if (!global_state.server) { - network_message message = create_protocol_user_moved(MOVE_UP, my_id); + network_message message = create_protocol_user_moved(MOVE_UP, player_id); network_client_send(global_state.client, message); } - move_user(window, my_id, MOVE_UP); + move_user(window, player_id, MOVE_UP); } if (keyboard_is_key_down(KEY_S)) { if (!global_state.server) { - network_message message = create_protocol_user_moved(MOVE_DOWN, my_id); + network_message message = create_protocol_user_moved(MOVE_DOWN, player_id); network_client_send(global_state.client, message); } - move_user(window, my_id, MOVE_DOWN); + move_user(window, player_id, MOVE_DOWN); } if (keyboard_is_key_down(KEY_A)) { if (!global_state.server) { - network_message message = create_protocol_user_moved(MOVE_LEFT, my_id); + network_message message = create_protocol_user_moved(MOVE_LEFT, player_id); network_client_send(global_state.client, message); } - move_user(window, my_id, MOVE_LEFT); + move_user(window, player_id, MOVE_LEFT); } if (keyboard_is_key_down(KEY_D)) { if (!global_state.server) { - network_message message = create_protocol_user_moved(MOVE_RIGHT, my_id); + network_message message = create_protocol_user_moved(MOVE_RIGHT, player_id); network_client_send(global_state.client, message); } - move_user(window, my_id, MOVE_RIGHT); + move_user(window, player_id, MOVE_RIGHT); } // Send gun position @@ -186,7 +186,7 @@ void take_player_input(platform_window* window) { p->gunx = p->playerx + gun_offset_x; p->guny = p->playery + gun_offset_y; - network_client_send(global_state.client, create_protocol_user_look(my_id, gun_offset_x, gun_offset_y)); + network_client_send(global_state.client, create_protocol_user_look(player_id, gun_offset_x, gun_offset_y)); } // shoot @@ -198,7 +198,7 @@ void take_player_input(platform_window* window) { dirx /= length; diry /= length; - network_message message = create_protocol_user_shoot(my_id, dirx, diry); + network_message message = create_protocol_user_shoot(player_id, dirx, diry); network_client_send(global_state.client, message); } } @@ -216,16 +216,16 @@ void draw_players(platform_window* window) { for (int i = 0; i < max_players; i++) { if (!players[i].active) continue; - OBJECT_RENDER_DEPTH((int)(players[i].playery)); + OBJECT_RENDER_DEPTH((int)(players[i].playery+size)); float height = get_height_of_tile_under_coords(window, players[i].playerx, players[i].playery); players[i].height = height; box box = get_render_box_of_square(window, (vec3f){players[i].playerx, players[i].playery, height}, (vec3f){size,size,0.8f}); - render_quad_with_outline(box.tl_b, box.tr_b, box.bl_b, box.br_b, rgb(200,150,120)); + render_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgb(200,150,120)); render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgb(200,150,120)); - render_quad_with_outline(box.tl_u, box.tl_b, box.bl_u, box.bl_b, rgb(200,150,120)); - render_quad_with_outline(box.bl_u, box.br_u, box.bl_b, box.br_b, rgb(200,150,120)); + render_quad_with_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, rgb(200,150,120)); + render_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, rgb(200,150,120)); int size = get_tile_width(window) / 2; map_info info = get_map_info(window); @@ -240,7 +240,7 @@ void draw_players(platform_window* window) { renderer->render_rectangle(gun_render_x, gun_render_y, size/4, size/4, rgb(20,255,20)); - if (players[i].id == my_id) { + if (players[i].id == player_id) { _next_camera_pos.x = -(window->width / 2) + player_render_x; _next_camera_pos.y = -(window->height / 2) + player_render_y; } diff --git a/src/protocol.c b/src/protocol.c index eb0d200..cdc14b8 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -1,10 +1,11 @@ #include "../include/protocol.h" #include "../include/players.h" -network_message create_protocol_get_id_up() +network_message create_protocol_get_id_up(u32 id) { protocol_get_id_upstream *buf = (protocol_get_id_upstream *)network_buffer; buf->type = MESSAGE_GET_ID_UPSTREAM; + buf->id = id; return network_create_message(network_buffer, sizeof(protocol_get_id_upstream), MAX_NETWORK_BUFFER_SIZE); } diff --git a/src/zombies.c b/src/zombies.c index 043bce1..fd47ea3 100644 --- a/src/zombies.c +++ b/src/zombies.c @@ -216,10 +216,10 @@ void draw_zombies(platform_window* window) { OBJECT_RENDER_DEPTH((int)o.position.y); box box = get_render_box_of_square(window, (vec3f){o.position.x, o.position.y, o.position.z}, o.size); - render_quad_with_outline(box.tl_b, box.tr_b, box.bl_b, box.br_b, rgb(200,200,0)); + render_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgb(200,200,0)); render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgb(200,200,0)); - render_quad_with_outline(box.tl_u, box.tl_b, box.bl_u, box.bl_b, rgb(200,200,0)); - render_quad_with_outline(box.bl_u, box.br_u, box.bl_b, box.br_b, rgb(200,200,0)); + render_quad_with_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, rgb(200,200,0)); + render_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, rgb(200,200,0)); if (global_state.server) draw_path_of_zombie(window, o); } |
