Add static water surface

main
En Yi 2025-08-31 20:44:59 +08:00
parent 595b778066
commit 2946921edc
1 changed files with 22 additions and 5 deletions

View File

@ -537,6 +537,7 @@ static void render_editor_game_scene(Scene_t* scene)
execute_render(&data->render_manager); execute_render(&data->render_manager);
const Color water_colour = ColorAlpha(BLUE, 0.5);
for (int tile_y = min.y; tile_y < max.y; tile_y++) for (int tile_y = min.y; tile_y < max.y; tile_y++)
{ {
for (int tile_x = min.x; tile_x < max.x; tile_x++) for (int tile_x = min.x; tile_x < max.x; tile_x++)
@ -586,7 +587,7 @@ static void render_editor_game_scene(Scene_t* scene)
int bot_line = y + TILE_SIZE - tilemap.tiles[i].water_level * WATER_BBOX_STEP - SURFACE_THICKNESS / 2; int bot_line = y + TILE_SIZE - tilemap.tiles[i].water_level * WATER_BBOX_STEP - SURFACE_THICKNESS / 2;
if (up >= 0 && tilemap.tiles[up].wet) if (up >= 0 && tilemap.tiles[up].wet)
{ {
DrawLineEx((Vector2){x + TILE_SIZE / 2, y}, (Vector2){x + TILE_SIZE / 2, y + TILE_SIZE - tilemap.tiles[i].water_level * WATER_BBOX_STEP}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7)); DrawLineEx((Vector2){x + TILE_SIZE / 2, y}, (Vector2){x + TILE_SIZE / 2, y + TILE_SIZE - tilemap.tiles[i].water_level * WATER_BBOX_STEP}, SURFACE_THICKNESS, water_colour);
} }
@ -597,18 +598,18 @@ static void render_editor_game_scene(Scene_t* scene)
{ {
if (i % tilemap.width != 0 && tilemap.tiles[left].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot-1].solid == SOLID)) if (i % tilemap.width != 0 && tilemap.tiles[left].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot-1].solid == SOLID))
{ {
DrawLineEx((Vector2){x, bot_line}, (Vector2){x + TILE_SIZE / 2, bot_line}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7)); DrawLineEx((Vector2){x, bot_line}, (Vector2){x + TILE_SIZE / 2, bot_line}, SURFACE_THICKNESS, water_colour);
} }
if (right % tilemap.width != 0 && tilemap.tiles[right].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot+1].solid == SOLID)) if (right % tilemap.width != 0 && tilemap.tiles[right].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot+1].solid == SOLID))
{ {
DrawLineEx((Vector2){x + TILE_SIZE / 2, bot_line}, (Vector2){x + TILE_SIZE, bot_line}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7)); DrawLineEx((Vector2){x + TILE_SIZE / 2, bot_line}, (Vector2){x + TILE_SIZE, bot_line}, SURFACE_THICKNESS, water_colour);
} }
} }
} }
if (tilemap.tiles[i].max_water_level < MAX_WATER_LEVEL) if (tilemap.tiles[i].max_water_level < MAX_WATER_LEVEL)
{ {
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, ColorAlpha(BLUE, 0.5)); DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, water_colour);
} }
} }
} }
@ -616,6 +617,8 @@ static void render_editor_game_scene(Scene_t* scene)
draw_particle_system(&scene->part_sys); draw_particle_system(&scene->part_sys);
// Draw water tile // Draw water tile
Sprite_t* surface_spr = get_sprite(&scene->engine->assets, "wsurf");
Vector2 surf_offset = get_anchor_offset(surface_spr->frame_size, AP_BOT_LEFT, false);
for (int tile_y = min.y; tile_y < max.y; tile_y++) for (int tile_y = min.y; tile_y < max.y; tile_y++)
{ {
for (int tile_x = min.x; tile_x < max.x; tile_x++) for (int tile_x = min.x; tile_x < max.x; tile_x++)
@ -625,7 +628,6 @@ static void render_editor_game_scene(Scene_t* scene)
int y = tile_y * TILE_SIZE; int y = tile_y * TILE_SIZE;
uint32_t water_height = tilemap.tiles[i].water_level * WATER_BBOX_STEP; uint32_t water_height = tilemap.tiles[i].water_level * WATER_BBOX_STEP;
Color water_colour = ColorAlpha(BLUE, 0.5);
DrawRectangle( DrawRectangle(
x, x,
y + (TILE_SIZE - water_height), y + (TILE_SIZE - water_height),
@ -633,6 +635,21 @@ static void render_editor_game_scene(Scene_t* scene)
water_height, water_height,
water_colour water_colour
); );
if (
(tilemap.tiles[i].water_level > 0 && tilemap.tiles[i].water_level < tilemap.tiles->max_water_level)
|| (
(tilemap.tiles[i].water_level == tilemap.tiles->max_water_level)
&& i >= tilemap.width
&& tilemap.tiles[i - tilemap.width].water_level == 0
&& !tilemap.tiles[i - tilemap.width].solid
)
)
{
Vector2 surf_pos = {x, y + (TILE_SIZE - water_height)};
surf_pos = Vector2Subtract(surf_pos, surf_offset);
draw_sprite_pro(surface_spr, 0, surf_pos, 0, false, (Vector2){1,1}, water_colour);
}
} }
} }