summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
6 files changed, 74 insertions, 46 deletions
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)) {