Better map uploading algorithm

This commit is contained in:
2025-09-24 19:17:48 +02:00
parent 8d7b8d82d8
commit d99ae5c05b
2 changed files with 9 additions and 5 deletions
+1
View File
@@ -45,3 +45,4 @@ void GfxContext_render (GfxContext *self);
void GfxContext_free (GfxContext * self);
void GfxContext_cache_World (GfxContext * self, World * world);
void GfxContext_update_Players (GfxContext *self, World * world);
+8 -5
View File
@@ -65,21 +65,24 @@ World_load_from_file (const char *path)
/* NULL is a palette, only used in indexed images. */
SDL_GetRGBA (pixel, details, NULL, &r, &g, &b, &a);
/* The ranges here can be tweaked to work better or
worse. */
if (b > 196 && r < 50 && g < 50)
/* Improved color ranges (handles light blue water better) */
if (b > 120 && (b > g || b > r))
{
/* Water: medium-to-light blues */
mt->terrain_type = TERRAIN_WATER;
}
else if (g > 200)
else if (g > 140 && g >= r && g >= b)
{
/* Green-dominant = flat/grassland */
mt->terrain_type = TERRAIN_FLAT;
}
else
{
/* Otherwise: hills/mountains */
mt->terrain_type = TERRAIN_HILL;
}
/* Thanks, ChatGPT! */
g_array_append_val (self->tiles, mt);
}
}