summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-05-01 21:54:44 +0200
committerAldrik Ramaekers <aldrik@amftech.nl>2023-05-01 21:54:44 +0200
commit7dd42a4af58f795dfced9a22b31855f276beecfc (patch)
treee1f7177b9bfff62a0cc62b6483248549c7114003
parent314c92ea455c235f1becf71eb420b8461292eae8 (diff)
editor work
-rw-r--r--build/data/maps/map1.datbin44808 -> 44808 bytes
-rw-r--r--build/zombies.exebin1951541 -> 1952053 bytes
-rw-r--r--data/maps/map1.datbin44808 -> 44808 bytes
-rw-r--r--src/editor.c83
-rw-r--r--src/map.c12
5 files changed, 54 insertions, 41 deletions
diff --git a/build/data/maps/map1.dat b/build/data/maps/map1.dat
index 15fcc91..f85da8a 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 4c1e73d..3375fbb 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/data/maps/map1.dat b/data/maps/map1.dat
index 15fcc91..f85da8a 100644
--- a/data/maps/map1.dat
+++ b/data/maps/map1.dat
Binary files differ
diff --git a/src/editor.c b/src/editor.c
index c50daf1..becfa14 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -39,6 +39,40 @@ void update_editor(platform_window* window)
_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;
+
+ 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()) {
+ if (map_to_load.heightmap[mouse_tile_y][mouse_tile_x] > 0) map_to_load.heightmap[mouse_tile_y][mouse_tile_x]--;
+ load_mapdata_into_world();
+ }
+ break;
+
+ default:
+ break;
+ }
+
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));
@@ -55,39 +89,22 @@ void draw_placing_rectangle(platform_window* window) {
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));
-
- 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;
- }
+ //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));
+
+ renderer->render_line(t.tl.x, t.tl.y, t.tr.x, t.tr.y, 1, rgb(0,0,255)); // top
+ renderer->render_line(t.tl.x, t.tl.y, t.bl.x, t.bl.y, 1, rgb(0,0,255)); // left
+ renderer->render_line(t.tr.x, t.tr.y, t.br.x, t.br.y, 1, rgb(0,0,255)); // right
+ renderer->render_line(t.bl.x, t.bl.y, t.br.x, t.br.y, 1, rgb(0,0,255)); // bottom
}
-static bool push_icon_button(int x, int y, int w, image* img) {
+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,0,0));
+ renderer->render_rectangle_outline(_global_camera.x+ x,_global_camera.y+ y, w, w, 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));
+ }
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));
@@ -108,13 +125,13 @@ 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)) {
+ if (push_icon_button(tile_w*0, 0, tile_w, img_arrow_up, edit_state == RAISING_GROUND)) {
edit_state = RAISING_GROUND;
}
- if (push_icon_button(tile_w*1, 0, tile_w, img_arrow_down)) {
+ if (push_icon_button(tile_w*1, 0, tile_w, img_arrow_down, edit_state == LOWERING_GROUND)) {
edit_state = LOWERING_GROUND;
}
- if (push_icon_button(tile_w*2, 0, tile_w, img_cancel)) {
+ if (push_icon_button(tile_w*2, 0, tile_w, img_cancel, edit_state == PLACING_TILE && tile_to_place == TILE_NONE)) {
tile_to_place = TILE_NONE;
edit_state = PLACING_TILE;
}
@@ -125,7 +142,7 @@ void draw_tile_panel(platform_window* window) {
int y = (start_y + ((i-tile_start) / cols)) * tile_w;
image* img = get_image_from_tiletype((tile_type)i);
- if (push_icon_button(x, y, tile_w, img)) {
+ if (push_icon_button(x, y, tile_w, img, edit_state == PLACING_TILE && tile_to_place == i)) {
tile_to_place = i;
edit_state = PLACING_TILE;
}
diff --git a/src/map.c b/src/map.c
index 62b72a4..06dcd58 100644
--- a/src/map.c
+++ b/src/map.c
@@ -129,8 +129,6 @@ 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();
}
@@ -234,15 +232,13 @@ void draw_grid(platform_window* window) {
vec2f topright;
int highest_point_topleft = tile.topleft;
- topleft = (vec2f){render_x, info.tile_width * y - highest_point_topleft*info.px_raised_per_h};
-
int highest_point_topright = tile.topright;
- topright = (vec2f){render_x + info.tile_width, info.tile_height * y - highest_point_topright*info.px_raised_per_h};
-
int highest_point_bottomright = tile.bottomright;
- bottomright = (vec2f){render_x + xdiff_between_bottom_and_top+info.tile_width, info.tile_height * y + info.tile_height - highest_point_bottomright*info.px_raised_per_h};
-
int highest_point_bottomleft = tile.bottomleft;
+
+ topleft = (vec2f){render_x, info.tile_width * y - highest_point_topleft*info.px_raised_per_h};
+ topright = (vec2f){render_x + info.tile_width, info.tile_height * y - highest_point_topright*info.px_raised_per_h};
+ bottomright = (vec2f){render_x + xdiff_between_bottom_and_top+info.tile_width, info.tile_height * y + info.tile_height - highest_point_bottomright*info.px_raised_per_h};
bottomleft = (vec2f){render_x + xdiff_between_bottom_and_top, info.tile_height * y + info.tile_height - highest_point_bottomleft*info.px_raised_per_h};
color c = rgb(205,205,205);