diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-05-01 14:41:31 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-05-01 14:41:31 +0200 |
| commit | 7338fe068fb4081938ca6530cd761a607a9c8ce9 (patch) | |
| tree | d276bf71821a4446713d71445e9a6c32152913a6 /src | |
| parent | b694a83655d97bb93318c4523a40c1915f3c05ee (diff) | |
icons
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset_defs.c | 23 | ||||
| -rw-r--r-- | src/editor.c | 81 | ||||
| -rw-r--r-- | src/map.c | 7 |
3 files changed, 78 insertions, 33 deletions
diff --git a/src/asset_defs.c b/src/asset_defs.c index c2edd78..23986b3 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -4,21 +4,28 @@ void load_assets() { 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); + // Icons img_icon_bullets = assets_load_image_from_file("data/imgs/bullets.png"); img_icon_nova = assets_load_image_from_file("data/imgs/nova.png"); - img_drop = assets_load_image_from_file("data/imgs/drop.png"); + 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_zombie_chunk_hand = assets_load_image_from_file("data/imgs/zombie_chunk_hand.png"); - 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/tiles/tile_cobblestone.png"); - + // Objects img_spawner = assets_load_image_from_file("data/imgs/spawner.png"); - img_obj_plants = assets_load_image_from_file("data/imgs/plants.png"); img_obj_wall1 = assets_load_image_from_file("data/imgs/wall1.png"); + // Players img_player = assets_load_image_from_file("data/imgs/player.png"); + + // Other + img_zombie_chunk_hand = assets_load_image_from_file("data/imgs/zombie_chunk_hand.png"); + 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"); + + // Tiles + img_tile_cobblestone = assets_load_image_from_file("data/imgs/tiles/tile_cobblestone.png"); + img_tile_grass1 = assets_load_image_from_file("data/imgs/tiles/tile_grass1.png"); }
\ No newline at end of file diff --git a/src/editor.c b/src/editor.c index e465408..673432b 100644 --- a/src/editor.c +++ b/src/editor.c @@ -26,6 +26,9 @@ void update_editor(platform_window* window) camera_x += update_delta*cam_speed; } + _next_camera_pos.x = -(window->width / 2) + camera_x; + _next_camera_pos.y = -(window->height / 2) + camera_y; + 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)); @@ -33,29 +36,65 @@ void update_editor(platform_window* window) } } +void draw_placing_rectangle(platform_window* window) { + 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 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)); + + return false; +} + +void draw_tile_panel(platform_window* window) { + int start_y = 1; + int width = 200; + int cols = 4; + int tile_w = width / cols; + + 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)) { + + } + if (push_icon_button(tile_w*1, 0, tile_w, img_arrow_down)) { + + } + if (push_icon_button(tile_w*2, 0, tile_w, img_cancel)) { + + } + + for (int i = 0; i < TILE_END; i++) { + int x = i % cols * tile_w; + int y = (start_y + (i / cols)) * tile_w; + + image* img = get_image_from_tiletype((tile_type)i); + push_icon_button(x, y, tile_w, img); + } +} + 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(); - } + draw_placing_rectangle(window); + draw_tile_panel(window); } }
\ No newline at end of file @@ -197,10 +197,9 @@ bool is_in_bounds(float x, float y) { image* get_image_from_tiletype(tile_type tile) { switch (tile) { - case TILE_COBBLESTONE1: - return img_tile_cobblestone; - default: - return 0; + case TILE_COBBLESTONE1: return img_tile_cobblestone; + case TILE_GRASS1: return img_tile_grass1; + default: return 0; } } |
