diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-05-01 16:12:11 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-05-01 16:12:11 +0200 |
| commit | 314c92ea455c235f1becf71eb420b8461292eae8 (patch) | |
| tree | 45051b889c62edade4289a644aa5857a9f046b27 | |
| parent | 7338fe068fb4081938ca6530cd761a607a9c8ce9 (diff) | |
editor work
| -rw-r--r-- | build/zombies.exe | bin | 1950456 -> 1951541 bytes | |||
| -rw-r--r-- | src/editor.c | 69 | ||||
| -rw-r--r-- | src/map.c | 11 |
3 files changed, 63 insertions, 17 deletions
diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex 9c8dd1e..4c1e73d 100644 --- a/build/zombies.exe +++ b/build/zombies.exe diff --git a/src/editor.c b/src/editor.c index 673432b..c50daf1 100644 --- a/src/editor.c +++ b/src/editor.c @@ -3,6 +3,16 @@ float camera_x = 0; float camera_y = 0; +typedef enum t_editor_state +{ + PLACING_TILE, + RAISING_GROUND, + LOWERING_GROUND, +} editor_state; + +editor_state edit_state = PLACING_TILE; +tile_type tile_to_place = TILE_NONE; + void update_editor(platform_window* window) { if (keyboard_is_key_pressed(KEY_F1)) { @@ -47,13 +57,31 @@ void draw_placing_rectangle(platform_window* window) { 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(); + switch (edit_state) + { + case PLACING_TILE: + if (is_left_down()) { + map_to_load.tiles[mouse_tile_y][mouse_tile_x] = tile_to_place; + load_mapdata_into_world(); + } + break; + + case RAISING_GROUND: + if (is_left_clicked()) { + map_to_load.heightmap[mouse_tile_y][mouse_tile_x]++; + load_mapdata_into_world(); + } + break; + + case LOWERING_GROUND: + if (is_left_clicked()) { + map_to_load.heightmap[mouse_tile_y][mouse_tile_x]--; + load_mapdata_into_world(); + } + break; + + default: + break; } } @@ -61,6 +89,14 @@ static bool push_icon_button(int x, int y, int w, image* img) { 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,0,0)); + if (_global_mouse.x > x && _global_mouse.x < x + w && _global_mouse.y > y && _global_mouse.y < y + w) { + renderer->render_rectangle(_global_camera.x+ x,_global_camera.y+ y, w, w, rgba(100,120,200,120)); + + if (is_left_clicked()) { + return true; + } + } + return false; } @@ -73,21 +109,26 @@ void draw_tile_panel(platform_window* window) { renderer->render_rectangle(_global_camera.x, _global_camera.y, width, window->height, rgb(200,150,100)); if (push_icon_button(tile_w*0, 0, tile_w, img_arrow_up)) { - + edit_state = RAISING_GROUND; } if (push_icon_button(tile_w*1, 0, tile_w, img_arrow_down)) { - + edit_state = LOWERING_GROUND; } if (push_icon_button(tile_w*2, 0, tile_w, img_cancel)) { - + tile_to_place = TILE_NONE; + edit_state = PLACING_TILE; } - for (int i = 0; i < TILE_END; i++) { - int x = i % cols * tile_w; - int y = (start_y + (i / cols)) * tile_w; + int tile_start = TILE_NONE+1; + for (int i = tile_start; i < TILE_END; i++) { + int x = ((i-tile_start) % cols) * tile_w; + int y = (start_y + ((i-tile_start) / cols)) * tile_w; image* img = get_image_from_tiletype((tile_type)i); - push_icon_button(x, y, tile_w, img); + if (push_icon_button(x, y, tile_w, img)) { + tile_to_place = i; + edit_state = PLACING_TILE; + } } } @@ -105,7 +105,7 @@ void load_mapdata_into_world() { 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); - loaded_map.heightmap[y][x] = (tile){h, TILE_COBBLESTONE1, highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright}; + loaded_map.heightmap[y][x] = (tile){.height = h, .type = map_to_load.tiles[y][x], highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright}; } } @@ -117,8 +117,11 @@ void create_empty_map() { 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)); + for (int y = 0; y < MAP_SIZE_Y; y++) { + for (int x = 0; x < MAP_SIZE_X; x++) { + map_to_load.tiles[y][x] = TILE_COBBLESTONE1; + } + } map_to_load.objects[0] = (object){.active = true, .h = 0, .position = (vec2f){16, 8}, .size = (vec3f){1,1,2}, .type = OBJECT_PLANTBOX1}; @@ -126,6 +129,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}; + printf("XDD: %d\n", map_to_load.tiles[0][0]); + load_mapdata_into_world(); } |
