diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-28 21:32:10 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-28 21:32:10 +0100 |
| commit | cb92e568b6af4c7a5cdfa4fccf20d6dd1d6e0727 (patch) | |
| tree | 4a92a68a1f4f7f6c75ee0892b1ec6a791c356bec /src | |
| parent | e3724ffc498462d1da85542a57e91d9b882ad6dd (diff) | |
working on shadows
Diffstat (limited to 'src')
| -rw-r--r-- | src/data.c | 1 | ||||
| -rw-r--r-- | src/include/data.h | 1 | ||||
| -rw-r--r-- | src/scenes/world_map.c | 47 | ||||
| -rw-r--r-- | src/world.c | 6 |
4 files changed, 55 insertions, 0 deletions
@@ -53,6 +53,7 @@ void data_load() img_denied = assets_load_image_from_file("data/img/denied.png");
img_world_map = assets_load_image_from_file("data/img/world_background.png");
img_invest = assets_load_image_from_file("data/img/invest.png");
+ img_shadow = assets_load_image_from_file("data/img/shadow.png");
img_panel_bottom = assets_load_image_from_file("data/img/panel_bottom.png");
img_panel_top = assets_load_image_from_file("data/img/panel_top.png");
diff --git a/src/include/data.h b/src/include/data.h index 65f7389..b5e038c 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -55,6 +55,7 @@ image* img_hired; image* img_denied;
image* img_world_map;
image* img_invest;
+image* img_shadow;
image* img_button_bottom;
image* img_button_top;
diff --git a/src/scenes/world_map.c b/src/scenes/world_map.c index 1e3f76d..39aa749 100644 --- a/src/scenes/world_map.c +++ b/src/scenes/world_map.c @@ -1054,6 +1054,51 @@ static void world_handle_scroll(platform_window* window) if (camera_x < max_camera_offset_x) camera_x = max_camera_offset_x;
}
+static vec4 world_map_get_daytime_rect()
+{
+ int hour = _active_world->current_time.tm_hour;
+ int minutes = _active_world->current_time.tm_min;
+
+ int offset = area.w*zoom - ((((hour*60.0f) + minutes) / (24*60.0f)) * area.w*zoom);
+
+ vec4 rec = (vec4){0,0,0,0};
+ return rec;
+}
+
+static color img_get_px(image* img, s32 x, s32 y)
+{
+ if (x < 0 || y < 0) return rgba(0,0,0,0);
+ if (x > img->width || y > img->height) return rgba(0,0,0,0);
+ u8* bytes = (((u8*)img->data) + (img->width * img->channels * y) + (img->channels * x));
+ color c = *(color*)(bytes);
+ return c;
+}
+
+static s32 shadow_offset = 0;
+static s32 shadow2_offset = 0;
+
+bool world_map_location_is_in_sun(vec2f px_pos)
+{
+ return !(img_get_px(img_shadow, shadow_offset + px_pos.x, px_pos.y).a == 255);
+ // return img_get_px(img_shadow, shadow2_offset - px_pos.x, px_pos.y).a == 255;
+}
+
+static void world_map_draw_night(platform_window* window)
+{
+ int hour = _active_world->current_time.tm_hour;
+ int minutes = _active_world->current_time.tm_min;
+
+ int offset = area.w*zoom - ((((hour*60.0f) + minutes) / (24*60.0f)) * area.w*zoom);
+
+ shadow_offset = area.x + camera_x + offset;
+ shadow2_offset = area.x + camera_x + offset - area.w*zoom;
+
+ renderer->render_image_tint(img_shadow, shadow_offset, area.y + camera_y, area.w*zoom, area.h*zoom, rgba(255,255,255,100));
+ //renderer->render_image_tint(img_shadow, shadow2_offset, area.y + camera_y, area.w*zoom, area.h*zoom, rgba(255,255,255,100));
+
+ img_get_px(img_shadow, offset, img_shadow->height/2);
+}
+
void world_map_scene_render(platform_window* window)
{
renderer->set_render_depth(5);
@@ -1106,6 +1151,8 @@ void world_map_scene_render(platform_window* window) vec4 area = camera_get_target_rectangle(window);
renderer->render_rectangle(area.x + camera_x, area.y + camera_y, area.w*zoom, area.h*zoom, COLOR_WORLD_MAP_BACKGROUND);
renderer->render_image(img_world_map, area.x + camera_x, area.y + camera_y, area.w*zoom, area.h*zoom);
+
+ world_map_draw_night(window);
}
void world_map_scene_update(platform_window* window)
diff --git a/src/world.c b/src/world.c index 8ceb5b3..13dc644 100644 --- a/src/world.c +++ b/src/world.c @@ -1351,6 +1351,8 @@ static bool world_check_location_accessibility(world_location* orig, world_locat return false;
}
+bool world_map_location_is_in_sun(vec2f px_pos);
+
world_update_result world_render(platform_window* window, world* world)
{
world_update_result result = {0,0};
@@ -1391,6 +1393,10 @@ world_update_result world_render(platform_window* window, world* world) if (!location->is_accessible) {
tint = COLOR_LOCATION_DOT_UNACCESSIBLE;
}
+
+ if (!world_map_location_is_in_sun(map_pos)) {
+ tint = rgb(255, 255, 0);
+ }
renderer->render_image_tint(img_locationdot, circle_x, circle_y, dotsize, dotsize, tint);
}
|
