summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/c_cpp_properties.json3
-rw-r--r--build/zombies.exebin1725226 -> 1732134 bytes
-rw-r--r--include/drops.h33
-rw-r--r--include/math_helper.h4
-rw-r--r--include/objects.h1
-rw-r--r--include/players.h5
-rw-r--r--include/protocol.h41
-rw-r--r--include/zombies.h2
-rw-r--r--main.c2
-rw-r--r--src/bullets.c7
-rw-r--r--src/drops.c80
-rw-r--r--src/game.c20
-rw-r--r--src/map.c2
-rw-r--r--src/math_helper.c3
-rw-r--r--src/objects.c15
-rw-r--r--src/overlay.c18
-rw-r--r--src/players.c40
-rw-r--r--src/protocol.c60
-rw-r--r--src/zombies.c13
19 files changed, 264 insertions, 85 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index 1fc7b4f..0b83e43 100644
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -4,7 +4,8 @@
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
- "C:\\mingw\\mingw64\\x86_64-w64-mingw32\\include"
+ "C:\\mingw\\mingw64\\x86_64-w64-mingw32\\include",
+ "C:\\Users\\aldri\\Desktop\\Vault\\Projects\\project-base\\src"
],
"defines": [
"_DEBUG",
diff --git a/build/zombies.exe b/build/zombies.exe
index 8a3112b..ed382ca 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/include/drops.h b/include/drops.h
new file mode 100644
index 0000000..e7ab661
--- /dev/null
+++ b/include/drops.h
@@ -0,0 +1,33 @@
+#ifndef INCLUDE_DROPS
+#define INCLUDE_DROPS
+
+#include <projectbase/project_base.h>
+
+#include "guns.h"
+
+typedef enum t_drop_type {
+ DROP_GUN,
+ DROP_AMMO,
+} drop_type;
+
+typedef struct t_drop {
+ bool active;
+ float time_active;
+ vec3f position;
+ vec3f size;
+ float start_h;
+ drop_type type;
+ union {
+ int ammo_count;
+ gun_type gun;
+ } data;
+} drop;
+
+#define MAX_DROPS 50
+drop drops[MAX_DROPS] = {0};
+
+void update_drops();
+void draw_drops(platform_window* window);
+void spawn_drop(vec3f pos);
+
+#endif \ No newline at end of file
diff --git a/include/math_helper.h b/include/math_helper.h
index b3a6cfe..ca27e14 100644
--- a/include/math_helper.h
+++ b/include/math_helper.h
@@ -8,6 +8,8 @@
#include "map.h"
#define MAP_RENDER_DEPTH renderer->set_render_depth(1);
+
+#define DROP_RENDER_DEPTH(_h) renderer->set_render_depth(4 + ceil(_h));
#define BULLET_RENDER_DEPTH(_h) renderer->set_render_depth(5 + ceil(_h));
#define OBJECT_RENDER_DEPTH(_h) renderer->set_render_depth(5 + ceil(_h));
#define OVERLAY_RENDER_DEPTH() renderer->set_render_depth(100);
@@ -17,6 +19,6 @@ int orientation(vec2f p, vec2f q, vec2f r);
bool lines_intersect(vec2f p1, vec2f q1, vec2f p2, vec2f q2);
vec2f get_intersection_point(vec2f A, vec2f B, vec2f C, vec2f D);
box get_render_box_of_square(platform_window* window, vec3f position, vec3f size);
-box get_box_of_square(platform_window* window, vec3f position, vec3f size);
+box get_box_of_square(vec3f position, vec3f size);
#endif \ No newline at end of file
diff --git a/include/objects.h b/include/objects.h
index b7c14b3..04f434b 100644
--- a/include/objects.h
+++ b/include/objects.h
@@ -34,5 +34,6 @@ object objects[150];
void create_objects();
void draw_objects_at_row(platform_window* window, int row);
box get_box_of_object(platform_window* window, object o);
+void render_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br, color c);
#endif \ No newline at end of file
diff --git a/include/players.h b/include/players.h
index e51e4e2..ab8da4c 100644
--- a/include/players.h
+++ b/include/players.h
@@ -20,8 +20,11 @@ typedef struct t_player {
float gun_height;
int total_ammo;
int ammo_in_mag;
+ float height;
gun_type guntype;
network_client client; // For the host: is_connected = false and socket = 0
+ int kills;
+ u64 ping;
} player;
#include "protocol.h"
@@ -35,7 +38,7 @@ player players[10] = {0};
int get_player_count();
player* get_player_by_id(u32 id);
-void draw_players_at_tile(platform_window* window, int x, int y);
+void draw_players(platform_window* window);
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);
diff --git a/include/protocol.h b/include/protocol.h
index 64822a2..aec65b4 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -3,7 +3,8 @@
#include <projectbase/project_base.h>
-typedef enum t_network_message_type {
+typedef enum t_network_message_type
+{
MESSAGE_GET_ID_UPSTREAM,
MESSAGE_GET_ID_DOWNSTREAM,
MESSAGE_USER_LIST,
@@ -14,48 +15,58 @@ typedef enum t_network_message_type {
MESSAGE_BULLET_LIST,
} network_message_type;
-typedef struct t_protocol_generic_client_message {
+typedef struct t_protocol_generic_client_message
+{
network_message_type type;
} protocol_generic_client_message;
-typedef struct t_protocol_generic_message {
+typedef struct t_protocol_generic_message
+{
network_client client;
protocol_generic_client_message *message;
+ u64 send_timestamp;
} protocol_generic_message;
-typedef struct t_protocol_get_id_upstream {
+typedef struct t_protocol_get_id_upstream
+{
network_message_type type;
} protocol_get_id_upstream;
-typedef struct t_protocol_get_id_downstream {
+typedef struct t_protocol_get_id_downstream
+{
network_message_type type;
u32 id;
} protocol_get_id_downstream;
-typedef struct t_protocol_user_list {
+typedef struct t_protocol_user_list
+{
network_message_type type;
player players[10];
} protocol_user_list;
-typedef struct t_protocol_zombie_list {
+typedef struct t_protocol_zombie_list
+{
network_message_type type;
zombie zombies[20];
} protocol_zombie_list;
-typedef enum t_protocol_move_type {
+typedef enum t_protocol_move_type
+{
MOVE_UP,
MOVE_DOWN,
MOVE_LEFT,
MOVE_RIGHT,
} protocol_move_type;
-typedef struct t_protocol_move {
+typedef struct t_protocol_move
+{
network_message_type type;
protocol_move_type move;
u32 id;
} protocol_move;
-typedef struct t_protocol_user_look {
+typedef struct t_protocol_user_look
+{
network_message_type type;
u32 id;
float gunx;
@@ -64,12 +75,14 @@ typedef struct t_protocol_user_look {
#include "bullets.h"
-typedef struct t_protocol_bullets_list {
+typedef struct t_protocol_bullets_list
+{
network_message_type type;
bullet bullets[500];
} protocol_bullets_list;
-typedef struct t_protocol_user_shoot {
+typedef struct t_protocol_user_shoot
+{
network_message_type type;
u32 id;
float dirx;
@@ -90,7 +103,7 @@ network_message create_protocol_bullets_list();
array messages_received_on_server;
array messages_received_on_client;
-void server_on_message_received(u8* buffer, u32 length, network_client client);
-void client_on_message_received(u8* buffer, u32 length);
+void server_on_message_received(u8 *buffer, u32 length, u64 timestamp, network_client client);
+void client_on_message_received(u8 *buffer, u32 length);
#endif \ No newline at end of file
diff --git a/include/zombies.h b/include/zombies.h
index f5df00e..df5e629 100644
--- a/include/zombies.h
+++ b/include/zombies.h
@@ -34,7 +34,7 @@ zombie zombies[20] = {0};
int max_zombies = 20;
void draw_spawners(platform_window* window);
-void draw_zombies_at_tile(platform_window* window, int x, int y);
+void draw_zombies(platform_window* window);
void spawn_zombie(int x, int y);
#endif \ No newline at end of file
diff --git a/main.c b/main.c
index dbc06cd..467dfe5 100644
--- a/main.c
+++ b/main.c
@@ -14,6 +14,7 @@
#include "include/guns.h"
#include "include/overlay.h"
#include "include/asset_defs.h"
+#include "include/drops.h"
#include "src/map.c"
#include "src/players.c"
@@ -29,6 +30,7 @@
#include "src/protocol.c"
#include "src/overlay.c"
#include "src/asset_defs.c"
+#include "src/drops.c"
#define CONFIG_DIRECTORY "zombieshooter"
diff --git a/src/bullets.c b/src/bullets.c
index 0feddef..472808b 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -79,7 +79,7 @@ bool check_if_bullet_collided_with_object(bullet* b, platform_window* window) {
object o = objects[i];
if (!o.active) continue;
if (b->position.z <= o.h + o.size.z && b->position.z >= o.h) {
- box obj_box = get_box_of_square(window, (vec3f){o.position.x, o.position.y, o.h}, o.size);
+ box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.h}, o.size);
vec2f intersect_point;
if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.bl_b, obj_box.br_b, &intersect_point)) {
result = true;
@@ -121,7 +121,7 @@ bool check_if_bullet_collided_with_zombie(bullet b, platform_window* window, boo
if (b.position.z <= o.position.z + o.size.z && b.position.z >= o.position.z) {
vec2f intersect_point;
- box obj_box = get_box_of_square(window, (vec3f){o.position.x, o.position.y, o.position.z}, o.size);
+ box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.position.z}, o.size);
bool this_zombie_collided = false;
if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.bl_b, obj_box.br_b, &intersect_point)) {
this_zombie_collided = true;
@@ -147,6 +147,7 @@ bool check_if_bullet_collided_with_zombie(bullet b, platform_window* window, boo
}
if (kill_if_collided && result) {
+ spawn_drop(zombies[index_of_closest_zombie].position);
zombies[index_of_closest_zombie].alive = false;
return result;
}
@@ -187,6 +188,7 @@ void draw_bullets(platform_window* window) {
bullet b = bullets[i];
if (!b.active) continue;
player *p = get_player_by_id(b.player_id);
+ if (!p) continue; // Bullet from inactive player?
bullets[i].position.x = p->gunx;
bullets[i].position.y = p->guny;
bullets[i].position.z = p->gun_height;
@@ -205,6 +207,7 @@ void draw_bullets(platform_window* window) {
if (check_if_bullet_collided_with_zombie(b, window, true)) {
bullets[i].active = false;
+ p->kills++;
}
bullets[i].alive_time += update_delta;
diff --git a/src/drops.c b/src/drops.c
new file mode 100644
index 0000000..f5f4fa0
--- /dev/null
+++ b/src/drops.c
@@ -0,0 +1,80 @@
+#include "../include/drops.h"
+#include "../include/objects.h"
+
+void handle_drop_pickup(player* p, drop* d) {
+ if (!d->active) return;
+
+ switch(d->type) {
+ case DROP_AMMO: p->total_ammo += d->data.ammo_count; break;
+
+ default: log_infox("Unhandled drop type: %d", d->type); break;
+ }
+ d->active = false;
+}
+
+void update_drops() {
+ #define MAX_HEIGHT_DIFF (0.3f)
+ #define FREQUENCY (0.15)
+
+ for (int i = 0; i < MAX_DROPS; i++) {
+ drop b = drops[i];
+ if (!b.active) continue;
+
+ drops[i].time_active += update_delta;
+ drops[i].position.z = MAX_HEIGHT_DIFF * sin (2 * M_PI * 0.5f * (drops[i].time_active) + 0) + b.start_h;
+
+ for (int x = 0; x < max_players; x++) {
+ player *p = &players[x];
+ if (!p->active) continue;
+
+ if (check_if_player_collided_with_box(*p, get_box_of_square(drops[i].position, drops[i].size))) {
+ handle_drop_pickup(p, &drops[i]);
+ }
+ }
+ }
+}
+
+void draw_drops(platform_window* window) {
+ for (int i = 0; i < MAX_DROPS; i++) {
+ drop b = drops[i];
+ if (!b.active) continue;
+
+ DROP_RENDER_DEPTH((int)(b.position.y));
+
+ b.position.z = b.start_h;
+ b.size.z = 0.0f;
+ b.position.y += 0.2f;
+ b.position.x -= 0.07f;
+ box shadow_box = get_render_box_of_square(window, b.position, b.size);
+ render_quad_with_outline(shadow_box.tl_b, shadow_box.tr_b, shadow_box.bl_b, shadow_box.br_b, rgba(0,0,0,120));
+ render_quad_with_outline(shadow_box.tl_u, shadow_box.tr_u, shadow_box.bl_u, shadow_box.br_u, rgba(0,0,0,120));
+ render_quad_with_outline(shadow_box.tl_u, shadow_box.tl_b, shadow_box.bl_u, shadow_box.bl_b, rgba(0,0,0,120));
+ render_quad_with_outline(shadow_box.bl_u, shadow_box.br_u, shadow_box.bl_b, shadow_box.br_b, rgba(0,0,0,120));
+
+ b = drops[i];
+ box full_box = get_render_box_of_square(window, b.position, b.size);
+ render_quad_with_outline(full_box.tl_b, full_box.tr_b, full_box.bl_b, full_box.br_b, rgb(218,112,214));
+ render_quad_with_outline(full_box.tl_u, full_box.tr_u, full_box.bl_u, full_box.br_u, rgb(218,112,214));
+ render_quad_with_outline(full_box.tl_u, full_box.tl_b, full_box.bl_u, full_box.bl_b, rgb(218,112,214));
+ render_quad_with_outline(full_box.bl_u, full_box.br_u, full_box.bl_b, full_box.br_b, rgb(218,112,214));
+ }
+}
+
+void spawn_drop(vec3f pos) {
+ for (int i = 0; i < MAX_DROPS; i++) {
+ drop b = drops[i];
+ if (b.active) continue;
+
+ drop new_drop;
+ new_drop.active = true;
+ new_drop.time_active = 0.0f;
+ new_drop.position = pos;
+ new_drop.size = (vec3f){0.3f, 0.3f, 0.4f};
+ new_drop.start_h = pos.z;
+ new_drop.type = DROP_AMMO;
+ new_drop.data.ammo_count = 10;
+
+ drops[i] = new_drop;
+ break;
+ }
+} \ No newline at end of file
diff --git a/src/game.c b/src/game.c
index aa5ae3a..2cb92e1 100644
--- a/src/game.c
+++ b/src/game.c
@@ -91,14 +91,30 @@ static void rotate_user(platform_window* window, protocol_user_look *message) {
p->guny = p->playery + message->guny;
}
+static void set_ping_for_player(protocol_generic_message* msg) {
+ u64 diff = platform_get_time(TIME_MS, TIME_PROCESS) - msg->send_timestamp;
+
+ for (int i = 0; i < max_players; i++) {
+ player p = players[i];
+ if (!p.client.is_connected) continue;
+ if (!p.active) continue;
+ if (p.client.ConnectSocket == msg->client.ConnectSocket) {
+ players[i].ping = diff;
+ return;
+ }
+ }
+}
+
float update_timer = 0.0f;
void update_server(platform_window* window) {
update_spawners();
+ update_drops();
update_players_server();
update_zombies_server(window);
for (int i = 0; i < messages_received_on_server.length; i++) {
protocol_generic_message* msg = *(protocol_generic_message**)array_at(&messages_received_on_server, i);
+ set_ping_for_player(msg);
switch (msg->message->type)
{
@@ -219,6 +235,10 @@ void update_game(platform_window* window) {
take_player_input(window);
draw_grid(window);
+ draw_drops(window);
+ draw_bullets(window);
+ draw_zombies(window);
+ draw_players(window);
draw_spawners(window);
draw_overlay(window);
diff --git a/src/map.c b/src/map.c
index 03aaf5f..e466f5f 100644
--- a/src/map.c
+++ b/src/map.c
@@ -233,8 +233,6 @@ void draw_grid(platform_window* window) {
draw_objects_at_row(window, y);
}
-
- draw_bullets(window);
}
inline map_info get_map_info(platform_window* window) {
diff --git a/src/math_helper.c b/src/math_helper.c
index 3bbfb29..69ad530 100644
--- a/src/math_helper.c
+++ b/src/math_helper.c
@@ -96,8 +96,7 @@ vec2f get_intersection_point(vec2f A, vec2f B, vec2f C, vec2f D) {
}
}
-box get_box_of_square(platform_window* window, vec3f position, vec3f size) {
- map_info info = get_map_info(window);
+box get_box_of_square(vec3f position, vec3f size) {
vec2f rendertl = (vec2f){position.x, position.y};
vec2f rendertr = (vec2f){position.x + size.x, position.y};
vec2f renderbr = (vec2f){position.x + size.x, position.y + size.y};
diff --git a/src/objects.c b/src/objects.c
index e4e01d9..c82f27f 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -4,13 +4,13 @@ box get_box_of_object(platform_window* window, object o) {
return get_render_box_of_square(window, (vec3f){o.position.x, o.position.y, o.h}, o.size);
}
-void render_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br) {
+void render_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br, color c) {
renderer->render_quad(
tl.x, tl.y,
bl.x, bl.y,
br.x, br.y,
tr.x, tr.y,
- rgb(200,200,0));
+ c);
renderer->render_line(tl.x, tl.y, tr.x, tr.y, 1, rgb(0,0,255)); // top
renderer->render_line(tl.x, tl.y, bl.x, bl.y, 1, rgb(0,0,255)); // left
@@ -32,18 +32,15 @@ void draw_objects_at_row(platform_window* window, int row) {
for (int i = MAP_SIZE_X-1; i >= 0; i--) {
object o = get_object_at_tile(i, row);
-
- draw_players_at_tile(window, i, row);
OBJECT_RENDER_DEPTH((int)o.position.y);
- draw_zombies_at_tile(window, i, row);
if (!o.active) continue;
box box = get_box_of_object(window, o);
- render_quad_with_outline(box.tl_b, box.tr_b, box.bl_b, box.br_b);
- render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u);
- render_quad_with_outline(box.tl_u, box.tl_b, box.bl_u, box.bl_b);
- render_quad_with_outline(box.bl_u, box.br_u, box.bl_b, box.br_b);
+ render_quad_with_outline(box.tl_b, box.tr_b, box.bl_b, box.br_b, rgb(200,200,0));
+ render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgb(200,200,0));
+ render_quad_with_outline(box.tl_u, box.tl_b, box.bl_u, box.bl_b, rgb(200,200,0));
+ render_quad_with_outline(box.bl_u, box.br_u, box.bl_b, box.br_b, rgb(200,200,0));
}
}
diff --git a/src/overlay.c b/src/overlay.c
index c79ef2e..de84aa7 100644
--- a/src/overlay.c
+++ b/src/overlay.c
@@ -26,10 +26,12 @@ static void draw_gun_info(platform_window* window) {
static void draw_leaderboard_entry(int x, int y, int w, int h, char* name, char* kills, char* deaths, char* ping) {
int width_for_name = w / 2;
int width_per_entry = (w-width_for_name)/3;
- renderer->render_text(fnt_20, x, y, name, rgb(0,0,0));
- renderer->render_text(fnt_20, x+width_for_name+width_per_entry*0, y, kills, rgb(0,0,0));
- renderer->render_text(fnt_20, x+width_for_name+width_per_entry*1, y, deaths, rgb(0,0,0));
- renderer->render_text(fnt_20, x+width_for_name+width_per_entry*2, y, ping, rgb(0,0,0));
+ int pad_y = (h-fnt_20->px_h)/2;
+ int pad_x = pad_y;
+ renderer->render_text(fnt_20, x+pad_x, y+pad_y, name, rgb(255,255,255));
+ renderer->render_text(fnt_20, x+pad_x+width_for_name+width_per_entry*0, y+pad_y, kills, rgb(255,255,255));
+ renderer->render_text(fnt_20, x+pad_x+width_for_name+width_per_entry*1, y+pad_y, deaths, rgb(255,255,255));
+ renderer->render_text(fnt_20, x+pad_x+width_for_name+width_per_entry*2, y+pad_y, ping, rgb(255,255,255));
}
static void draw_leaderboard(platform_window* window) {
@@ -40,21 +42,21 @@ static void draw_leaderboard(platform_window* window) {
if (actual_width > maximum_width) actual_width = maximum_width;
if (actual_width < minimum_width) actual_width = minimum_width;
- int height_per_row = 20;
+ int height_per_row = 24;
int height_total = height_per_row * (get_player_count() + 1);
int x = (int)_global_camera.x + (window->width - actual_width) / 2;
int y = (int)_global_camera.y + (window->height - height_total) / 4;
- renderer->render_rectangle(x, y, actual_width, height_total, rgba(255,255,255, 200));
+ renderer->render_rectangle(x, y, actual_width, height_total, rgba(0,0,0,120));
draw_leaderboard_entry(x, y, actual_width, height_per_row, "Player", "Kills", "Deaths", "Ping");
for (int i = 0; i < max_players; i++) {
if (!players[i].active) continue;
- char kills[30]; snprintf(kills, 30, "%d", 0);
+ char kills[30]; snprintf(kills, 30, "%d", players[i].kills);
char deaths[30]; snprintf(deaths, 30, "%d", 0);
- char ping[30]; snprintf(ping, 30, "%d", 0);
+ char ping[30]; snprintf(ping, 30, "%d", players[i].ping);
draw_leaderboard_entry(x, y + ((i+1)*height_per_row), actual_width, height_per_row, players[i].client.ip, kills, deaths, ping);
}
}
diff --git a/src/players.c b/src/players.c
index c4b7bb0..390a30f 100644
--- a/src/players.c
+++ b/src/players.c
@@ -38,6 +38,7 @@ void spawn_player(int id, network_client client) {
players[i].gun_height = 0.0f;
players[i].id = id;
players[i].guntype = GUN_MP5;
+ players[i].height = 0.0f;
players[i].client = client;
gun g = get_gun_by_type(players[i].guntype);
@@ -63,7 +64,7 @@ void move_user(platform_window* window, u32 id, protocol_move_type move) {
if (is_in_bounds(p->playerx, newy)) {
p->playery = newy;
object o = check_if_player_collided_with_object(window, *p);
- if (o.active) p->playery = o.position.y+o.size.y - get_player_size_in_tile() + pad_between_player_and_obj;
+ if (o.active) p->playery = o.position.y+o.size.y + pad_between_player_and_obj;
}
}
@@ -103,6 +104,17 @@ player* get_player_by_id(u32 id) {
return 0;
}
+bool check_if_player_collided_with_box(player p, box o) {
+ float player_size = get_player_size_in_tile();
+
+ box pbox = get_box_of_square((vec3f){p.playerx, p.playery, p.height}, (vec3f){player_size,player_size,0.8f});
+
+ // [x1, y1, x2, y2]
+ bool b1 = min(pbox.br_u.x, o.br_b.x) > max(pbox.tl_u.x, o.tl_u.x);
+ bool b2 = min(pbox.br_u.y, o.br_b.y) > max(pbox.tl_u.y, o.tl_u.y);
+ return b1 && b2;
+}
+
object check_if_player_collided_with_object(platform_window* window, player p) {
map_info info = get_map_info(window);
float player_size = get_player_size(window);
@@ -111,13 +123,7 @@ object check_if_player_collided_with_object(platform_window* window, player p) {
object o = objects[i];
if (!o.active) continue;
- box box = get_box_of_object(window, o);
- float x_to_check = p.playerx;
- float player_size_in_tile_px = player_size / (float)info.tile_width;
- float y_to_check = p.playery + player_size_in_tile_px;
-
- if (x_to_check+player_size_in_tile_px >= o.position.x && x_to_check <= o.position.x+o.size.x
- && y_to_check >= o.position.y && y_to_check <= o.position.y+o.size.y) {
+ if (check_if_player_collided_with_box(p, get_box_of_square((vec3f){o.position.x, o.position.y, o.h}, o.size))) {
return o;
}
}
@@ -205,20 +211,28 @@ void update_players_server() {
}
}
-void draw_players_at_tile(platform_window* window, int x, int y) {
+void draw_players(platform_window* window) {
+ float size = get_player_size_in_tile();
for (int i = 0; i < max_players; i++) {
if (!players[i].active) continue;
- if ((int)players[i].playerx != x || (int)(players[i].playery+get_player_size_in_tile()) != y) continue;
- OBJECT_RENDER_DEPTH((int)(players[i].playery+get_player_size_in_tile()));
+ OBJECT_RENDER_DEPTH((int)(players[i].playery));
+
+ float height = get_height_of_tile_under_coords(window, players[i].playerx, players[i].playery);
+ players[i].height = height;
+
+ box box = get_render_box_of_square(window, (vec3f){players[i].playerx, players[i].playery, height}, (vec3f){size,size,0.8f});
+ render_quad_with_outline(box.tl_b, box.tr_b, box.bl_b, box.br_b, rgb(200,150,120));
+ render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgb(200,150,120));
+ render_quad_with_outline(box.tl_u, box.tl_b, box.bl_u, box.bl_b, rgb(200,150,120));
+ render_quad_with_outline(box.bl_u, box.br_u, box.bl_b, box.br_b, rgb(200,150,120));
int size = get_tile_width(window) / 2;
map_info info = get_map_info(window);
- float height = get_height_of_tile_under_coords(window, players[i].playerx, players[i].playery);
+
float player_render_x = players[i].playerx*info.tile_width + (players[i].playery*info.px_incline);
float player_render_y = players[i].playery*info.tile_height - (height*info.px_raised_per_h);
- renderer->render_rectangle(player_render_x, player_render_y, size, size, rgb(200,150,120));
players[i].gun_height = height+0.5;
float gun_render_x = players[i].gunx*info.tile_width + (players[i].guny*info.px_incline);
diff --git a/src/protocol.c b/src/protocol.c
index dc4783b..eb0d200 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -1,51 +1,57 @@
#include "../include/protocol.h"
#include "../include/players.h"
-network_message create_protocol_get_id_up() {
- protocol_get_id_upstream* buf = (protocol_get_id_upstream*)network_buffer;
+network_message create_protocol_get_id_up()
+{
+ protocol_get_id_upstream *buf = (protocol_get_id_upstream *)network_buffer;
buf->type = MESSAGE_GET_ID_UPSTREAM;
return network_create_message(network_buffer, sizeof(protocol_get_id_upstream), MAX_NETWORK_BUFFER_SIZE);
}
-network_message create_protocol_get_id_down(u32 id) {
- protocol_get_id_downstream* buf = (protocol_get_id_downstream*)network_buffer;
+network_message create_protocol_get_id_down(u32 id)
+{
+ protocol_get_id_downstream *buf = (protocol_get_id_downstream *)network_buffer;
buf->type = MESSAGE_GET_ID_DOWNSTREAM;
buf->id = id;
return network_create_message(network_buffer, sizeof(protocol_get_id_downstream), MAX_NETWORK_BUFFER_SIZE);
}
-network_message create_protocol_user_list() {
- protocol_user_list* buf = (protocol_user_list*)network_buffer;
+network_message create_protocol_user_list()
+{
+ protocol_user_list *buf = (protocol_user_list *)network_buffer;
buf->type = MESSAGE_USER_LIST;
memcpy(buf->players, players, sizeof(players));
return network_create_message(network_buffer, sizeof(protocol_user_list), MAX_NETWORK_BUFFER_SIZE);
}
-network_message create_protocol_zombie_list() {
- protocol_zombie_list* buf = (protocol_zombie_list*)network_buffer;
+network_message create_protocol_zombie_list()
+{
+ protocol_zombie_list *buf = (protocol_zombie_list *)network_buffer;
buf->type = MESSAGE_ZOMBIE_LIST;
memcpy(buf->zombies, zombies, sizeof(zombies));
return network_create_message(network_buffer, sizeof(protocol_zombie_list), MAX_NETWORK_BUFFER_SIZE);
}
-network_message create_protocol_bullets_list() {
- protocol_bullets_list* buf = (protocol_bullets_list*)network_buffer;
+network_message create_protocol_bullets_list()
+{
+ protocol_bullets_list *buf = (protocol_bullets_list *)network_buffer;
buf->type = MESSAGE_BULLET_LIST;
memcpy(buf->bullets, bullets, sizeof(bullets));
return network_create_message(network_buffer, sizeof(protocol_bullets_list), MAX_NETWORK_BUFFER_SIZE);
}
-
-network_message create_protocol_user_moved(protocol_move_type move, u32 id) {
- protocol_move* buf = (protocol_move*)network_buffer;
+network_message create_protocol_user_moved(protocol_move_type move, u32 id)
+{
+ protocol_move *buf = (protocol_move *)network_buffer;
buf->type = MESSAGE_USER_MOVED;
buf->move = move;
buf->id = id;
return network_create_message(network_buffer, sizeof(protocol_move), MAX_NETWORK_BUFFER_SIZE);
}
-network_message create_protocol_user_shoot(u32 id, float dirx, float diry) {
- protocol_user_shoot* buf = (protocol_user_shoot*)network_buffer;
+network_message create_protocol_user_shoot(u32 id, float dirx, float diry)
+{
+ protocol_user_shoot *buf = (protocol_user_shoot *)network_buffer;
buf->type = MESSAGE_USER_SHOOT;
buf->id = id;
buf->dirx = dirx;
@@ -53,8 +59,9 @@ network_message create_protocol_user_shoot(u32 id, float dirx, float diry) {
return network_create_message(network_buffer, sizeof(protocol_user_shoot), MAX_NETWORK_BUFFER_SIZE);
}
-network_message create_protocol_user_look(u32 id, float gunx, float guny) {
- protocol_user_look* buf = (protocol_user_look*)network_buffer;
+network_message create_protocol_user_look(u32 id, float gunx, float guny)
+{
+ protocol_user_look *buf = (protocol_user_look *)network_buffer;
buf->type = MESSAGE_USER_LOOK;
buf->id = id;
buf->gunx = gunx;
@@ -62,16 +69,19 @@ network_message create_protocol_user_look(u32 id, float gunx, float guny) {
return network_create_message(network_buffer, sizeof(protocol_user_look), MAX_NETWORK_BUFFER_SIZE);
}
-void server_on_message_received(u8* buffer, u32 length, network_client client) {
- protocol_generic_message* allocated_buf = mem_alloc(sizeof(protocol_generic_message));
+void server_on_message_received(u8 *buffer, u32 length, u64 timestamp, network_client client)
+{
+ protocol_generic_message *allocated_buf = mem_alloc(sizeof(protocol_generic_message));
allocated_buf->client = client;
allocated_buf->message = mem_alloc(length);
- memcpy(allocated_buf->message, buffer + 4, length-4);
- array_push(&messages_received_on_server, (u8*)&allocated_buf);
+ allocated_buf->send_timestamp = timestamp;
+ memcpy(allocated_buf->message, buffer, length);
+ array_push(&messages_received_on_server, (u8 *)&allocated_buf);
}
-void client_on_message_received(u8* buffer, u32 length) {
- u8* allocated_buf = mem_alloc(length);
- memcpy(allocated_buf, buffer+4, length-4);
- array_push(&messages_received_on_client, (u8*)&allocated_buf);
+void client_on_message_received(u8 *buffer, u32 length)
+{
+ u8 *allocated_buf = mem_alloc(length);
+ memcpy(allocated_buf, buffer, length);
+ array_push(&messages_received_on_client, (u8 *)&allocated_buf);
}
diff --git a/src/zombies.c b/src/zombies.c
index a924443..043bce1 100644
--- a/src/zombies.c
+++ b/src/zombies.c
@@ -205,20 +205,21 @@ void update_zombies_server(platform_window* window) {
}
}
-void draw_zombies_at_tile(platform_window* window, int x, int y) {
+void draw_zombies(platform_window* window) {
map_info info = get_map_info(window);
for (int i = 0; i < max_zombies; i++) {
zombie o = zombies[i];
if (!o.alive) continue;
- if ((int)o.position.x != x || (int)ceil(o.position.y) != y) continue;
+ //if ((int)o.position.x != x || (int)ceil(o.position.y) != y) continue;
+ OBJECT_RENDER_DEPTH((int)o.position.y);
box box = get_render_box_of_square(window, (vec3f){o.position.x, o.position.y, o.position.z}, o.size);
- render_quad_with_outline(box.tl_b, box.tr_b, box.bl_b, box.br_b);
- render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u);
- render_quad_with_outline(box.tl_u, box.tl_b, box.bl_u, box.bl_b);
- render_quad_with_outline(box.bl_u, box.br_u, box.bl_b, box.br_b);
+ render_quad_with_outline(box.tl_b, box.tr_b, box.bl_b, box.br_b, rgb(200,200,0));
+ render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgb(200,200,0));
+ render_quad_with_outline(box.tl_u, box.tl_b, box.bl_u, box.bl_b, rgb(200,200,0));
+ render_quad_with_outline(box.bl_u, box.br_u, box.bl_b, box.br_b, rgb(200,200,0));
if (global_state.server) draw_path_of_zombie(window, o);
}