diff options
| -rw-r--r-- | data/imgs/ui/skull.png | bin | 0 -> 193251 bytes | |||
| -rw-r--r-- | data/psd/skull.psd | bin | 0 -> 1342821 bytes | |||
| -rw-r--r-- | include/asset_defs.h | 1 | ||||
| -rw-r--r-- | include/game.h | 3 | ||||
| -rw-r--r-- | include/protocol.h | 1 | ||||
| -rw-r--r-- | include/rounds.h | 5 | ||||
| -rw-r--r-- | src/asset_defs.c | 1 | ||||
| -rw-r--r-- | src/game.c | 14 | ||||
| -rw-r--r-- | src/overlay.c | 43 | ||||
| -rw-r--r-- | src/protocol.c | 1 | ||||
| -rw-r--r-- | src/rounds.c | 24 |
11 files changed, 77 insertions, 16 deletions
diff --git a/data/imgs/ui/skull.png b/data/imgs/ui/skull.png Binary files differnew file mode 100644 index 0000000..1531d90 --- /dev/null +++ b/data/imgs/ui/skull.png diff --git a/data/psd/skull.psd b/data/psd/skull.psd Binary files differnew file mode 100644 index 0000000..3fa5956 --- /dev/null +++ b/data/psd/skull.psd diff --git a/include/asset_defs.h b/include/asset_defs.h index 8379656..8249177 100644 --- a/include/asset_defs.h +++ b/include/asset_defs.h @@ -33,6 +33,7 @@ font* fnt_4; // UI image* img_red_border; image* img_heart; +image* img_skull; image* img_hurt_overlay_left; image* img_hurt_overlay_right; image* img_stats_overlay; diff --git a/include/game.h b/include/game.h index 2884a92..91f471d 100644 --- a/include/game.h +++ b/include/game.h @@ -39,12 +39,13 @@ typedef struct t_game { scene_state global_scene_state = SCENE_MAIN_MENU; game global_state = {GAMESTATE_IDLE,DISCONNECTED,0,0}; -bool game_is_paused = false; +extern bool game_is_paused; pathfinding_request active_requests[SERVER_PATHFINDING_THREADS] = {0}; void init_game(); void start_solo_game(); bool connect_to_game(char* ip, char* port); void fill_game_structs(); +bool every_player_died(); #endif
\ No newline at end of file diff --git a/include/protocol.h b/include/protocol.h index d89952c..001e601 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -95,6 +95,7 @@ typedef struct t_protocol_round { network_message_type type; zombie_round round; + bool game_is_paused; } protocol_round; typedef enum t_protocol_move_type diff --git a/include/rounds.h b/include/rounds.h index e13f58d..2a93f30 100644 --- a/include/rounds.h +++ b/include/rounds.h @@ -10,14 +10,17 @@ typedef enum t_round_state { ROUND_SWITCHING, } round_state; +#define FADE_IN_DURATION 3.0f + typedef struct t_zombie_round { u32 round_nr; u32 zombies; round_state state; float round_timer; + float fade_in_timer; } zombie_round; -zombie_round _current_round = {.round_nr = 12, .zombies = 0, .state = ROUND_SWITCHING}; +zombie_round _current_round = {.round_nr = 0, .zombies = 0, .state = ROUND_SWITCHING, 3.0f}; bool current_round_is_done(); void start_next_round(); diff --git a/src/asset_defs.c b/src/asset_defs.c index 495f064..171c759 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -33,6 +33,7 @@ void load_assets() { // Assets loaded at match start. // UI img_red_border = assets_load_image_from_file("data/imgs/ui/red_border.png"); img_heart = assets_load_image_from_file("data/imgs/ui/heart.png"); + img_skull = assets_load_image_from_file("data/imgs/ui/skull.png"); img_hurt_overlay_left = assets_load_image_from_file("data/imgs/ui/hurt_overlay_left.png"); img_hurt_overlay_right = assets_load_image_from_file("data/imgs/ui/hurt_overlay_right.png"); img_stats_overlay = assets_load_image_from_file("data/imgs/ui/stats_overlay.png"); @@ -1,6 +1,8 @@ #include "../include/game.h" #include "../include/pathfinding.h" +bool game_is_paused = false; + static void server_on_client_disconnect(network_client c) { for (int i = 0; i < MAX_PLAYERS; i++) { player p = players[i]; @@ -241,6 +243,17 @@ static void rotate_user(platform_window* window, protocol_user_look *message) { p->diry = message->diry; } +bool every_player_died() +{ + for (int i = 0; i < MAX_PLAYERS; i++) { + player p = players[i]; + if (!p.active) continue; + // TODO: if player is disconnected for 2+ min, kill player. + if (p.health != 0) return false; + } + return true; +} + static void set_ping_for_player(protocol_generic_message* msg) { u64 diff = platform_get_time(TIME_FULL, TIME_MILI_S) - msg->send_timestamp; @@ -430,6 +443,7 @@ void update_client(platform_window* window) { case MESSAGE_ROUND_DATA: { protocol_round* msg_round = (protocol_round*)msg; _current_round = msg_round->round; + game_is_paused = msg_round->game_is_paused; } break; case MESSAGE_ZOMBIE_LIST: { diff --git a/src/overlay.c b/src/overlay.c index 185173e..988406e 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -234,23 +234,30 @@ static void draw_hurt_borders(platform_window* window) { if (!p) return; if (p->max_health == p->health) return; - if (p->health == 0) return; - - float freq = 1.0f * (p->health/(float)p->max_health); - static float heatbeat_timestamp = 0.0f; - heatbeat_timestamp += update_delta; + if (p->health == 0) + { + int skull_size = window->width / 7; + renderer->render_image(img_skull, + _global_camera.x + (window->width/2)-(skull_size/2), + _global_camera.y + (window->height/2)-(skull_size/2), skull_size, skull_size); + } + else { + float freq = 1.0f * (p->health/(float)p->max_health); + static float heatbeat_timestamp = 0.0f; + heatbeat_timestamp += update_delta; - float opacity = 1.0f - (heatbeat_timestamp / freq); - int heart_size = window->width / 7; - color c = rgba(255,255,255,255*opacity); + float opacity = 1.0f - (heatbeat_timestamp / freq); + int heart_size = window->width / 7; + color c = rgba(255,255,255,255*opacity); - renderer->render_image_tint(img_heart, - _global_camera.x + (window->width/2)-(heart_size/2), - _global_camera.y + (window->height/2)-(heart_size/2), heart_size, heart_size, c); + renderer->render_image_tint(img_heart, + _global_camera.x + (window->width/2)-(heart_size/2), + _global_camera.y + (window->height/2)-(heart_size/2), heart_size, heart_size, c); - if (heatbeat_timestamp >= freq) { - heatbeat_timestamp = 0.0f; - play_sound(-1, wav_heartbeat); + if (heatbeat_timestamp >= freq) { + heatbeat_timestamp = 0.0f; + play_sound(-1, wav_heartbeat); + } } float border_opacity = 1.0f - (p->health/(float)p->max_health); @@ -314,6 +321,13 @@ static void draw_global_message(platform_window* window) { renderer->render_text(fnt_52, x + (window->width/2)-(text_w/2), y, text, rgb(255,255,255)); } +static void draw_fadein_overlay(platform_window* window) +{ + float percentage = _current_round.fade_in_timer / FADE_IN_DURATION; + if (percentage <= 0.0f) return; + renderer->render_rectangle(_global_camera.x, _global_camera.y, window->width, window->height, rgba(0,0,0,255*percentage)); +} + void draw_overlay(platform_window* window) { draw_hurt_borders(window); draw_gun_info(window); @@ -321,4 +335,5 @@ void draw_overlay(platform_window* window) { draw_leaderboard(window); draw_debug_stats(window); draw_global_message(window); + draw_fadein_overlay(window); }
\ No newline at end of file diff --git a/src/protocol.c b/src/protocol.c index cfcbd10..1070ff0 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -88,6 +88,7 @@ network_message create_protocol_round_data(zombie_round round) protocol_round *buf = alloc_network_message(protocol_round); buf->type = MESSAGE_ROUND_DATA; buf->round = round; + buf->game_is_paused = game_is_paused; return network_create_message((u8*)buf, sizeof(protocol_round), MAX_NETWORK_BUFFER_SIZE); } diff --git a/src/rounds.c b/src/rounds.c index 4d69aff..4c991af 100644 --- a/src/rounds.c +++ b/src/rounds.c @@ -21,6 +21,11 @@ void start_next_round() _current_round.state = ROUND_SWITCHING; _current_round.round_timer = 0.0f; + // Fade in at start of game. + if (_current_round.round_nr == 1) { + _current_round.fade_in_timer = FADE_IN_DURATION; + } + add_ui_audio_event_to_queue(EVENT_ROUND_CHANGE); log_infox("Next round: %d", _current_round.round_nr); @@ -85,10 +90,29 @@ void draw_round(platform_window* window) { } } +void restart_game() +{ + // TODO +} + void update_round_server() { static int visible_previously_count = 0; + if (!every_player_died()) { + _current_round.fade_in_timer -= SERVER_TICK_RATE; + if (_current_round.fade_in_timer <= 0.0f) + _current_round.fade_in_timer = 0.0f; + } + else { + _current_round.fade_in_timer += SERVER_TICK_RATE; + if (_current_round.fade_in_timer >= FADE_IN_DURATION) { + _current_round.fade_in_timer = FADE_IN_DURATION; + + restart_game(); + } + } + _current_round.round_timer += SERVER_TICK_RATE; if (_current_round.state == ROUND_SWITCHING) { if (_current_round.round_timer >= ROUND_SWITCH_TIME) { |
