consider non-collision blocks as ground blocks

efd/v1
Dominik Madarász 2022-10-16 02:13:38 +02:00
parent 671445d4a7
commit 2d09fd90cd
4 changed files with 15 additions and 7 deletions

View File

@ -288,7 +288,13 @@ static void game__world_view_render_push_entry(uint64_t key, entity_view * data)
.blk_id = blk_id,
.x = (data->x*size + offset) + (float)tx*WORLD_BLOCK_SIZE + WORLD_BLOCK_SIZE/2,
.y = (data->y*size + offset) + (float)ty*WORLD_BLOCK_SIZE + WORLD_BLOCK_SIZE/2,
.cy = (data->y*size + offset) + (float)ty*WORLD_BLOCK_SIZE + WORLD_BLOCK_SIZE/2,
};
if (!(blocks_get_flags(blk_id) & BLOCK_FLAG_COLLISION)) {
entry.cy = ZPL_F32_MIN;
}
zpl_array_append(render_queue, entry);
}
}
@ -301,6 +307,7 @@ static void game__world_view_render_push_entry(uint64_t key, entity_view * data)
.data = data,
.x = data->x,
.y = data->y,
.cy = data->y,
.blk_id = 0,
};
zpl_array_append(render_queue, entry);
@ -320,7 +327,7 @@ void game_world_view_render_world(void) {
profile(PROF_RENDER_PUSH_AND_SORT_ENTRIES) {
game_world_view_active_entity_map(game__world_view_render_push_entry);
zpl_sort_array(render_queue, zpl_array_count(render_queue), zpl_f32_cmp(zpl_offset_of(game_world_render_entry, y)));
zpl_sort_array(render_queue, zpl_array_count(render_queue), zpl_f32_cmp(zpl_offset_of(game_world_render_entry, cy)));
}
game_world_view_active_entity_map(game__world_view_render_ground);

View File

@ -114,7 +114,7 @@ void buildmode_draw(void) {
for (size_t i = 0; i < build_num_placements; i++) {
item_placement *it = &build_placements[i];
renderer_draw_single(it->x, it->y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(build_is_deletion_mode ? RED : WHITE, 0.4f));
renderer_draw_single(it->x, it->y, !build_is_deletion_mode ? item->kind : ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(build_is_deletion_mode ? RED : WHITE, 0.4f));
}
if (build_is_in_draw_mode) {

View File

@ -9,6 +9,7 @@ typedef struct {
entity_view *data;
float x;
float y;
float cy;
block_id blk_id;
} game_world_render_entry;

View File

@ -250,13 +250,13 @@ void renderer_debug_draw(void) {
EndMode2D();
}
void renderer_draw_single(float x, float y, asset_id id, Color color) {
void renderer_draw_single(float x1, float y1, asset_id id, Color color) {
BeginMode2D(render_camera);
x -= 32.0f;
y -= 32.0f;
DrawTexturePro(GetSpriteTexture2D(assets_find(id)), ASSET_SRC_RECT(), ASSET_DST_RECT(x,y), (Vector2){0.5f,0.5f}, 0.0f, color);
Texture2D tex = GetSpriteTexture2D(assets_find(id));
float x = x1 - tex.width/2;
float y = y1 - (tex.height-WORLD_BLOCK_SIZE/2);
DrawTexturePro(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), ASSET_DST_RECT_TEX(x,y, tex.width, tex.height), (Vector2){0.5f,0.5f}, 0.0f, color);
EndMode2D();
}