diff --git a/code/foundation/src/core/game.c b/code/foundation/src/core/game.c index 3b87d6f..e6b922d 100644 --- a/code/foundation/src/core/game.c +++ b/code/foundation/src/core/game.c @@ -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); diff --git a/code/foundation/src/gui/build_mode.c b/code/foundation/src/gui/build_mode.c index f3db38a..dd3f960 100644 --- a/code/foundation/src/gui/build_mode.c +++ b/code/foundation/src/gui/build_mode.c @@ -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) { diff --git a/code/foundation/src/platform/renderer.h b/code/foundation/src/platform/renderer.h index 5ba3db3..d87e6b6 100644 --- a/code/foundation/src/platform/renderer.h +++ b/code/foundation/src/platform/renderer.h @@ -9,6 +9,7 @@ typedef struct { entity_view *data; float x; float y; + float cy; block_id blk_id; } game_world_render_entry; diff --git a/code/games/sandbox/src/renderer.c b/code/games/sandbox/src/renderer.c index 8c8095e..62ba5c0 100644 --- a/code/games/sandbox/src/renderer.c +++ b/code/games/sandbox/src/renderer.c @@ -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(); }