diff options
| -rw-r--r-- | build/zombies.exe | bin | 1733868 -> 1733882 bytes | |||
| -rw-r--r-- | include/protocol.h | 12 | ||||
| -rw-r--r-- | include/zombies.h | 8 | ||||
| -rw-r--r-- | src/bullets.c | 5 | ||||
| -rw-r--r-- | src/drops.c | 4 | ||||
| -rw-r--r-- | src/game.c | 9 | ||||
| -rw-r--r-- | src/map.c | 10 | ||||
| -rw-r--r-- | src/protocol.c | 9 | ||||
| -rw-r--r-- | src/zombies.c | 15 |
9 files changed, 49 insertions, 23 deletions
diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex fc90201..47da708 100644 --- a/build/zombies.exe +++ b/build/zombies.exe diff --git a/include/protocol.h b/include/protocol.h index f02e873..a49aaab 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -13,6 +13,7 @@ typedef enum t_network_message_type MESSAGE_ZOMBIE_LIST, MESSAGE_USER_SHOOT, MESSAGE_BULLET_LIST, + MESSAGE_DROP_LIST, } network_message_type; typedef struct t_protocol_generic_client_message @@ -45,12 +46,20 @@ typedef struct t_protocol_user_list player players[10]; } protocol_user_list; +#include "zombies.h" typedef struct t_protocol_zombie_list { network_message_type type; - zombie zombies[20]; + zombie zombies[MAX_ZOMBIES]; } protocol_zombie_list; +#include "drops.h" +typedef struct t_protocol_drop_list +{ + network_message_type type; + drop drops[MAX_DROPS]; +} protocol_drop_list; + typedef enum t_protocol_move_type { MOVE_UP, @@ -100,6 +109,7 @@ network_message create_protocol_user_look(u32 id, float gunx, float guny); network_message create_protocol_user_shoot(u32 id, float dirx, float diry); network_message create_protocol_zombie_list(); network_message create_protocol_bullets_list(); +network_message create_protocol_drop_list(); array messages_received_on_server; array messages_received_on_client; diff --git a/include/zombies.h b/include/zombies.h index df5e629..c99063e 100644 --- a/include/zombies.h +++ b/include/zombies.h @@ -24,14 +24,16 @@ typedef struct t_spawner { float sec_since_last_spawn; } spawner; +#define MAX_SPAWNERS (3) // data data that is stored on disk -spawner spawner_tiles[2] = { +spawner spawner_tiles[MAX_SPAWNERS] = { {15, 5, 999}, {3, 8, 999}, + {11, 18, 999}, }; -zombie zombies[20] = {0}; -int max_zombies = 20; +#define MAX_ZOMBIES (50) +zombie zombies[MAX_ZOMBIES] = {0}; void draw_spawners(platform_window* window); void draw_zombies(platform_window* window); diff --git a/src/bullets.c b/src/bullets.c index 69ba22c..4431eff 100644 --- a/src/bullets.c +++ b/src/bullets.c @@ -112,7 +112,7 @@ bool check_if_bullet_collided_with_zombie(bullet b, platform_window* window, boo float dist_of_closest_intersect = __FLT_MAX__; int index_of_closest_zombie = -1; - for (int i = 0; i < max_zombies; i++) { + for (int i = 0; i < MAX_ZOMBIES; i++) { zombie o = zombies[i]; if (!o.alive) continue; @@ -203,7 +203,6 @@ void update_bullets(platform_window* window) { } if (check_if_bullet_collided_with_zombie(b, window, true)) { - bullets[i].active = false; p->kills++; } @@ -229,7 +228,7 @@ void draw_bullets(platform_window* window) { float bullet_render_x_end = b.endx*info.tile_width + (b.endy*info.px_incline); 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)); + renderer->render_line(bullet_render_x, bullet_render_y, bullet_render_x_end, bullet_render_y_end, 5, rgb(255, 51, 51)); bullets[i].active = false; } diff --git a/src/drops.c b/src/drops.c index 5a8350f..a03f7ca 100644 --- a/src/drops.c +++ b/src/drops.c @@ -75,13 +75,13 @@ void draw_drops(platform_window* window) { } void spawn_drop(vec3f pos) { - static int drop_percentage = 100; + static int drop_percentage = 15; int val = rand() % (100 + 1); if (val > drop_percentage) { drop_percentage += 2; return; } - drop_percentage = 100; + drop_percentage = 15; for (int i = 0; i < MAX_DROPS; i++) { drop b = drops[i]; @@ -161,6 +161,7 @@ void update_server(platform_window* window) { broadcast_to_clients(create_protocol_user_list()); broadcast_to_clients(create_protocol_zombie_list()); broadcast_to_clients(create_protocol_bullets_list()); + broadcast_to_clients(create_protocol_drop_list()); update_timer = 0.0f; } @@ -205,7 +206,7 @@ void update_client(platform_window* window) { case MESSAGE_ZOMBIE_LIST: { if (global_state.server) break; // zombies are simulated on server so dont overwrite data. protocol_zombie_list* msg_zombies = (protocol_zombie_list*)msg; - memcpy(zombies, msg_zombies->zombies, sizeof(zombies)); + memcpy(zombies, msg_zombies->zombies, sizeof(zombies)); } break; case MESSAGE_BULLET_LIST: { @@ -213,6 +214,12 @@ void update_client(platform_window* window) { protocol_bullets_list* msg_bullets = (protocol_bullets_list*)msg; memcpy(bullets, msg_bullets->bullets, sizeof(bullets)); } break; + + case MESSAGE_DROP_LIST: { + if (global_state.server) break; // drops are simulated on server so dont overwrite data. + protocol_drop_list* msg_drops = (protocol_drop_list*)msg; + memcpy(drops, msg_drops->drops, sizeof(drops)); + } break; default: log_info("Unhandled message received"); break; @@ -193,25 +193,25 @@ void draw_grid(platform_window* window) { int highest_point_bottomleft = tile.bottomleft; bottomleft = (vec2f){render_x + xdiff_between_bottom_and_top, info.tile_height * y + info.tile_height - highest_point_bottomleft*info.px_raised_per_h}; - int r = 220; + color c = rgb(128, 64, 0); if (highest_point_topleft > highest_point_bottomleft || highest_point_topright > highest_point_bottomright || highest_point_topleft > highest_point_bottomright || highest_point_topright > highest_point_bottomleft || - highest_point_topright > highest_point_topleft || highest_point_bottomright > highest_point_bottomleft) r = 180; + highest_point_topright > highest_point_topleft || highest_point_bottomright > highest_point_bottomleft) c = rgb(108, 64, 0); if (highest_point_topleft < highest_point_bottomleft || highest_point_topright < highest_point_bottomright || - highest_point_topleft > highest_point_topright) r = 240; + highest_point_topleft > highest_point_topright) c = rgb(148, 64, 0); renderer->render_quad( topleft.x, topleft.y, bottomleft.x, bottomleft.y, bottomright.x, bottomright.y, topright.x, topright.y, - rgb(r,0,0)); + c); if (highest_point_topleft != highest_point_bottomright && highest_point_bottomleft == highest_point_topright) { if (highest_point_bottomleft < highest_point_topleft || highest_point_bottomleft < highest_point_bottomright) { renderer->render_tri(topleft.x, topleft.y, bottomleft.x, bottomleft.y, - bottomright.x, bottomright.y, rgb(180,0,0)); + bottomright.x, bottomright.y, rgb(108, 64, 0)); } renderer->render_line(topleft.x, topleft.y, bottomright.x, bottomright.y, 1, rgb(0,0,255)); // diag } diff --git a/src/protocol.c b/src/protocol.c index cdc14b8..628dc6f 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -41,6 +41,15 @@ network_message create_protocol_bullets_list() return network_create_message(network_buffer, sizeof(protocol_bullets_list), MAX_NETWORK_BUFFER_SIZE); } +network_message create_protocol_drop_list() +{ + protocol_drop_list *buf = (protocol_drop_list *)network_buffer; + buf->type = MESSAGE_DROP_LIST; + memcpy(buf->drops, drops, sizeof(drops)); + return network_create_message(network_buffer, sizeof(protocol_drop_list), MAX_NETWORK_BUFFER_SIZE); +} + + network_message create_protocol_user_moved(protocol_move_type move, u32 id) { protocol_move *buf = (protocol_move *)network_buffer; diff --git a/src/zombies.c b/src/zombies.c index fd47ea3..76c5267 100644 --- a/src/zombies.c +++ b/src/zombies.c @@ -24,7 +24,7 @@ static player get_closest_player_to_tile(int x, int y) { } void spawn_zombie(int x, int y) { - for (int i = 0; i < max_zombies; i++) { + for (int i = 0; i < MAX_ZOMBIES; i++) { zombie o = zombies[i]; if (o.alive) continue; @@ -46,7 +46,7 @@ void spawn_zombie(int x, int y) { } void update_spawners() { - for (int x = 0; x < 1; x++) { + for (int x = 0; x < MAX_SPAWNERS; x++) { spawner spawner = spawner_tiles[x]; spawner_tiles[x].sec_since_last_spawn += update_delta; if (spawner_tiles[x].sec_since_last_spawn >= 2.0f) { @@ -59,7 +59,7 @@ void update_spawners() { void draw_spawners(platform_window* window) { map_info info = get_map_info(window); - for (int x = 0; x < 1; x++) { + for (int x = 0; x < MAX_SPAWNERS; 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; @@ -138,7 +138,7 @@ static bool is_within_next_tile(zombie o) { void update_zombies_client(platform_window* window) { float speed = 0.05f; - for (int i = 0; i < max_zombies; i++) { + for (int i = 0; i < MAX_ZOMBIES; i++) { zombie o = zombies[i]; if (!o.alive) continue; if (o.next2tiles[0].x == -1 || o.next2tiles[0].y == -1) continue; // ran out of stored path. @@ -160,7 +160,7 @@ void update_zombies_client(platform_window* window) { void update_zombies_server(platform_window* window) { float speed = 0.05f; - for (int i = 0; i < max_zombies; i++) { + for (int i = 0; i < MAX_ZOMBIES; i++) { zombie o = zombies[i]; if (!o.alive) continue; @@ -208,11 +208,10 @@ void update_zombies_server(platform_window* window) { void draw_zombies(platform_window* window) { map_info info = get_map_info(window); - for (int i = 0; i < max_zombies; i++) { + for (int i = 0; i < MAX_ZOMBIES; i++) { zombie o = zombies[i]; if (!o.alive) continue; - //if ((int)o.position.x != x || (int)ceil(o.position.y) != y) continue; 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); @@ -221,7 +220,7 @@ void draw_zombies(platform_window* window) { 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); + //if (global_state.server) draw_path_of_zombie(window, o); } } |
