diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-15 16:44:17 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-15 16:44:17 +0100 |
| commit | 66b82a20506b53ce8dc5dde8e6ea0979a22610f0 (patch) | |
| tree | 32b6e62c93e9f68a907f2095243e931614de1670 /src | |
| parent | 8c086739e1344fb8789e89074dd962c5719ab030 (diff) | |
work
Diffstat (limited to 'src')
| -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 |
6 files changed, 33 insertions, 19 deletions
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); } } |
