summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2022-12-14 00:04:20 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2022-12-14 00:04:20 +0100
commit99f328fa19bb9cb266d9525629813cc0268a889e (patch)
tree514d5eb5fe51afc5f19bb3acf240a425239eba2a /include
parentf8ccfba637267bae8064daa320cfb00b8ffe3e66 (diff)
bullets network transfer
Diffstat (limited to 'include')
-rw-r--r--include/bullets.h3
-rw-r--r--include/guns.h29
-rw-r--r--include/players.h3
-rw-r--r--include/protocol.h18
4 files changed, 52 insertions, 1 deletions
diff --git a/include/bullets.h b/include/bullets.h
index ed64333..a42e6a4 100644
--- a/include/bullets.h
+++ b/include/bullets.h
@@ -6,6 +6,7 @@
#include "players.h"
#include "objects.h"
#include "map.h"
+#include "guns.h"
typedef struct t_bullet {
int player_id;
@@ -19,7 +20,7 @@ typedef struct t_bullet {
bullet bullets[500] = {0};
int max_bullets = 500;
-void shoot(platform_window* window, player p);
+void shoot(platform_window* window, u32 id, float dirx, float diry);
void draw_bullets(platform_window* window);
#endif \ No newline at end of file
diff --git a/include/guns.h b/include/guns.h
new file mode 100644
index 0000000..62d43df
--- /dev/null
+++ b/include/guns.h
@@ -0,0 +1,29 @@
+#ifndef INCLUDE_GUNS
+#define INCLUDE_GUNS
+
+typedef enum t_gun_type {
+ GUN_DESERTEAGLE,
+ GUN_MP5,
+ GUN_NOVA,
+
+ GUN_ALL,
+} gun_type;
+
+typedef struct t_gun {
+ gun_type type;
+ int magazine_size;
+ int max_ammunition;
+ float bullet_spread;
+ int bullets_per_shot;
+ float shots_per_second;
+} gun;
+
+gun guns[GUN_ALL] = {
+ {GUN_DESERTEAGLE, 8, 64, 0.0f, 1, 4.0f},
+ {GUN_MP5, 30, 120, 0.1f, 1, 10.0f},
+ {GUN_NOVA, 12, 80, 0.2f, 3, 1.2f},
+};
+
+gun get_gun_by_type(gun_type type);
+
+#endif \ No newline at end of file
diff --git a/include/players.h b/include/players.h
index 6d401c4..4e148c9 100644
--- a/include/players.h
+++ b/include/players.h
@@ -7,6 +7,7 @@
#include "objects.h"
#include "zombies.h"
#include "math_helper.h"
+#include "guns.h"
typedef struct t_player {
int id;
@@ -17,6 +18,7 @@ typedef struct t_player {
float gunx;
float guny;
float gun_height;
+ gun_type guntype;
} player;
#include "protocol.h"
@@ -32,5 +34,6 @@ void draw_bullets(platform_window* window);
object check_if_player_collided_with_object(platform_window* window, player p);
float get_player_size(platform_window* window);
void move_user(platform_window* window, u32 id, protocol_move_type move);
+void update_players_server();
#endif \ No newline at end of file
diff --git a/include/protocol.h b/include/protocol.h
index 989c4d5..64822a2 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -10,6 +10,8 @@ typedef enum t_network_message_type {
MESSAGE_USER_MOVED,
MESSAGE_USER_LOOK,
MESSAGE_ZOMBIE_LIST,
+ MESSAGE_USER_SHOOT,
+ MESSAGE_BULLET_LIST,
} network_message_type;
typedef struct t_protocol_generic_client_message {
@@ -60,6 +62,20 @@ typedef struct t_protocol_user_look {
float guny;
} protocol_user_look;
+#include "bullets.h"
+
+typedef struct t_protocol_bullets_list {
+ network_message_type type;
+ bullet bullets[500];
+} protocol_bullets_list;
+
+typedef struct t_protocol_user_shoot {
+ network_message_type type;
+ u32 id;
+ float dirx;
+ float diry;
+} protocol_user_shoot;
+
#define MAX_NETWORK_BUFFER_SIZE 50000
u8 network_buffer[50000];
network_message create_protocol_get_id_up();
@@ -67,7 +83,9 @@ network_message create_protocol_get_id_down(u32 id);
network_message create_protocol_user_list();
network_message create_protocol_user_moved(protocol_move_type move, u32 id);
network_message create_protocol_user_look(u32 id, float gunx, float guny);
+network_message create_protocol_user_shoot(u32 id, float dirx, float diry);
network_message create_protocol_zombie_list();
+network_message create_protocol_bullets_list();
array messages_received_on_server;
array messages_received_on_client;