summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asset_defs.c4
-rw-r--r--src/game.c6
-rw-r--r--src/map.c67
-rw-r--r--src/players.c28
-rw-r--r--src/protocol.c9
-rw-r--r--src/zombies.c2
6 files changed, 76 insertions, 40 deletions
diff --git a/src/asset_defs.c b/src/asset_defs.c
index a136e5f..2753ae6 100644
--- a/src/asset_defs.c
+++ b/src/asset_defs.c
@@ -1,8 +1,8 @@
#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);
+ fnt_24 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 24);
+ fnt_20 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 20);
img_icon_bullets = assets_load_image_from_file("data/imgs/bullets.png");
img_icon_nova = assets_load_image_from_file("data/imgs/nova.png");
diff --git a/src/game.c b/src/game.c
index d184ae5..268513d 100644
--- a/src/game.c
+++ b/src/game.c
@@ -64,7 +64,7 @@ void load_map() {
thread_detach(&send_thread);
}
- load_map_from_data();
+ load_map_from_file();
create_objects();
pathfinding_init();
@@ -322,6 +322,10 @@ void update_game(platform_window* window) {
draw_players(window);
draw_spawners(window);
draw_overlay(window);
+
+#ifdef MODE_DEBUG
+ draw_debug(window);
+#endif
_global_camera.x = (int)_next_camera_pos.x;
_global_camera.y = (int)_next_camera_pos.y;
diff --git a/src/map.c b/src/map.c
index 2b22888..29f9d55 100644
--- a/src/map.c
+++ b/src/map.c
@@ -3,19 +3,19 @@
static int get_height_of_tile_tl(int current_height, int x, int y) {
int highest_point = current_height;
if (y > 0) {
- int tile_above = map[y-1][x];
+ int tile_above = map_to_load.heightmap[y-1][x];
if (tile_above > highest_point) {
highest_point = tile_above;
}
}
if (y > 0 && x > 0) {
- int tile_above = map[y-1][x-1];
+ int tile_above = map_to_load.heightmap[y-1][x-1];
if (tile_above > highest_point) {
highest_point = tile_above;
}
}
if (x > 0) {
- int tile_above = map[y][x-1];
+ int tile_above = map_to_load.heightmap[y][x-1];
if (tile_above > highest_point) {
highest_point = tile_above;
}
@@ -27,19 +27,19 @@ static int get_height_of_tile_tl(int current_height, int x, int y) {
static int get_height_of_tile_br(int current_height, int x, int y) {
int highest_point = current_height;
if (x < MAP_SIZE_X-1) {
- int tile_right = map[y][x+1];
+ int tile_right = map_to_load.heightmap[y][x+1];
if (tile_right > highest_point) {
highest_point = tile_right;
}
}
if (y < MAP_SIZE_Y-1 && x < MAP_SIZE_X-1) {
- int tile_bottom_right = map[y+1][x+1];
+ int tile_bottom_right = map_to_load.heightmap[y+1][x+1];
if (tile_bottom_right > highest_point) {
highest_point = tile_bottom_right;
}
}
if (y < MAP_SIZE_Y-1) {
- int tile_bottom = map[y+1][x];
+ int tile_bottom = map_to_load.heightmap[y+1][x];
if (tile_bottom > highest_point) {
highest_point = tile_bottom;
}
@@ -50,19 +50,19 @@ static int get_height_of_tile_br(int current_height, int x, int y) {
static int get_height_of_tile_bl(int current_height, int x, int y) {
int highest_point = current_height;
if (y > 0 && x > 0) {
- int tile_left = map[y][x-1];
+ int tile_left = map_to_load.heightmap[y][x-1];
if (tile_left > highest_point) {
highest_point = tile_left;
}
}
if (y < MAP_SIZE_Y-1 && x > 0) {
- int tile_bottom_left = map[y+1][x-1];
+ int tile_bottom_left = map_to_load.heightmap[y+1][x-1];
if (tile_bottom_left > highest_point) {
highest_point = tile_bottom_left;
}
}
if (y < MAP_SIZE_Y-1) {
- int tile_bottom = map[y+1][x];
+ int tile_bottom = map_to_load.heightmap[y+1][x];
if (tile_bottom > highest_point) {
highest_point = tile_bottom;
}
@@ -73,19 +73,19 @@ static int get_height_of_tile_bl(int current_height, int x, int y) {
static int get_height_of_tile_tr(int current_height, int x, int y) {
int highest_point = current_height;
if (y > 0) {
- int tile_above = map[y-1][x];
+ int tile_above = map_to_load.heightmap[y-1][x];
if (tile_above > highest_point) {
highest_point = tile_above;
}
}
if (y > 0 && x < MAP_SIZE_X-1) {
- int tile_above_right = map[y-1][x+1];
+ int tile_above_right = map_to_load.heightmap[y-1][x+1];
if (tile_above_right > highest_point) {
highest_point = tile_above_right;
}
}
if (x < MAP_SIZE_X-1) {
- int tile_right = map[y][x+1];
+ int tile_right = map_to_load.heightmap[y][x+1];
if (tile_right > highest_point) {
highest_point = tile_right;
}
@@ -93,17 +93,7 @@ static int get_height_of_tile_tr(int current_height, int x, int y) {
return highest_point;
}
-// load hardcoded map.
-void load_map_from_data() {
-
- // load map from file..
- file_content content = platform_read_file_content("data/maps/map1.dat", "rb");
- memcpy(&map_to_load, content.content, content.content_length);
-
- //map_to_load.width = MAP_SIZE_X;
- //map_to_load.height = MAP_SIZE_Y;
- //memcpy(map_to_load.heightmap, map, sizeof(map));
-
+void export_map_from_map_data() {
for (int y = 0; y < MAP_SIZE_Y; y++) {
for (int x = MAP_SIZE_X-1; x >= 0; x--) {
int h = map_to_load.heightmap[y][x];
@@ -111,13 +101,30 @@ void load_map_from_data() {
int highest_point_topright = get_height_of_tile_tr(h, x, y);
int highest_point_bottomright = get_height_of_tile_br(h, x, y);
int highest_point_bottomleft = get_height_of_tile_bl(h, x, y);
- map_loaded[y][x] = (tile){h, highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright};
+ loaded_map.heightmap[y][x] = (tile){h, highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright};
}
}
}
+
+void load_map_from_file() {
+
+ // load map from file..
+ file_content content = platform_read_file_content("data/maps/map1.dat", "rb");
+ memcpy(&map_to_load, content.content, content.content_length);
+
+ //map_to_load.width = MAP_SIZE_X;
+ //map_to_load.height = MAP_SIZE_Y;
+ //memcpy(map_to_load.heightmap, map, sizeof(map));
+
+ loaded_map.width = map_to_load.width;
+ loaded_map.height = map_to_load.height;
+
+ export_map_from_map_data();
+}
+
tile get_tile_under_coords(float x, float y) {
- return map_loaded[(int)(y)][(int)(x)];
+ return loaded_map.heightmap[(int)(y)][(int)(x)];
}
float get_height_of_tile_under_coords(float tocheckx, float tochecky) {
@@ -178,7 +185,7 @@ void draw_grid(platform_window* window) {
for (int y = 0; y < MAP_SIZE_Y; y++) {
MAP_RENDER_DEPTH;
for (int x = MAP_SIZE_X-1; x >= 0; x--) {
- tile tile = map_loaded[y][x];
+ tile tile = loaded_map.heightmap[y][x];
float xdiff_between_bottom_and_top = info.px_incline;
float render_x = (info.tile_width * x) + (xdiff_between_bottom_and_top * y);
@@ -241,10 +248,10 @@ void draw_grid(platform_window* window) {
renderer->render_line(topright.x, topright.y, bottomright.x, bottomright.y, 1, rgb(0,0,255)); // right
renderer->render_line(bottomleft.x, bottomleft.y, bottomright.x, bottomright.y, 1, rgb(0,0,255)); // bottom
*/
- map_loaded[y][x].tl = topleft;
- map_loaded[y][x].tr = topright;
- map_loaded[y][x].bl = bottomleft;
- map_loaded[y][x].br = bottomright;
+ loaded_map.heightmap[y][x].tl = topleft;
+ loaded_map.heightmap[y][x].tr = topright;
+ loaded_map.heightmap[y][x].bl = bottomleft;
+ loaded_map.heightmap[y][x].br = bottomright;
}
draw_objects_at_row(window, y);
diff --git a/src/players.c b/src/players.c
index 6409b77..64518d1 100644
--- a/src/players.c
+++ b/src/players.c
@@ -140,13 +140,37 @@ int get_my_player_index() {
return -1;
}
+static bool is_editing_map = false;
+void draw_debug(platform_window* window) {
+ if (is_editing_map) {
+ map_info info = get_map_info(window);
+ int mouse_tile_y = (_global_mouse.y + _global_camera.y) / info.tile_height;
+ int mouse_tile_x = (((_global_mouse.x + _global_camera.x) - (info.px_incline * mouse_tile_y)) / info.tile_width);
+
+ if (mouse_tile_x < 0 || mouse_tile_y < 0) return;
+ if (mouse_tile_x >= loaded_map.width || mouse_tile_y >= loaded_map.height) return;
+
+ tile t = loaded_map.heightmap[mouse_tile_y][mouse_tile_x];
+ renderer->render_rectangle_outline(t.tl.x, t.tl.y, t.tr.x - t.tl.x, t.br.y - t.tr.y, 2, rgb(255,0,0));
+
+ if (is_left_clicked()) {
+ map_to_load.heightmap[mouse_tile_y][mouse_tile_x]++;
+ export_map_from_map_data();
+ }
+ }
+}
+
static void take_update_debug(platform_window* window) {
if (keyboard_is_key_down(KEY_LEFT_CONTROL) && keyboard_is_key_pressed(KEY_S)) {
platform_write_file_content("../data/maps/map1.dat", "wb", (u8*)&map_to_load, sizeof(map_to_load));
platform_write_file_content("data/maps/map1.dat", "wb", (u8*)&map_to_load, sizeof(map_to_load));
-
log_info("Saved map");
}
+
+ if (keyboard_is_key_pressed(KEY_F1)) {
+ is_editing_map = !is_editing_map;
+ log_infox("Editing map: %d", is_editing_map);
+ }
}
void take_player_input(platform_window* window) {
@@ -204,6 +228,8 @@ void take_player_input(platform_window* window) {
}
// shoot
+ if (is_editing_map) return;
+
{
if (is_left_down()) {
float dirx = (_global_mouse.x - (window->width/2));
diff --git a/src/protocol.c b/src/protocol.c
index 7d921de..b54091e 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -145,25 +145,24 @@ void add_message_to_outgoing_queue(send_queue_entry entry) {
void* network_send_thread(void* args) {
while (1) {
+ mutex_lock(&messages_to_send_queue_mutex);
for (int i = 0; i < OUTGOING_QUEUE_SIZE; i++)
{
- mutex_lock(&messages_to_send_queue_mutex);
if (!messages_to_send_queue[i].active) {
- mutex_unlock(&messages_to_send_queue_mutex);
continue;
}
send_queue_entry message = messages_to_send_queue[i];
messages_to_send_queue[i].active = false;
- mutex_unlock(&messages_to_send_queue_mutex);
- for (int x = 0; x < 10; x++) {
+ for (int x = 0; x < SERVER_MAX_PLAYERS; x++) {
network_client c = message.recipients[x];
if (c.ConnectSocket != 0) {
network_client_send(&c, message.message);
}
}
mem_free(message.message.data);
- thread_sleep(1000);
}
+ mutex_unlock(&messages_to_send_queue_mutex);
+ thread_sleep(1000);
}
} \ No newline at end of file
diff --git a/src/zombies.c b/src/zombies.c
index 542412e..f578701 100644
--- a/src/zombies.c
+++ b/src/zombies.c
@@ -82,7 +82,7 @@ void draw_spawners(platform_window* window) {
int render_x = (info.tile_width * spawner.position.x) + (info.px_incline * spawner.position.y);
int render_y = info.tile_height * spawner.position.y;
- tile tile = map_loaded[spawner.position.y][spawner.position.x];
+ tile tile = loaded_map.heightmap[spawner.position.y][spawner.position.x];
sprite_frame frame = sprite_get_frame(&spawner.sprite);
renderer->render_image_quad_partial(spawner.sprite.image,