summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-11-02 18:24:46 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2023-11-02 18:24:46 +0100
commit11fc04b238ff9d42b17e6befa6ab4a673606fc1a (patch)
treecf4f48820fe3c55ed98c39038352924fab682ca8 /src
parent0648e9ec83977fe5151896097afd1dbae3f4143b (diff)
throwables on server side
Diffstat (limited to 'src')
-rw-r--r--src/game.c11
-rw-r--r--src/players.c8
-rw-r--r--src/protocol.c19
-rw-r--r--src/throwables.c2
4 files changed, 33 insertions, 7 deletions
diff --git a/src/game.c b/src/game.c
index 1999815..df65282 100644
--- a/src/game.c
+++ b/src/game.c
@@ -174,6 +174,11 @@ void update_server(platform_window* window) {
} break;
+ case MESSAGE_USER_THROW: {
+ protocol_user_throw* throw_msg = (protocol_user_throw*)msg->message;
+ throw_throwable(throw_msg->id, throw_msg->throwable, throw_msg->dirx, throw_msg->diry);
+ } break;
+
case MESSAGE_USER_MOVED: {
protocol_move* move_msg = (protocol_move*)msg->message;
move_user(window, move_msg->id, move_msg->move, move_msg->delta);
@@ -225,6 +230,7 @@ void update_server(platform_window* window) {
broadcast_to_clients(create_protocol_zombie_list());
broadcast_to_clients(create_protocol_bullets_list());
broadcast_to_clients(create_protocol_drop_list());
+ broadcast_to_clients(create_protocol_throwables_list());
// play sounds locally and send them to clients.
play_sounds_in_queue();
@@ -286,6 +292,11 @@ void update_client(platform_window* window) {
memcpy(zombies, msg_zombies->zombies, sizeof(zombies));
} break;
+ case MESSAGE_THROWABLES_LIST: {
+ protocol_throwables_list* msg_throwables = (protocol_throwables_list*)msg;
+ memcpy(throwables, msg_throwables->throwables, sizeof(throwables));
+ } break;
+
case MESSAGE_BULLET_LIST: {
protocol_bullets_list* msg_bullets = (protocol_bullets_list*)msg;
load_bullets_into_existing_list(msg_bullets);
diff --git a/src/players.c b/src/players.c
index d88ac97..bd80d5b 100644
--- a/src/players.c
+++ b/src/players.c
@@ -240,12 +240,8 @@ void take_player_input(platform_window* window) {
dirx /= length;
diry /= length;
- throw_throwable(window, player_id, THROWABLE_GRENADE, dirx, diry);
- //network_message message = create_protocol_user_shoot(player_id, dirx, diry);
- //add_message_to_outgoing_queuex(message, *global_state.client);
- }
-
-
+ add_message_to_outgoing_queuex(create_protocol_user_throw(player_id, dirx, diry, THROWABLE_GRENADE), *global_state.client);
+ }
}
void update_players_client() {
diff --git a/src/protocol.c b/src/protocol.c
index 307aac3..a33f421 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -35,6 +35,14 @@ network_message create_protocol_user_list()
return network_create_message((u8*)buf, sizeof(protocol_user_list), MAX_NETWORK_BUFFER_SIZE);
}
+network_message create_protocol_throwables_list()
+{
+ protocol_throwables_list *buf = alloc_network_message(protocol_throwables_list);
+ buf->type = MESSAGE_THROWABLES_LIST;
+ memcpy(buf->throwables, throwables, sizeof(throwables));
+ return network_create_message((u8*)buf, sizeof(protocol_throwables_list), MAX_NETWORK_BUFFER_SIZE);
+}
+
network_message create_protocol_zombie_list()
{
protocol_zombie_list *buf = alloc_network_message(protocol_zombie_list);
@@ -70,6 +78,17 @@ network_message create_protocol_user_moved(protocol_move_type move, u32 id)
return network_create_message((u8*)buf, sizeof(protocol_move), MAX_NETWORK_BUFFER_SIZE);
}
+network_message create_protocol_user_throw(u32 id, float dirx, float diry, throwable_type type)
+{
+ protocol_user_throw *buf = alloc_network_message(protocol_user_throw);
+ buf->type = MESSAGE_USER_THROW;
+ buf->id = id;
+ buf->dirx = dirx;
+ buf->diry = diry;
+ buf->throwable = type;
+ return network_create_message((u8*)buf, sizeof(protocol_user_throw), MAX_NETWORK_BUFFER_SIZE);
+}
+
network_message create_protocol_user_shoot(u32 id, float dirx, float diry)
{
protocol_user_shoot *buf = alloc_network_message(protocol_user_shoot);
diff --git a/src/throwables.c b/src/throwables.c
index f874bab..1492287 100644
--- a/src/throwables.c
+++ b/src/throwables.c
@@ -1,7 +1,7 @@
#include "../include/throwables.h"
#include "../include/audio.h"
-void throw_throwable(platform_window* window, u32 id, throwable_type type, float dirx, float diry) {
+void throw_throwable(u32 id, throwable_type type, float dirx, float diry) {
for (int i = 0; i < max_throwables; i++) {
if (throwables[i].active) continue;