diff options
| -rw-r--r-- | build/data/imgs/icons/3d.png | bin | 0 -> 1813 bytes | |||
| -rw-r--r-- | build/data/imgs/icons/sunny.png | bin | 0 -> 2107 bytes | |||
| -rw-r--r-- | build/data/imgs/icons/tiles.png | bin | 0 -> 1779 bytes | |||
| -rw-r--r-- | build/zombies.exe | bin | 1959351 -> 1961607 bytes | |||
| -rw-r--r-- | data/imgs/icons/3d.png | bin | 0 -> 1813 bytes | |||
| -rw-r--r-- | data/imgs/icons/sunny.png | bin | 0 -> 2107 bytes | |||
| -rw-r--r-- | data/imgs/icons/tiles.png | bin | 0 -> 1779 bytes | |||
| -rw-r--r-- | include/asset_defs.h | 3 | ||||
| -rw-r--r-- | include/map.h | 3 | ||||
| -rw-r--r-- | include/objects.h | 1 | ||||
| -rw-r--r-- | src/asset_defs.c | 3 | ||||
| -rw-r--r-- | src/editor.c | 59 | ||||
| -rw-r--r-- | src/map.c | 11 |
13 files changed, 65 insertions, 15 deletions
diff --git a/build/data/imgs/icons/3d.png b/build/data/imgs/icons/3d.png Binary files differnew file mode 100644 index 0000000..27b9168 --- /dev/null +++ b/build/data/imgs/icons/3d.png diff --git a/build/data/imgs/icons/sunny.png b/build/data/imgs/icons/sunny.png Binary files differnew file mode 100644 index 0000000..5cc30fd --- /dev/null +++ b/build/data/imgs/icons/sunny.png diff --git a/build/data/imgs/icons/tiles.png b/build/data/imgs/icons/tiles.png Binary files differnew file mode 100644 index 0000000..682397f --- /dev/null +++ b/build/data/imgs/icons/tiles.png diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex 4c31521..3fa502c 100644 --- a/build/zombies.exe +++ b/build/zombies.exe diff --git a/data/imgs/icons/3d.png b/data/imgs/icons/3d.png Binary files differnew file mode 100644 index 0000000..27b9168 --- /dev/null +++ b/data/imgs/icons/3d.png diff --git a/data/imgs/icons/sunny.png b/data/imgs/icons/sunny.png Binary files differnew file mode 100644 index 0000000..5cc30fd --- /dev/null +++ b/data/imgs/icons/sunny.png diff --git a/data/imgs/icons/tiles.png b/data/imgs/icons/tiles.png Binary files differnew file mode 100644 index 0000000..682397f --- /dev/null +++ b/data/imgs/icons/tiles.png diff --git a/include/asset_defs.h b/include/asset_defs.h index 154f542..a29ec89 100644 --- a/include/asset_defs.h +++ b/include/asset_defs.h @@ -13,6 +13,9 @@ image* img_drop; image* img_arrow_up; image* img_arrow_down; image* img_cancel; +image* img_3d; +image* img_tiles; +image* img_sunny; // Objects image* img_spawner; diff --git a/include/map.h b/include/map.h index e264600..9134d18 100644 --- a/include/map.h +++ b/include/map.h @@ -33,6 +33,7 @@ typedef struct t_tile { #define MAP_SIZE_X 40 #define MAP_SIZE_Y 40 +#define MAX_LIGHT_EMITTERS 100 typedef struct t_map_info { int tile_width; @@ -47,6 +48,7 @@ typedef struct t_map_data { int heightmap[MAP_SIZE_Y][MAP_SIZE_X]; tile_type tiles[MAP_SIZE_Y][MAP_SIZE_X]; object objects[MAX_OBJECTS]; + light_emitter light_emitters[MAX_LIGHT_EMITTERS]; } map_data; typedef struct t_light_data { @@ -62,6 +64,7 @@ typedef struct t_extracted_map_data { tile heightmap[MAP_SIZE_Y][MAP_SIZE_X]; object objects[MAX_OBJECTS]; light_data lightmap[MAP_SIZE_Y][MAP_SIZE_X]; + light_emitter light_emitters[MAX_LIGHT_EMITTERS]; } extracted_map_data; map_data map_to_load = {0}; diff --git a/include/objects.h b/include/objects.h index f79e115..e742f1e 100644 --- a/include/objects.h +++ b/include/objects.h @@ -12,6 +12,7 @@ typedef struct t_vec3f { } vec3f; typedef struct t_light_emitter { + bool active; vec3f position; float brightness; float range; diff --git a/src/asset_defs.c b/src/asset_defs.c index 23986b3..52df3b0 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -11,6 +11,9 @@ void load_assets() { img_arrow_up = assets_load_image_from_file("data/imgs/icons/arrow_up.png"); img_arrow_down = assets_load_image_from_file("data/imgs/icons/arrow_down.png"); img_cancel = assets_load_image_from_file("data/imgs/icons/cross.png"); + img_3d = assets_load_image_from_file("data/imgs/icons/3d.png"); + img_tiles = assets_load_image_from_file("data/imgs/icons/tiles.png"); + img_sunny = assets_load_image_from_file("data/imgs/icons/sunny.png"); // Objects img_spawner = assets_load_image_from_file("data/imgs/spawner.png"); diff --git a/src/editor.c b/src/editor.c index bb2fa7b..dd46e7d 100644 --- a/src/editor.c +++ b/src/editor.c @@ -14,11 +14,17 @@ typedef enum t_editor_state { EDITING_TILES, EDITING_OBJECTS, + EDITING_LIGHTING, } editor_state; +editor_state edit_state = EDITING_TILES; tile_editor_state tile_edit_state = PLACING_TILE; tile_type tile_to_place = TILE_NONE; +int editor_width = 200; +int borderw = 8; +int offset_y = 50; + void update_editor(platform_window* window) { if (keyboard_is_key_pressed(KEY_F1)) { @@ -106,10 +112,10 @@ void draw_placing_rectangle(platform_window* window) { static bool push_icon_button(int x, int y, int w, image* img, bool isSelected) { if (img) renderer->render_image(img,_global_camera.x+ x,_global_camera.y+ y, w, w); - renderer->render_rectangle_outline(_global_camera.x+ x,_global_camera.y+ y, w, w, 1, rgb(255,255,255)); + renderer->render_rectangle_outline(_global_camera.x+ x,_global_camera.y+ y, w+1, w+1, 1, rgb(255,255,255)); if (isSelected) { - renderer->render_rectangle_outline(_global_camera.x+ x,_global_camera.y+ y, w, w, 3, rgb(50,50,200)); + renderer->render_rectangle_outline(_global_camera.x+ x + 1,_global_camera.y+ y + 1, w-2, w-2, 3, rgb(50,50,200)); } if (_global_mouse.x > x && _global_mouse.x < x + w && _global_mouse.y > y && _global_mouse.y < y + w) { @@ -124,20 +130,17 @@ static bool push_icon_button(int x, int y, int w, image* img, bool isSelected) { } void draw_tile_panel(platform_window* window) { - int start_y = 1; - int width = 200; + int start_y = 1; // rows to skip int cols = 4; - int tile_w = width / cols; - - renderer->render_rectangle(_global_camera.x, _global_camera.y, width, window->height, rgb(200,150,100)); + int tile_w = editor_width / cols; - if (push_icon_button(tile_w*0, 0, tile_w, img_arrow_up, tile_edit_state == RAISING_GROUND)) { + if (push_icon_button(tile_w*0, offset_y, tile_w, img_arrow_up, tile_edit_state == RAISING_GROUND)) { tile_edit_state = RAISING_GROUND; } - if (push_icon_button(tile_w*1, 0, tile_w, img_arrow_down, tile_edit_state == LOWERING_GROUND)) { + if (push_icon_button(tile_w*1, offset_y, tile_w, img_arrow_down, tile_edit_state == LOWERING_GROUND)) { tile_edit_state = LOWERING_GROUND; } - if (push_icon_button(tile_w*2, 0, tile_w, img_cancel, tile_edit_state == PLACING_TILE && tile_to_place == TILE_NONE)) { + if (push_icon_button(tile_w*2, offset_y, tile_w, img_cancel, tile_edit_state == PLACING_TILE && tile_to_place == TILE_NONE)) { tile_to_place = TILE_NONE; tile_edit_state = PLACING_TILE; } @@ -147,6 +150,8 @@ void draw_tile_panel(platform_window* window) { int x = ((i-tile_start) % cols) * tile_w; int y = (start_y + ((i-tile_start) / cols)) * tile_w; + y += offset_y; + image* img = get_image_from_tiletype((tile_type)i); if (push_icon_button(x, y, tile_w, img, tile_edit_state == PLACING_TILE && tile_to_place == i)) { tile_to_place = i; @@ -155,10 +160,42 @@ void draw_tile_panel(platform_window* window) { } } +void draw_lighting_panel(platform_window* window) { + int row_h = 40; + + int count = 0; + for (int i = 0; i < MAX_LIGHT_EMITTERS; i++) { + light_emitter emitter = loaded_map.light_emitters[i]; + if (!emitter.active) continue; + + renderer->render_rectangle(_global_camera.x, _global_camera.y + offset_y + ((row_h+1)*count), editor_width, row_h, rgba(255,0,0,40)); + } +} + void draw_editor(platform_window* window) { if (is_editing_map) { draw_placing_rectangle(window); - draw_tile_panel(window); + + renderer->render_rectangle(_global_camera.x, _global_camera.y, editor_width, window->height, rgb(73, 140, 138)); + renderer->render_rectangle(_global_camera.x + editor_width, _global_camera.y, borderw, window->height, rgb(70, 172, 194)); + + if (push_icon_button(10, 10, 30, img_tiles, edit_state == EDITING_TILES)) { + edit_state = EDITING_TILES; + } + if (push_icon_button(50, 10, 30, img_3d, edit_state == EDITING_OBJECTS)) { + edit_state = EDITING_OBJECTS; + } + if (push_icon_button(90, 10, 30, img_sunny, edit_state == EDITING_LIGHTING)) { + edit_state = EDITING_LIGHTING; + } + + switch (edit_state) + { + case EDITING_TILES: draw_tile_panel(window); break; + case EDITING_OBJECTS: break; + case EDITING_LIGHTING: draw_lighting_panel(window); break; + } + } }
\ No newline at end of file @@ -139,15 +139,16 @@ void load_mapdata_into_world() { } } - light_emitter emitters[1] = { - {.brightness = 1.0f, .position = (vec3f){0, 0, 0}, .range = 10.0f}, - }; + // Load emitters + for (int i = 0; i < MAX_LIGHT_EMITTERS; i++) { + loaded_map.light_emitters[i] = map_to_load.light_emitters[i]; + } // Load lightmap for (int y = 0; y < MAP_SIZE_Y; y++) { for (int x = 0; x < MAP_SIZE_X; x++) { for (int l = 0; l < 1; l++) { - light_emitter emitter = emitters[l]; + light_emitter emitter = loaded_map.light_emitters[l]; float dist_tl = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map.heightmap[y][x].topleft}); float dist_tr = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map.heightmap[y][x].topright}); float dist_bl = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map.heightmap[y][x].bottomleft}); @@ -204,6 +205,8 @@ void create_empty_map() { map_to_load.objects[2] = (object){.active = true, .h = 0, .position = (vec2f){0, 1}, .size = (vec3f){1,1,2}, .type = OBJECT_COBBLESTONEWALL1}; map_to_load.objects[3] = (object){.active = true, .h = 0, .position = (vec2f){0, 2}, .size = (vec3f){1,1,2}, .type = OBJECT_COBBLESTONEWALL1}; + map_to_load.light_emitters[0] = (light_emitter){.brightness = 1.0f, .position = (vec3f){0, 0, 0}, .range = 10.0f, .active = true}; + load_mapdata_into_world(); } |
