diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/game.c | 6 | ||||
| -rw-r--r-- | src/protocol.c | 8 | ||||
| -rw-r--r-- | src/zombie_chunk.c | 23 |
3 files changed, 30 insertions, 7 deletions
@@ -231,6 +231,7 @@ void update_server(platform_window* window) { broadcast_to_clients(create_protocol_bullets_list()); broadcast_to_clients(create_protocol_drop_list()); broadcast_to_clients(create_protocol_throwables_list()); + broadcast_to_clients(create_protocol_zombie_chunk_list()); // play sounds locally and send them to clients. play_sounds_in_queue(); @@ -292,6 +293,11 @@ void update_client(platform_window* window) { memcpy(zombies, msg_zombies->zombies, sizeof(zombies)); } break; + case MESSAGE_ZOMBIE_CHUNK_LIST: { + protocol_zombie_chunk_list* msg_zombies = (protocol_zombie_chunk_list*)msg; + memcpy(zombie_chunks, msg_zombies->zombie_chunks, sizeof(zombie_chunks)); + } break; + case MESSAGE_THROWABLES_LIST: { protocol_throwables_list* msg_throwables = (protocol_throwables_list*)msg; memcpy(throwables, msg_throwables->throwables, sizeof(throwables)); diff --git a/src/protocol.c b/src/protocol.c index a33f421..d8506b7 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -51,6 +51,14 @@ network_message create_protocol_zombie_list() return network_create_message((u8*)buf, sizeof(protocol_zombie_list), MAX_NETWORK_BUFFER_SIZE); } +network_message create_protocol_zombie_chunk_list() +{ + protocol_zombie_chunk_list *buf = alloc_network_message(protocol_zombie_chunk_list); + buf->type = MESSAGE_ZOMBIE_CHUNK_LIST; + memcpy(buf->zombie_chunks, zombie_chunks, sizeof(zombie_chunks)); + return network_create_message((u8*)buf, sizeof(protocol_zombie_chunk_list), MAX_NETWORK_BUFFER_SIZE); +} + network_message create_protocol_bullets_list() { protocol_bullets_list *buf = alloc_network_message(protocol_bullets_list); diff --git a/src/zombie_chunk.c b/src/zombie_chunk.c index 9a10e00..02e7027 100644 --- a/src/zombie_chunk.c +++ b/src/zombie_chunk.c @@ -10,11 +10,20 @@ static vec2f get_random_point_around_point(vec3f center, float distance) { return (vec2f){x, y}; } -static image* get_chunk_image() { +static image* get_chunk_image_from_type(zombie_chunk_type type) { + switch(type) { + default: + case CHUNK_HAND: return img_zombie_chunk_hand; + case CHUNK_FOOT: return img_zombie_chunk_foot; + case CHUNK_SPLATTER: return img_zombie_chunk_blood; + } +} + +static zombie_chunk_type get_random_chunk_type() { #define AVAILABLE_ZOMBIE_CHUNK_COUNT 2 - image* available_zombie_chunks[AVAILABLE_ZOMBIE_CHUNK_COUNT] = { - img_zombie_chunk_hand, - img_zombie_chunk_foot, + zombie_chunk_type available_zombie_chunks[AVAILABLE_ZOMBIE_CHUNK_COUNT] = { + CHUNK_HAND, + CHUNK_FOOT, }; return available_zombie_chunks[rand() % AVAILABLE_ZOMBIE_CHUNK_COUNT]; } @@ -30,7 +39,7 @@ void spawn_zombie_splatter(vec3f center) { zombie_chunk chunk = {.active = true, .start_position = center, .direction = dir, .position = center, .duration = 0.0f, .target_position = center, - .img = img_zombie_chunk_blood, .rotation = (float)rand()/(float)(RAND_MAX), .rotation_speed = 0.0f}; + .type = CHUNK_SPLATTER, .rotation = (float)rand()/(float)(RAND_MAX), .rotation_speed = 0.0f}; zombie_chunks[i] = chunk; return; } @@ -47,7 +56,7 @@ void spawn_zombie_chunk(vec3f center) { zombie_chunk chunk = {.active = true, .start_position = center, .direction = dir, .position = center, .duration = 0.0f, .target_position = (vec3f){target.x, target.y, height}, - .img = get_chunk_image(), .rotation = (float)rand()/(float)(RAND_MAX), .rotation_speed = dir.x < 0.0f ? update_delta : -update_delta}; + .type = get_random_chunk_type(), .rotation = (float)rand()/(float)(RAND_MAX), .rotation_speed = dir.x < 0.0f ? update_delta : -update_delta}; zombie_chunks[i] = chunk; return; } @@ -97,7 +106,7 @@ void draw_zombie_chunks(platform_window* window) { //render_box_with_outline(box, rgba(200, 50, 50, alpha)); renderer->render_set_rotation(zombie_chunks[i].rotation); - renderer->render_image_tint(zombie_chunks[i].img, box.tl_d.x, box.tl_d.y, box.tr_d.x - box.tl_d.x, box.br_d.y - box.tr_d.y, rgba(255,255,255,alpha)); + renderer->render_image_tint(get_chunk_image_from_type(zombie_chunks[i].type), box.tl_d.x, box.tl_d.y, box.tr_d.x - box.tl_d.x, box.br_d.y - box.tr_d.y, rgba(255,255,255,alpha)); renderer->render_set_rotation(0.0f); } }
\ No newline at end of file |
