summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asset_defs.c6
-rw-r--r--src/bullets.c17
-rw-r--r--src/game.c19
-rw-r--r--src/map.c2
-rw-r--r--src/objects.c5
-rw-r--r--src/overlay.c27
-rw-r--r--src/players.c12
7 files changed, 74 insertions, 14 deletions
diff --git a/src/asset_defs.c b/src/asset_defs.c
new file mode 100644
index 0000000..d7fc6a5
--- /dev/null
+++ b/src/asset_defs.c
@@ -0,0 +1,6 @@
+#include "../include/asset_defs.h"
+
+void load_assets() {
+ fnt_24 = assets_load_font(mono_ttf, mono_ttf+mono_ttf_len, 24);
+ fnt_20 = assets_load_font(mono_ttf, mono_ttf+mono_ttf_len, 20);
+} \ No newline at end of file
diff --git a/src/bullets.c b/src/bullets.c
index 0357025..0feddef 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -13,7 +13,17 @@ void shoot(platform_window* window, u32 id, float dirx, float diry) {
}
p->sec_since_last_shot = 0.0f;
- for (int i = 0; i < g.bullets_per_shot; i++)
+ int bullets_to_shoot = g.bullets_per_shot;
+ if (bullets_to_shoot > p->ammo_in_mag) bullets_to_shoot = p->ammo_in_mag;
+ p->ammo_in_mag -= bullets_to_shoot;
+ if (p->ammo_in_mag == 0) {
+ int amount_to_reload = g.magazine_size;
+ if (amount_to_reload > p->total_ammo) amount_to_reload = p->total_ammo;
+ p->total_ammo -= amount_to_reload;
+ p->ammo_in_mag = amount_to_reload;
+ }
+
+ for (int i = 0; i < bullets_to_shoot; i++)
{
map_info info = get_map_info(window);
float bullet_range = 100.0f;
@@ -180,8 +190,6 @@ void draw_bullets(platform_window* window) {
bullets[i].position.x = p->gunx;
bullets[i].position.y = p->guny;
bullets[i].position.z = p->gun_height;
-
- printf("%d\n", i);
if (check_if_bullet_collided_with_ground(&b, window)) {
bullets[i].endy = b.endy;
@@ -202,7 +210,8 @@ void draw_bullets(platform_window* window) {
bullets[i].alive_time += update_delta;
bullets[i].active = false;
- BULLET_RENDER_DEPTH(b.position.z);
+ if ((int)bullets[i].position.y < (int)bullets[i].endy) { BULLET_RENDER_DEPTH((int)bullets[i].position.y); }
+ else { BULLET_RENDER_DEPTH((int)bullets[i].endy); }
float bullet_render_x = b.position.x*info.tile_width + (b.position.y*info.px_incline);
float bullet_render_y = b.position.y*info.tile_height - (b.position.z*info.px_raised_per_h);
diff --git a/src/game.c b/src/game.c
index bb3b987..1bc9f0d 100644
--- a/src/game.c
+++ b/src/game.c
@@ -46,6 +46,7 @@ void init_game() {
global_state.state = IDLE;
global_state.network_state = DISCONNECTED;
+ load_assets();
load_map();
}
@@ -103,7 +104,6 @@ void update_server(platform_window* window) {
case MESSAGE_USER_SHOOT: {
protocol_user_shoot* shoot_msg = (protocol_user_shoot*)msg->message;
shoot(window, shoot_msg->id, shoot_msg->dirx, shoot_msg->diry);
- printf("Player %d shot\n", shoot_msg->id);
} break;
default:
@@ -148,7 +148,15 @@ void update_client(platform_window* window) {
player copy;
if (p) copy = *p;
memcpy(players, msg_players->players, sizeof(players));
- if (p) *p = copy;
+
+ // These properties are simulated locally so dont overwrite.
+ if (p) {
+ p->playerx = copy.playerx;
+ p->playery = copy.playery;
+ p->gunx = copy.gunx;
+ p->guny = copy.guny;
+ p->gun_height = copy.gun_height;
+ }
} break;
case MESSAGE_ZOMBIE_LIST: {
@@ -158,6 +166,7 @@ void update_client(platform_window* window) {
} break;
case MESSAGE_BULLET_LIST: {
+ if (global_state.server) break; // bullets are simulated on server so dont overwrite data.
protocol_bullets_list* msg_bullets = (protocol_bullets_list*)msg;
memcpy(bullets, msg_bullets->bullets, sizeof(bullets));
} break;
@@ -173,10 +182,10 @@ void update_client(platform_window* window) {
}
void update_game(platform_window* window) {
+ update_client(window);
if (global_state.server) {
update_server(window);
}
- update_client(window);
if (global_state.network_state == CONNECTED) {
if (!global_state.server) {
@@ -186,5 +195,9 @@ void update_game(platform_window* window) {
draw_grid(window);
draw_spawners(window);
+ draw_overlay(window);
+
+ _global_camera.x = (int)_next_camera_pos.x;
+ _global_camera.y = (int)_next_camera_pos.y;
}
} \ No newline at end of file
diff --git a/src/map.c b/src/map.c
index e466f5f..03aaf5f 100644
--- a/src/map.c
+++ b/src/map.c
@@ -233,6 +233,8 @@ 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/objects.c b/src/objects.c
index ae65af2..e4e01d9 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -33,13 +33,10 @@ 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);
- OBJECT_RENDER_DEPTH(o.h);
draw_players_at_tile(window, i, row);
+ OBJECT_RENDER_DEPTH((int)o.position.y);
draw_zombies_at_tile(window, i, row);
-
- draw_bullets(window);
- OBJECT_RENDER_DEPTH(o.h);
if (!o.active) continue;
box box = get_box_of_object(window, o);
diff --git a/src/overlay.c b/src/overlay.c
new file mode 100644
index 0000000..5a81726
--- /dev/null
+++ b/src/overlay.c
@@ -0,0 +1,27 @@
+#include "../include/overlay.h"
+#include "../include/guns.h"
+
+#define EDGE_PADDING 10
+
+static void draw_gun_info(platform_window* window) {
+ player *p = get_player_by_id(my_id);
+ if (!p) return;
+
+ gun g = get_gun_by_type(p->guntype);
+
+
+ int y = window->height - fnt_24->px_h - EDGE_PADDING;
+ int x = EDGE_PADDING;
+
+ renderer->render_text(fnt_24, (int)_global_camera.x + x, (int)_global_camera.y + y, g.name, rgb(255,255,255));
+ y -= fnt_24->px_h;
+
+ char ammo_txt[50];
+ sprintf(ammo_txt, "%d / %d", p->ammo_in_mag, p->total_ammo);
+ renderer->render_text(fnt_20, (int)_global_camera.x + x, (int)_global_camera.y + y, ammo_txt, rgb(255,255,255));
+}
+
+void draw_overlay(platform_window* window) {
+ OVERLAY_RENDER_DEPTH();
+ draw_gun_info(window);
+} \ No newline at end of file
diff --git a/src/players.c b/src/players.c
index 877e2b6..1b86944 100644
--- a/src/players.c
+++ b/src/players.c
@@ -28,7 +28,11 @@ void spawn_player(int id) {
players[i].guny = 0.0f;
players[i].gun_height = 0.0f;
players[i].id = id;
- players[i].guntype = GUN_NOVA;
+ players[i].guntype = GUN_MP5;
+
+ gun g = get_gun_by_type(players[i].guntype);
+ players[i].total_ammo = g.max_ammunition;
+ players[i].ammo_in_mag = g.magazine_size;
return;
}
}
@@ -196,6 +200,8 @@ void draw_players_at_tile(platform_window* window, int x, int y) {
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()));
+
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);
@@ -211,8 +217,8 @@ void draw_players_at_tile(platform_window* window, int x, int y) {
renderer->render_rectangle(gun_render_x, gun_render_y, size/4, size/4, rgb(20,255,20));
if (players[i].id == my_id) {
- _global_camera.x = -(window->width / 2) + player_render_x;
- _global_camera.y = -(window->height / 2) + player_render_y;
+ _next_camera_pos.x = -(window->width / 2) + player_render_x;
+ _next_camera_pos.y = -(window->height / 2) + player_render_y;
}
}
}