summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json6
-rw-r--r--build/data/imgs/tile_cobblestone.pngbin2553 -> 3147 bytes
-rw-r--r--build/data/imgs/tiles/tile_cobblestone.pngbin0 -> 42438 bytes
-rw-r--r--build/data/imgs/tiles/tile_grass1.pngbin0 -> 32757 bytes
-rw-r--r--build/data/maps/map1.datbin6408 -> 44808 bytes
-rw-r--r--build/zombies.exebin1947626 -> 1948683 bytes
-rw-r--r--data/imgs/tile_cobblestone.pngbin2553 -> 3147 bytes
-rw-r--r--data/imgs/tiles/tile_cobblestone.pngbin0 -> 42438 bytes
-rw-r--r--data/imgs/tiles/tile_grass1.pngbin0 -> 32757 bytes
-rw-r--r--data/maps/map1.datbin6408 -> 44808 bytes
-rw-r--r--include/editor.h11
-rw-r--r--include/game.h2
-rw-r--r--main.c2
-rw-r--r--src/asset_defs.c2
-rw-r--r--src/editor.c61
-rw-r--r--src/game.c6
-rw-r--r--src/map.c7
-rw-r--r--src/objects.c2
-rw-r--r--src/players.c42
19 files changed, 93 insertions, 48 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..0282dca
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,6 @@
+{
+ "files.associations": {
+ "*.ejs": "html",
+ "editor.h": "c"
+ }
+} \ No newline at end of file
diff --git a/build/data/imgs/tile_cobblestone.png b/build/data/imgs/tile_cobblestone.png
index 42c6f81..86a59fb 100644
--- a/build/data/imgs/tile_cobblestone.png
+++ b/build/data/imgs/tile_cobblestone.png
Binary files differ
diff --git a/build/data/imgs/tiles/tile_cobblestone.png b/build/data/imgs/tiles/tile_cobblestone.png
new file mode 100644
index 0000000..31ab8ee
--- /dev/null
+++ b/build/data/imgs/tiles/tile_cobblestone.png
Binary files differ
diff --git a/build/data/imgs/tiles/tile_grass1.png b/build/data/imgs/tiles/tile_grass1.png
new file mode 100644
index 0000000..24210cb
--- /dev/null
+++ b/build/data/imgs/tiles/tile_grass1.png
Binary files differ
diff --git a/build/data/maps/map1.dat b/build/data/maps/map1.dat
index 956b184..15fcc91 100644
--- a/build/data/maps/map1.dat
+++ b/build/data/maps/map1.dat
Binary files differ
diff --git a/build/zombies.exe b/build/zombies.exe
index aa6d180..c29910a 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/data/imgs/tile_cobblestone.png b/data/imgs/tile_cobblestone.png
index 42c6f81..86a59fb 100644
--- a/data/imgs/tile_cobblestone.png
+++ b/data/imgs/tile_cobblestone.png
Binary files differ
diff --git a/data/imgs/tiles/tile_cobblestone.png b/data/imgs/tiles/tile_cobblestone.png
new file mode 100644
index 0000000..31ab8ee
--- /dev/null
+++ b/data/imgs/tiles/tile_cobblestone.png
Binary files differ
diff --git a/data/imgs/tiles/tile_grass1.png b/data/imgs/tiles/tile_grass1.png
new file mode 100644
index 0000000..24210cb
--- /dev/null
+++ b/data/imgs/tiles/tile_grass1.png
Binary files differ
diff --git a/data/maps/map1.dat b/data/maps/map1.dat
index 956b184..15fcc91 100644
--- a/data/maps/map1.dat
+++ b/data/maps/map1.dat
Binary files differ
diff --git a/include/editor.h b/include/editor.h
new file mode 100644
index 0000000..e6fbb0a
--- /dev/null
+++ b/include/editor.h
@@ -0,0 +1,11 @@
+#ifndef INCLUDE_EDITOR
+#define INCLUDE_EDITOR
+
+#ifdef MODE_DEBUG
+bool is_editing_map = false;
+
+void update_editor(platform_window* window);
+void draw_editor(platform_window* window);
+#endif
+
+#endif \ No newline at end of file
diff --git a/include/game.h b/include/game.h
index cc1057d..f2fd0cb 100644
--- a/include/game.h
+++ b/include/game.h
@@ -11,8 +11,6 @@
#define SERVER_MAX_PLAYERS (10)
#define SERVER_PATHFINDING_INTERVAL (0.25f)
-bool is_editing_map = false;
-
typedef enum t_game_state {
GAMESTATE_IDLE,
GAMESTATE_LOADING_MAP,
diff --git a/main.c b/main.c
index 86eaad4..b0505e9 100644
--- a/main.c
+++ b/main.c
@@ -20,6 +20,7 @@
#include "include/wall_item.h"
#include "include/zombie_chunk.h"
#include "include/sprite.h"
+#include "include/editor.h"
#include "src/map.c"
#include "src/players.c"
@@ -39,6 +40,7 @@
#include "src/wall_item.c"
#include "src/zombie_chunk.c"
#include "src/sprite.c"
+#include "src/editor.c"
#define CONFIG_DIRECTORY "zombieshooter"
diff --git a/src/asset_defs.c b/src/asset_defs.c
index 2753ae6..c2edd78 100644
--- a/src/asset_defs.c
+++ b/src/asset_defs.c
@@ -13,7 +13,7 @@ void load_assets() {
img_zombie_chunk_foot = assets_load_image_from_file("data/imgs/zombie_chunk_foot.png");
img_zombie_chunk_blood = assets_load_image_from_file("data/imgs/zombie_chunk_blood.png");
- img_tile_cobblestone = assets_load_image_from_file("data/imgs/tile_cobblestone.png");
+ img_tile_cobblestone = assets_load_image_from_file("data/imgs/tiles/tile_cobblestone.png");
img_spawner = assets_load_image_from_file("data/imgs/spawner.png");
diff --git a/src/editor.c b/src/editor.c
new file mode 100644
index 0000000..e465408
--- /dev/null
+++ b/src/editor.c
@@ -0,0 +1,61 @@
+#include "../include/editor.h"
+
+float camera_x = 0;
+float camera_y = 0;
+
+void update_editor(platform_window* window)
+{
+ if (keyboard_is_key_pressed(KEY_F1)) {
+ is_editing_map = !is_editing_map;
+ log_infox("Editing map: %d", is_editing_map);
+ }
+
+ if (!is_editing_map) return;
+
+ float cam_speed = 500;
+ if (keyboard_is_key_down(KEY_W)) {
+ camera_y -= update_delta*cam_speed;
+ }
+ if (keyboard_is_key_down(KEY_S)) {
+ camera_y += update_delta*cam_speed;
+ }
+ if (keyboard_is_key_down(KEY_A)) {
+ camera_x -= update_delta*cam_speed;
+ }
+ if (keyboard_is_key_down(KEY_D)) {
+ camera_x += update_delta*cam_speed;
+ }
+
+ 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");
+ }
+}
+
+void draw_editor(platform_window* window)
+{
+ if (is_editing_map) {
+ _next_camera_pos.x = -(window->width / 2) + camera_x;
+ _next_camera_pos.y = -(window->height / 2) + camera_y;
+
+ 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]++;
+ load_mapdata_into_world();
+ }
+ if (is_right_clicked()) {
+ map_to_load.heightmap[mouse_tile_y][mouse_tile_x]--;
+ load_mapdata_into_world();
+ }
+ }
+} \ No newline at end of file
diff --git a/src/game.c b/src/game.c
index f07a658..4c5f682 100644
--- a/src/game.c
+++ b/src/game.c
@@ -301,12 +301,16 @@ void update_game(platform_window* window) {
#endif
draw_zombies(window);
+ #ifdef MODE_DEBUG
+ if (!is_editing_map)
+ #endif
draw_players(window);
+
draw_spawners(window);
draw_overlay(window);
#ifdef MODE_DEBUG
- draw_debug(window);
+ draw_editor(window);
#endif
_global_camera.x = (int)_next_camera_pos.x;
diff --git a/src/map.c b/src/map.c
index 441cc81..499bf60 100644
--- a/src/map.c
+++ b/src/map.c
@@ -94,6 +94,9 @@ static int get_height_of_tile_tr(int current_height, int x, int y) {
}
void load_mapdata_into_world() {
+ loaded_map.width = map_to_load.width;
+ loaded_map.height = map_to_load.height;
+
// Load heightmap
for (int y = 0; y < MAP_SIZE_Y; y++) {
for (int x = MAP_SIZE_X-1; x >= 0; x--) {
@@ -111,8 +114,8 @@ void load_mapdata_into_world() {
}
void create_empty_map() {
- loaded_map.width = MAP_SIZE_X;
- loaded_map.height = MAP_SIZE_Y;
+ map_to_load.width = MAP_SIZE_X;
+ map_to_load.height = MAP_SIZE_Y;
memset(map_to_load.tiles, TILE_COBBLESTONE1, sizeof(map_to_load.tiles));
memset(map_to_load.heightmap, 0, sizeof(loaded_map.heightmap));
diff --git a/src/objects.c b/src/objects.c
index 3969000..17123f9 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -99,7 +99,7 @@ void create_objects() {
create_spawner((vec2){15, 5});
create_spawner((vec2){3, 8});
- create_spawner((vec2){11, 18});
*/
+ create_spawner((vec2){11, 18});
create_wallitem((vec3f){14, 1, 0}, WALLITEM_GUN, (wall_item_data){.gun = GUN_NOVA});
} \ No newline at end of file
diff --git a/src/players.c b/src/players.c
index 05da02c..2488693 100644
--- a/src/players.c
+++ b/src/players.c
@@ -140,52 +140,12 @@ int get_my_player_index() {
return -1;
}
-#ifdef MODE_DEBUG
-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]++;
- load_mapdata_into_world();
- }
- if (is_right_clicked()) {
- map_to_load.heightmap[mouse_tile_y][mouse_tile_x]--;
- load_mapdata_into_world();
- }
- }
-}
-
-static void take_update_debug(platform_window* window) {
- if (keyboard_is_key_pressed(KEY_F1)) {
- is_editing_map = !is_editing_map;
- log_infox("Editing map: %d", is_editing_map);
- }
-
- if (!is_editing_map) return;
-
- 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");
- }
-}
-#endif
-
void take_player_input(platform_window* window) {
player* p = get_player_by_id(player_id);
if (!p) return;
#ifdef MODE_DEBUG
- take_update_debug(window);
+ update_editor(window);
#endif
if (keyboard_is_key_down(KEY_W)) {