Make water look slightly better in editor

- Render water in a separate layer
- Reorder editor layers
main
En Yi 2025-09-02 20:54:58 +08:00
parent f1cbfbd4b1
commit e85dc42f3e
2 changed files with 85 additions and 77 deletions

View File

@ -54,9 +54,10 @@ static Vector2 urchin_click_pos = {0,0};
#define SELECTION_REGION_WIDTH (SELECTION_TILE_SIZE * MAX_SPAWN_TYPE)
#define SELECTION_REGION_HEIGHT SELECTION_TILE_SIZE
#define GAME_LAYER 2
#define WATER_LAYER 2
#define GAME_LAYER 1
#define SELECTION_LAYER 0
#define CONTROL_LAYER 1
#define CONTROL_LAYER 3
#define N_SOLID_TILESETS 4
static const char* SOLID_TILE_SELECTIONS[N_SOLID_TILESETS] = {
@ -133,7 +134,7 @@ static void level_scene_render_func(Scene_t* scene)
ClearBackground(BLANK);
if (data->camera.mode == CAMERA_RANGED_MOVEMENT)
{
DrawRectangle(game_rec.x - 3, game_rec.y - 3, game_rec.width + 6, game_rec.height + 6, RED);
DrawRectangleLinesEx((Rectangle){game_rec.x - 3, game_rec.y - 3, game_rec.width + 6, game_rec.height + 6}, 3, RED);
}
DrawRectangleLines(
@ -273,6 +274,20 @@ static void level_scene_render_func(Scene_t* scene)
gui_y += 330;
sprintf(buffer, "Chests: %u / %u", data->coins.current, data->coins.total);
DrawText(buffer, gui_x, gui_y, 24, BLACK);
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_ent)
{
CAirTimer_t* p_air = get_component(p_ent, CAIRTIMER_T);
Sprite_t* spr = get_sprite(&scene->engine->assets, "p_bigbubble");
Vector2 air_pos = {data->game_rec.width - 32, data->game_rec.height - 32};
for (uint8_t i = 0; i < p_air->curr_count; i++)
{
draw_sprite(spr, 0, air_pos, 0, false);
//DrawCircleV(air_pos, 16, BLUE);
air_pos.x -= 32;
}
}
EndTextureMode();
}
@ -349,7 +364,7 @@ static void render_editor_game_scene(Scene_t* scene)
Texture2D* bg = get_texture(&scene->engine->assets, "bg_tex");
BeginTextureMode(scene->layers.render_layers[GAME_LAYER].layer_tex);
ClearBackground(WHITE);
ClearBackground(DARKGRAY);
DrawTexturePro(*bg,
//(Rectangle){0,0,64,64},
(Rectangle){min.x,0,(tilemap.width+1)*tilemap.tile_size*2, (tilemap.height+1)*tilemap.tile_size*2},
@ -539,8 +554,6 @@ static void render_editor_game_scene(Scene_t* scene)
}
}
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++)
@ -579,10 +592,62 @@ static void render_editor_game_scene(Scene_t* scene)
);
}
}
}
}
draw_particle_system(&scene->part_sys);
if (data->show_grid)
{
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;
int x = tile_x * TILE_SIZE;
int y = tile_y * TILE_SIZE;
sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set));
{
DrawText(buffer, x, y, 10, WHITE);
}
}
}
// Draw tile grid
for (size_t i = min.x; i < max.x; ++i)
{
int x = (i+1)*TILE_SIZE;
DrawLine(x, 0, x, tilemap.height * TILE_SIZE, WHITE);
}
for (size_t i = min.y; i < max.y;++i)
{
int y = (i+1)*TILE_SIZE;
DrawLine(0, y, tilemap.width * TILE_SIZE, y, WHITE);
}
}
EndMode2D();
EndTextureMode();
const Color water_colour = ColorAlpha(BLUE, data->show_grid ? 0.8f : 1.0f);
BeginTextureMode(scene->layers.render_layers[WATER_LAYER].layer_tex);
ClearBackground(BLANK);
BeginMode2D(data->camera.cam);
// Draw water tile
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];
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;
int x = tile_x * TILE_SIZE;
int y = tile_y * TILE_SIZE;
if (tilemap.tiles[i].wet)
{
#define SURFACE_THICKNESS 4
#define SURFACE_THICKNESS 2
int up = i - tilemap.width;
unsigned int bot = i + tilemap.width;
int right = i + 1;
@ -610,25 +675,11 @@ static void render_editor_game_scene(Scene_t* scene)
}
}
if (tilemap.tiles[i].max_water_level < MAX_WATER_LEVEL)
if (tilemap.tiles[i].max_water_level == 0)
{
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, water_colour);
}
}
}
draw_particle_system(&scene->part_sys);
// Draw water tile
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];
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;
int x = tile_x * TILE_SIZE;
int y = tile_y * TILE_SIZE;
uint32_t water_height = tilemap.tiles[i].water_level * WATER_BBOX_STEP;
DrawRectangle(
@ -660,57 +711,7 @@ static void render_editor_game_scene(Scene_t* scene)
}
}
}
if (data->show_grid)
{
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;
int x = tile_x * TILE_SIZE;
int y = tile_y * TILE_SIZE;
sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set));
//if (tilemap.tiles[i].solid > 0)
{
DrawText(buffer, x, y, 10, WHITE);
}
//else
//{
// // Draw water tile
// DrawText(buffer, x, y, 10, BLACK);
//}
}
}
// Draw tile grid
for (size_t i = min.x; i < max.x; ++i)
{
int x = (i+1)*TILE_SIZE;
DrawLine(x, 0, x, tilemap.height * TILE_SIZE, WHITE);
}
for (size_t i = min.y; i < max.y;++i)
{
int y = (i+1)*TILE_SIZE;
DrawLine(0, y, tilemap.width * TILE_SIZE, y, WHITE);
}
}
EndMode2D();
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_ent)
{
CAirTimer_t* p_air = get_component(p_ent, CAIRTIMER_T);
Sprite_t* spr = get_sprite(&scene->engine->assets, "p_bigbubble");
Vector2 air_pos = {data->game_rec.width - 32, data->game_rec.height - 32};
for (uint8_t i = 0; i < p_air->curr_count; i++)
{
draw_sprite(spr, 0, air_pos, 0, false);
//DrawCircleV(air_pos, 16, BLUE);
air_pos.x -= 32;
}
}
EndTextureMode();
}
@ -895,6 +896,7 @@ static void toggle_block_system(Scene_t* scene, ActionType_t action, bool presse
{
change_a_tile(&tilemap, tile_idx, EMPTY_TILE);
tilemap.tiles[tile_idx].water_level = 0;
tilemap.tiles[tile_idx].max_water_level = MAX_WATER_LEVEL;
Entity_t* ent;
unsigned int m_id;
@ -1319,6 +1321,15 @@ void init_sandbox_scene(LevelScene_t* scene)
SELECTION_REGION_WIDTH, SELECTION_REGION_HEIGHT
}
);
add_scene_layer(
&scene->scene, scene->data.game_rec.width, scene->data.game_rec.height,
scene->data.game_rec
);
add_scene_layer(
&scene->scene, scene->data.game_rec.width, scene->data.game_rec.height,
scene->data.game_rec
);
add_scene_layer(
&scene->scene, scene->scene.engine->intended_window_size.x,
scene->scene.engine->intended_window_size.y,
@ -1328,10 +1339,7 @@ void init_sandbox_scene(LevelScene_t* scene)
scene->scene.engine->intended_window_size.y
}
);
add_scene_layer(
&scene->scene, scene->data.game_rec.width, scene->data.game_rec.height,
scene->data.game_rec
);
scene->scene.layers.render_layers[WATER_LAYER].alpha = 0.5;
{
Entity_t* p_player = create_player(&scene->scene.ent_manager);

View File

@ -41,7 +41,7 @@ void init_level_scene_data(LevelSceneData_t* data, uint32_t max_tiles, Tile_t* t
data->tilemap.tiles[i].tile_type = EMPTY_TILE;
data->tilemap.tiles[i].rotation = TILE_NOROTATE;
data->tilemap.tiles[i].moveable = true;
data->tilemap.tiles[i].max_water_level = 4;
data->tilemap.tiles[i].max_water_level = MAX_WATER_LEVEL;
sc_map_init_64v(&data->tilemap.tiles[i].entities_set, 16, 0);
data->tilemap.tiles[i].size = (Vector2){TILE_SIZE, TILE_SIZE};
}