Update rendering for editor scene
Internal Changelog: - Add background - Update grid and bbox drawingmain
parent
f20daa9cce
commit
2c908ffd46
|
@ -160,10 +160,12 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
#endif
|
||||
CAirTimer_t* p_air = get_component(p_ent, CAIRTIMER_T);
|
||||
|
||||
Vector2 air_pos = {game_rec.x + game_rec.width - 16, game_rec.y + game_rec.height - 16};
|
||||
Sprite_t* spr = get_sprite(&scene->engine->assets, "p_bigbubble");
|
||||
Vector2 air_pos = {game_rec.x + game_rec.width - 32, game_rec.y + game_rec.height - 32};
|
||||
for (uint8_t i = 0; i < p_air->curr_count; i++)
|
||||
{
|
||||
DrawCircleV(air_pos, 16, BLUE);
|
||||
draw_sprite(spr, 0, air_pos, 0, false);
|
||||
//DrawCircleV(air_pos, 16, BLUE);
|
||||
air_pos.x -= 32;
|
||||
}
|
||||
}
|
||||
|
@ -208,92 +210,20 @@ static void render_editor_game_scene(Scene_t* scene)
|
|||
max.x = (int)fmin(tilemap.width, max.x + 1);
|
||||
max.y = (int)fmin(tilemap.height, max.y + 1);
|
||||
|
||||
Texture2D* bg = get_texture(&scene->engine->assets, "bg_tex");
|
||||
BeginTextureMode(scene->layers.render_layers[GAME_LAYER].layer_tex);
|
||||
ClearBackground(WHITE);
|
||||
BeginMode2D(data->camera.cam);
|
||||
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].moveable)
|
||||
//{
|
||||
// // Draw water tile
|
||||
// Color water_colour = ColorAlpha(RED, 0.2);
|
||||
// DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour);
|
||||
//}
|
||||
|
||||
uint8_t tile_sprite_idx = tilemap.tiles[i].tile_type + tilemap.tiles[i].rotation;
|
||||
if (data->tile_sprites[tile_sprite_idx] != NULL)
|
||||
{
|
||||
draw_sprite(data->tile_sprites[tile_sprite_idx], 0, (Vector2){x,y}, 0.0f, false);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == SOLID_TILE)
|
||||
{
|
||||
draw_sprite(
|
||||
data->solid_tile_sprites, CONNECTIVITY_TILE_MAPPING[tilemap.tiles[i].connectivity],
|
||||
(Vector2){x,y}, 0.0f, false
|
||||
float rect_x = data->camera.target_pos.x;
|
||||
DrawTexturePro(*bg,
|
||||
//(Rectangle){0,0,64,64},
|
||||
(Rectangle){0,0,(tilemap.width+1)*tilemap.tile_size*2, (tilemap.height+1)*tilemap.tile_size*2},
|
||||
(Rectangle){-rect_x / 4,0,(tilemap.width+1)*tilemap.tile_size*2, (tilemap.height+1)*tilemap.tile_size*2},
|
||||
//(Rectangle){0,0,game_rec.width, game_rec.height},
|
||||
(Vector2){0,0}, 0.0f, WHITE
|
||||
);
|
||||
//sprintf(buffer, "%u", tilemap.tiles[i].connectivity);
|
||||
//DrawText(buffer, x + tilemap.tile_size / 2, y + tilemap.tile_size / 2, 12, WHITE);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == ONEWAY_TILE)
|
||||
{
|
||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == LADDER)
|
||||
{
|
||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, ORANGE);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == SPIKES)
|
||||
{
|
||||
DrawRectangle(
|
||||
x + tilemap.tiles[i].offset.x, y + tilemap.tiles[i].offset.y,
|
||||
tilemap.tiles[i].size.x, tilemap.tiles[i].size.y, RED
|
||||
);
|
||||
}
|
||||
if (tilemap.tiles[i].wet)
|
||||
{
|
||||
#define SURFACE_THICKNESS 4
|
||||
int up = i - tilemap.width;
|
||||
unsigned int bot = i + tilemap.width;
|
||||
int right = i + 1;
|
||||
int left = i - 1;
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
bot <= tilemap.n_tiles
|
||||
&& tilemap.tiles[i].water_level == 0
|
||||
)
|
||||
{
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tilemap.tiles[i].max_water_level < MAX_WATER_LEVEL)
|
||||
{
|
||||
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, ColorAlpha(BLUE, 0.5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char buffer[64] = {0};
|
||||
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
||||
{
|
||||
|
@ -315,6 +245,8 @@ static void render_editor_game_scene(Scene_t* scene)
|
|||
|| p_ent->position.y > max.y * tilemap.tile_size
|
||||
) continue;
|
||||
|
||||
if (data->show_grid)
|
||||
{
|
||||
Color colour;
|
||||
switch(p_ent->m_tag)
|
||||
{
|
||||
|
@ -427,6 +359,8 @@ static void render_editor_game_scene(Scene_t* scene)
|
|||
};
|
||||
DrawRectangleLinesEx(rec, 1.5, PURPLE);
|
||||
}
|
||||
}
|
||||
|
||||
CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
|
||||
if (p_cspr != NULL)
|
||||
{
|
||||
|
@ -460,6 +394,89 @@ static void render_editor_game_scene(Scene_t* scene)
|
|||
DrawCircleV(p_ent->position, tilemap.tile_size >> 1, (data->coins.current < data->coins.total)? RED : GREEN);
|
||||
}
|
||||
|
||||
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].moveable)
|
||||
//{
|
||||
// // Draw water tile
|
||||
// Color water_colour = ColorAlpha(RED, 0.2);
|
||||
// DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour);
|
||||
//}
|
||||
|
||||
uint8_t tile_sprite_idx = tilemap.tiles[i].tile_type + tilemap.tiles[i].rotation;
|
||||
if (data->tile_sprites[tile_sprite_idx] != NULL)
|
||||
{
|
||||
draw_sprite(data->tile_sprites[tile_sprite_idx], 0, (Vector2){x,y}, 0.0f, false);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == SOLID_TILE)
|
||||
{
|
||||
draw_sprite(
|
||||
data->solid_tile_sprites, CONNECTIVITY_TILE_MAPPING[tilemap.tiles[i].connectivity],
|
||||
(Vector2){x,y}, 0.0f, false
|
||||
);
|
||||
//sprintf(buffer, "%u", tilemap.tiles[i].connectivity);
|
||||
//DrawText(buffer, x + tilemap.tile_size / 2, y + tilemap.tile_size / 2, 12, WHITE);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == ONEWAY_TILE)
|
||||
{
|
||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == LADDER)
|
||||
{
|
||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, ORANGE);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == SPIKES)
|
||||
{
|
||||
DrawRectangle(
|
||||
x + tilemap.tiles[i].offset.x, y + tilemap.tiles[i].offset.y,
|
||||
tilemap.tiles[i].size.x, tilemap.tiles[i].size.y, RED
|
||||
);
|
||||
}
|
||||
if (tilemap.tiles[i].wet)
|
||||
{
|
||||
#define SURFACE_THICKNESS 4
|
||||
int up = i - tilemap.width;
|
||||
unsigned int bot = i + tilemap.width;
|
||||
int right = i + 1;
|
||||
int left = i - 1;
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
bot <= tilemap.n_tiles
|
||||
&& tilemap.tiles[i].water_level == 0
|
||||
)
|
||||
{
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tilemap.tiles[i].max_water_level < MAX_WATER_LEVEL)
|
||||
{
|
||||
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, ColorAlpha(BLUE, 0.5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
draw_particle_system(&scene->part_sys);
|
||||
|
||||
// Draw water tile
|
||||
|
@ -505,15 +522,15 @@ static void render_editor_game_scene(Scene_t* scene)
|
|||
|
||||
sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set));
|
||||
|
||||
if (tilemap.tiles[i].solid > 0)
|
||||
//if (tilemap.tiles[i].solid > 0)
|
||||
{
|
||||
DrawText(buffer, x, y, 10, WHITE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw water tile
|
||||
DrawText(buffer, x, y, 10, BLACK);
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// // Draw water tile
|
||||
// DrawText(buffer, x, y, 10, BLACK);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -521,12 +538,12 @@ static void render_editor_game_scene(Scene_t* scene)
|
|||
for (size_t i = min.x; i < max.x; ++i)
|
||||
{
|
||||
int x = (i+1)*TILE_SIZE;
|
||||
DrawLine(x, 0, x, tilemap.height * TILE_SIZE, BLACK);
|
||||
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, BLACK);
|
||||
DrawLine(0, y, tilemap.width * TILE_SIZE, y, WHITE);
|
||||
}
|
||||
}
|
||||
EndMode2D();
|
||||
|
@ -1043,6 +1060,8 @@ void init_sandbox_scene(LevelScene_t* scene)
|
|||
scene->data.tile_sprites[SPIKES + TILE_180ROT] = get_sprite(&scene->scene.engine->assets, "u_spikes");
|
||||
scene->data.selected_solid_tilemap = 0;
|
||||
scene->data.solid_tile_sprites = get_sprite(&scene->scene.engine->assets, SOLID_TILE_SELECTIONS[0]);
|
||||
Texture2D* tex = get_texture(&scene->scene.engine->assets, "bg_tex");
|
||||
SetTextureWrap(*tex, TEXTURE_WRAP_REPEAT);
|
||||
|
||||
for (size_t i = 0; i < scene->data.tilemap.width; ++i)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue