Add water surface sprite rendering to main game

main
En Yi 2025-09-01 16:44:34 +08:00
parent bbcef9124b
commit 0d2753d505
1 changed files with 32 additions and 9 deletions

View File

@ -208,13 +208,13 @@ static void render_regular_game_scene(Scene_t* scene)
}
// Queue Sprite rendering
unsigned int ent_idx;
CSprite_t* p_cspr;
sc_map_foreach(&scene->ent_manager.component_map[CSPRITE_T], ent_idx, p_cspr)
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
{
Entity_t* p_ent = get_entity(&scene->ent_manager, ent_idx);
if (!p_ent->m_alive) continue;
CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
if (p_cspr == NULL) continue;
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
if (spr.sprite == NULL) continue;
@ -437,12 +437,15 @@ static void render_regular_game_scene(Scene_t* scene)
// Particle effect will always be in front of everything except water
draw_particle_system(&scene->part_sys);
CSprite_t* water_surface_spr = get_component_wtih_id(CSPRITE_T, data->water_surface_spr_cidx);
const SpriteRenderInfo_t surface_spr = water_surface_spr->sprites[water_surface_spr->current_idx];
// Render water
const Color water_colour = ColorAlpha(BLUE, 0.5);
for (int tile_y = min.y; tile_y < max.y; tile_y++)
{
for (int tile_x = min.x; tile_x < max.x; tile_x++)
{
int i = tile_x + tile_y * tilemap.width;
unsigned int i = tile_x + tile_y * tilemap.width;
if (!tilemap.tiles[i].wet && tilemap.tiles[i].water_level == 0) {
continue;
}
@ -459,7 +462,7 @@ static void render_regular_game_scene(Scene_t* scene)
int bot_line = y + TILE_SIZE - tilemap.tiles[i].water_level * WATER_BBOX_STEP - SURFACE_THICKNESS / 2;
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);
}
if (
@ -469,11 +472,11 @@ static void render_regular_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))
{
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))
{
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);
}
}
@ -483,7 +486,6 @@ static void render_regular_game_scene(Scene_t* scene)
//}
uint32_t water_height = tilemap.tiles[i].water_level * WATER_BBOX_STEP;
Color water_colour = ColorAlpha(BLUE, 0.5);
DrawRectangle(
x,
y + (TILE_SIZE - water_height),
@ -491,6 +493,27 @@ static void render_regular_game_scene(Scene_t* scene)
water_height,
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,
get_anchor_offset(surface_spr.sprite->frame_size, AP_BOT_LEFT, false)
);
draw_sprite_pro(surface_spr.sprite, water_surface_spr->current_frame, surf_pos, 0, false, (Vector2){1,1}, water_colour);
}
}
}
EndMode2D();