diff options
| -rw-r--r-- | build/zombies.exe | bin | 1992896 -> 1992936 bytes | |||
| -rw-r--r-- | src/game.c | 1 | ||||
| -rw-r--r-- | src/players.c | 68 |
3 files changed, 39 insertions, 30 deletions
diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex d083f6a..a19cc0f 100644 --- a/build/zombies.exe +++ b/build/zombies.exe @@ -316,6 +316,7 @@ void update_client(platform_window* window) { logic_update_time = platform_get_time(TIME_FULL, TIME_NS) - logic_update_time; update_zombies_client(window); + update_players_client(); } void update_game(platform_window* window) { diff --git a/src/players.c b/src/players.c index 7ac0819..d88ac97 100644 --- a/src/players.c +++ b/src/players.c @@ -82,6 +82,7 @@ void move_user(platform_window* window, u32 id, protocol_move_type move, float d if (move == MOVE_UP) { float newy = p->playery - speed; + p->direction = DIRECTION_UP; if (is_in_bounds(p->playerx, newy)) { p->playery = newy; object o = check_if_player_collided_with_object(*p); @@ -91,6 +92,7 @@ void move_user(platform_window* window, u32 id, protocol_move_type move, float d if (move == MOVE_DOWN) { float newy = p->playery + speed; + p->direction = DIRECTION_DOWN; if (is_in_bounds(p->playerx, newy)) { p->playery = newy; object o = check_if_player_collided_with_object(*p); @@ -99,7 +101,8 @@ void move_user(platform_window* window, u32 id, protocol_move_type move, float d } if (move == MOVE_LEFT) { - float newx = p->playerx - speed; + float newx = p->playerx - speed; + p->direction = DIRECTION_LEFT; if (is_in_bounds(newx, p->playery)) { p->playerx = newx; object o = check_if_player_collided_with_object(*p); @@ -109,6 +112,7 @@ void move_user(platform_window* window, u32 id, protocol_move_type move, float d if (move == MOVE_RIGHT) { float newx = p->playerx + speed; + p->direction = DIRECTION_RIGHT; if (is_in_bounds(newx, p->playery)) { p->playerx = newx; object o = check_if_player_collided_with_object(*p); @@ -168,37 +172,33 @@ void take_player_input(platform_window* window) { if (keyboard_is_key_down(KEY_A)) { network_message message = create_protocol_user_moved(MOVE_LEFT, player_id); add_message_to_outgoing_queuex(message, *global_state.client); - p->direction = DIRECTION_LEFT; } if (keyboard_is_key_down(KEY_D)) { network_message message = create_protocol_user_moved(MOVE_RIGHT, player_id); add_message_to_outgoing_queuex(message, *global_state.client); - p->direction = DIRECTION_RIGHT; } if (keyboard_is_key_down(KEY_W)) { network_message message = create_protocol_user_moved(MOVE_UP, player_id); add_message_to_outgoing_queuex(message, *global_state.client); - p->direction = DIRECTION_UP; - if (keyboard_is_key_down(KEY_A)) { - p->direction = DIRECTION_TOPLEFT; - } - else if (keyboard_is_key_down(KEY_D)) { - p->direction = DIRECTION_TOPRIGHT; - } + // if (keyboard_is_key_down(KEY_A)) { + // p->direction = DIRECTION_TOPLEFT; + // } + // else if (keyboard_is_key_down(KEY_D)) { + // p->direction = DIRECTION_TOPRIGHT; + // } } if (keyboard_is_key_down(KEY_S)) { network_message message = create_protocol_user_moved(MOVE_DOWN, player_id); add_message_to_outgoing_queuex(message, *global_state.client); - p->direction = DIRECTION_DOWN; - if (keyboard_is_key_down(KEY_A)) { - p->direction = DIRECTION_BOTTOMLEFT; - } - else if (keyboard_is_key_down(KEY_D)) { - p->direction = DIRECTION_BOTTOMRIGHT; - } + // if (keyboard_is_key_down(KEY_A)) { + // p->direction = DIRECTION_BOTTOMLEFT; + // } + // else if (keyboard_is_key_down(KEY_D)) { + // p->direction = DIRECTION_BOTTOMRIGHT; + // } } @@ -248,21 +248,9 @@ void take_player_input(platform_window* window) { } -void update_players_server() { +void update_players_client() { for (int i = 0; i < MAX_PLAYERS; i++) { if (!players[i].active) continue; - players[i].sec_since_last_shot += SERVER_TICK_RATE; - players[i].sec_since_interact_state_change += SERVER_TICK_RATE; - - gun g = get_gun_by_type(players[i].guntype); - if (players[i].interact_state == INTERACT_RELOADING && players[i].sec_since_interact_state_change >= g.reload_time) { - int amount_to_reload = g.magazine_size; - if (amount_to_reload > players[i].total_ammo) amount_to_reload = players[i].total_ammo; - players[i].total_ammo -= amount_to_reload; - players[i].ammo_in_mag = amount_to_reload; - - players[i].interact_state = INTERACT_IDLE; - } if (players[i].direction == DIRECTION_DOWN) { players[i].sprite.frame_start = 374; @@ -295,6 +283,26 @@ void update_players_server() { } } +void update_players_server() { + for (int i = 0; i < MAX_PLAYERS; i++) { + if (!players[i].active) continue; + players[i].sec_since_last_shot += SERVER_TICK_RATE; + players[i].sec_since_interact_state_change += SERVER_TICK_RATE; + + gun g = get_gun_by_type(players[i].guntype); + if (players[i].interact_state == INTERACT_RELOADING && players[i].sec_since_interact_state_change >= g.reload_time) { + int amount_to_reload = g.magazine_size; + if (amount_to_reload > players[i].total_ammo) amount_to_reload = players[i].total_ammo; + players[i].total_ammo -= amount_to_reload; + players[i].ammo_in_mag = amount_to_reload; + + players[i].interact_state = INTERACT_IDLE; + } + } + + update_players_client(); +} + void draw_players(platform_window* window) { float size = get_player_size_in_tile(); for (int i = 0; i < MAX_PLAYERS; i++) { |
