summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-05-01 14:41:31 +0200
committerAldrik Ramaekers <aldrik@amftech.nl>2023-05-01 14:41:31 +0200
commit7338fe068fb4081938ca6530cd761a607a9c8ce9 (patch)
treed276bf71821a4446713d71445e9a6c32152913a6
parentb694a83655d97bb93318c4523a40c1915f3c05ee (diff)
icons
-rw-r--r--build/data/imgs/icons/arrow_down.pngbin0 -> 1980 bytes
-rw-r--r--build/data/imgs/icons/arrow_up.pngbin0 -> 1941 bytes
-rw-r--r--build/data/imgs/icons/cross.pngbin0 -> 6654 bytes
-rw-r--r--build/zombies.exebin1948683 -> 1950456 bytes
-rw-r--r--data/imgs/icons/arrow_down.pngbin0 -> 1980 bytes
-rw-r--r--data/imgs/icons/arrow_up.pngbin0 -> 1941 bytes
-rw-r--r--data/imgs/icons/cross.pngbin0 -> 6654 bytes
-rw-r--r--include/asset_defs.h13
-rw-r--r--include/map.h4
-rw-r--r--src/asset_defs.c23
-rw-r--r--src/editor.c81
-rw-r--r--src/map.c7
12 files changed, 93 insertions, 35 deletions
diff --git a/build/data/imgs/icons/arrow_down.png b/build/data/imgs/icons/arrow_down.png
new file mode 100644
index 0000000..0b06687
--- /dev/null
+++ b/build/data/imgs/icons/arrow_down.png
Binary files differ
diff --git a/build/data/imgs/icons/arrow_up.png b/build/data/imgs/icons/arrow_up.png
new file mode 100644
index 0000000..0ff88ae
--- /dev/null
+++ b/build/data/imgs/icons/arrow_up.png
Binary files differ
diff --git a/build/data/imgs/icons/cross.png b/build/data/imgs/icons/cross.png
new file mode 100644
index 0000000..a454a99
--- /dev/null
+++ b/build/data/imgs/icons/cross.png
Binary files differ
diff --git a/build/zombies.exe b/build/zombies.exe
index c29910a..9c8dd1e 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/data/imgs/icons/arrow_down.png b/data/imgs/icons/arrow_down.png
new file mode 100644
index 0000000..0b06687
--- /dev/null
+++ b/data/imgs/icons/arrow_down.png
Binary files differ
diff --git a/data/imgs/icons/arrow_up.png b/data/imgs/icons/arrow_up.png
new file mode 100644
index 0000000..0ff88ae
--- /dev/null
+++ b/data/imgs/icons/arrow_up.png
Binary files differ
diff --git a/data/imgs/icons/cross.png b/data/imgs/icons/cross.png
new file mode 100644
index 0000000..a454a99
--- /dev/null
+++ b/data/imgs/icons/cross.png
Binary files differ
diff --git a/include/asset_defs.h b/include/asset_defs.h
index 10919b4..154f542 100644
--- a/include/asset_defs.h
+++ b/include/asset_defs.h
@@ -6,21 +6,30 @@
font* fnt_24;
font* fnt_20;
+// Icons
image* img_icon_bullets;
image* img_icon_nova;
-
image* img_drop;
-image* img_spawner;
+image* img_arrow_up;
+image* img_arrow_down;
+image* img_cancel;
+// Objects
+image* img_spawner;
image* img_obj_plants;
image* img_obj_wall1;
+
+// Players
image* img_player;
+// Other
image* img_zombie_chunk_hand;
image* img_zombie_chunk_foot;
image* img_zombie_chunk_blood;
+// Tiles
image* img_tile_cobblestone;
+image* img_tile_grass1;
void load_assets();
diff --git a/include/map.h b/include/map.h
index 6a509e2..738d1c2 100644
--- a/include/map.h
+++ b/include/map.h
@@ -9,6 +9,9 @@
typedef enum t_tile_type {
TILE_NONE = 0,
TILE_COBBLESTONE1 = 1,
+ TILE_GRASS1 = 2,
+
+ TILE_END,
} tile_type;
typedef struct t_tile {
@@ -65,5 +68,6 @@ int get_tile_width(platform_window* window);
bool is_in_bounds(float x, float y);
void draw_grid(platform_window* window);
map_info get_map_info(platform_window* window);
+image* get_image_from_tiletype(tile_type tile);
#endif \ No newline at end of file
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
diff --git a/src/map.c b/src/map.c
index 499bf60..2f6b6b0 100644
--- a/src/map.c
+++ b/src/map.c
@@ -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;
}
}