diff --git a/art/furnace.aseprite b/art/furnace.aseprite new file mode 100644 index 0000000..ac4b914 Binary files /dev/null and b/art/furnace.aseprite differ diff --git a/art/gen/bigtree.png b/art/gen/bigtree.png new file mode 100644 index 0000000..b436c49 Binary files /dev/null and b/art/gen/bigtree.png differ diff --git a/art/gen/coal.png b/art/gen/coal.png index 5b3fde8..18e8cec 100644 Binary files a/art/gen/coal.png and b/art/gen/coal.png differ diff --git a/art/gen/furnace-export.png b/art/gen/furnace-export.png new file mode 100644 index 0000000..7a35a1c Binary files /dev/null and b/art/gen/furnace-export.png differ diff --git a/art/gen/furnace.png b/art/gen/furnace.png new file mode 100644 index 0000000..936446a Binary files /dev/null and b/art/gen/furnace.png differ diff --git a/art/gen/test-tall.png b/art/gen/test-tall.png new file mode 100644 index 0000000..da05aea Binary files /dev/null and b/art/gen/test-tall.png differ diff --git a/art/gen/wood.png b/art/gen/wood.png index 9dc833e..52dfd80 100644 Binary files a/art/gen/wood.png and b/art/gen/wood.png differ diff --git a/code/foundation/src/debug/debug_ui.c b/code/foundation/src/debug/debug_ui.c index a6c934e..1d78554 100644 --- a/code/foundation/src/debug/debug_ui.c +++ b/code/foundation/src/debug/debug_ui.c @@ -143,6 +143,7 @@ static debug_item items[] = { { .kind = DITEM_BUTTON, .name = "spawn furnace", .on_click = ActSpawnFurnace }, { .kind = DITEM_BUTTON, .name = "spawn demo blueprint", .on_click = ActSpawnDemoHouseItem }, { .kind = DITEM_BUTTON, .name = "spawn random durability icemaker", .on_click = ActSpawnDurabilityTest }, + { .kind = DITEM_BUTTON, .name = "spawn sprite tall test", .on_click = ActSpawnTallTest }, { .kind = DITEM_LIST, .name = "demo npcs", diff --git a/code/foundation/src/debug/debug_ui_actions.c b/code/foundation/src/debug/debug_ui_actions.c index a4543dd..a0b061b 100644 --- a/code/foundation/src/debug/debug_ui_actions.c +++ b/code/foundation/src/debug/debug_ui_actions.c @@ -85,6 +85,17 @@ ActSpawnFurnace(void) { entity_set_position(e, dest->x, dest->y); } +void +ActSpawnTallTest(void) { + ecs_entity_t e = item_spawn(ASSET_TEST_TALL, 32); + ecs_entity_t plr = camera_get().ent_id; + + Position const* origin = ecs_get(world_ecs(), plr, Position); + Position * dest = ecs_get_mut(world_ecs(), e, Position); + *dest = *origin; + entity_set_position(e, dest->x, dest->y); +} + void ActSpawnDemoHouseItem(void) { ecs_entity_t e = item_spawn(ASSET_BLUEPRINT, 1); diff --git a/code/foundation/src/gen/texgen_fallback.c b/code/foundation/src/gen/texgen_fallback.c index 5615ea7..e0c7e99 100644 --- a/code/foundation/src/gen/texgen_fallback.c +++ b/code/foundation/src/gen/texgen_fallback.c @@ -35,7 +35,8 @@ Texture2D texgen_build_sprite_fallback(asset_id id) { case ASSET_HILL: return LoadTexEco("rock"); case ASSET_LAVA: return LoadTexEco("lava"); case ASSET_WOOD: return LoadTexEco("wood"); - case ASSET_TREE: return LoadTexEco("tree"); + case ASSET_TREE: return LoadTexEco("bigtree"); + case ASSET_TEST_TALL: return LoadTexEco("test-tall"); // case ASSET_WATER: return LoadTexEco("water"); case ASSET_BELT: @@ -46,6 +47,7 @@ Texture2D texgen_build_sprite_fallback(asset_id id) { // NOTE(zaklaus): devices case ASSET_CHEST: return LoadTexEco("chest"); + case ASSET_FURNACE: return LoadTexEco("furnace-export"); default: return GenColorEco(PINK); break; } diff --git a/code/foundation/src/gui/inventory.c b/code/foundation/src/gui/inventory.c index ab06325..ee60153 100644 --- a/code/foundation/src/gui/inventory.c +++ b/code/foundation/src/gui/inventory.c @@ -116,7 +116,10 @@ void inventory_render_held_item(bool is_player){ Vector2 mpos = GetMousePosition(); mpos.x -= 32; mpos.y -= 32; - DrawTexturePro(GetSpriteTexture2D(assets_find(inv->held_item.kind)), ASSET_SRC_RECT(), ASSET_DST_RECT(mpos.x, mpos.y), (Vector2){0.5f,0.5f}, 0.0f, ColorAlpha(WHITE, 0.8f)); + Texture2D tex = GetSpriteTexture2D(assets_find(inv->held_item.kind)); + float aspect = tex.width/(float)tex.height; + float size = WORLD_BLOCK_SIZE * aspect; + DrawTexturePro(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), ASSET_DST_RECT_TEX(mpos.x, mpos.y, size, WORLD_BLOCK_SIZE), (Vector2){0.5f,0.5f}, 0.0f, ColorAlpha(WHITE, 0.8f)); DrawTextEco(zpl_bprintf("%d", inv->held_item.quantity), mpos.x, mpos.y, 16, RAYWHITE, 0.0f); if (!inv->is_inside && IsMouseButtonReleased(MOUSE_LEFT_BUTTON) && !inv2->is_inside) { diff --git a/code/foundation/src/lists/assets_ids.h b/code/foundation/src/lists/assets_ids.h index 51b54cb..91d00cc 100644 --- a/code/foundation/src/lists/assets_ids.h +++ b/code/foundation/src/lists/assets_ids.h @@ -34,6 +34,7 @@ typedef enum { ASSET_COAL, ASSET_IRON_ORE, ASSET_IRON_INGOT, + ASSET_TEST_TALL, ASSET_BELT, ASSET_BELT_LEFT, diff --git a/code/foundation/src/lists/assets_list.c b/code/foundation/src/lists/assets_list.c index 5b6faa5..56bf4d9 100644 --- a/code/foundation/src/lists/assets_list.c +++ b/code/foundation/src/lists/assets_list.c @@ -32,6 +32,7 @@ static asset assets[] = { ASSET_TEX(ASSET_HILL_SNOW), ASSET_TEX(ASSET_HOLE), ASSET_TEX(ASSET_WOOD), + ASSET_TEX(ASSET_TEST_TALL), ASSET_TEX(ASSET_TREE), ASSET_TEX(ASSET_BELT), diff --git a/code/foundation/src/lists/blocks_list.c b/code/foundation/src/lists/blocks_list.c index 4de963f..cedacf9 100644 --- a/code/foundation/src/lists/blocks_list.c +++ b/code/foundation/src/lists/blocks_list.c @@ -19,6 +19,7 @@ static block blocks[] = { BLOCK(ASSET_TREE, BLOCK_FLAG_COLLISION|BLOCK_FLAG_DESTROY_ON_COLLISION, '@', .drag = 1.0f , .friction = 1.0f, .bounce = 0.0f), BLOCK(ASSET_CHEST, BLOCK_FLAG_ENTITY, 'C'), BLOCK(ASSET_FURNACE, BLOCK_FLAG_ENTITY, 'F'), + BLOCK(ASSET_TEST_TALL, BLOCK_FLAG_COLLISION, '.'), BLOCK(ASSET_BELT_LEFT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = -150.0f), BLOCK(ASSET_BELT_RIGHT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = 150.0f), diff --git a/code/foundation/src/lists/items_list.c b/code/foundation/src/lists/items_list.c index 876aa20..0dd0c3a 100644 --- a/code/foundation/src/lists/items_list.c +++ b/code/foundation/src/lists/items_list.c @@ -8,6 +8,7 @@ static item_desc items[] = { ITEM_SELF(ASSET_FENCE, 64), ITEM_ENERGY(ASSET_WOOD, ASSET_FURNACE, 64, 15.0f), ITEM_HOLD(ASSET_TREE, 64), + ITEM_SELF(ASSET_TEST_TALL, 64), // ITEM_BLUEPRINT(ASSET_BLUEPRINT, 1, 4, 4, "]]]]]CF] ]]]]]"), ITEM_BLUEPRINT(ASSET_BLUEPRINT, 1, 4, 4, PROT({ ASSET_WOOD,ASSET_WOOD,ASSET_WOOD,ASSET_WOOD, diff --git a/code/foundation/src/models/assets.h b/code/foundation/src/models/assets.h index 03115fd..63aba06 100644 --- a/code/foundation/src/models/assets.h +++ b/code/foundation/src/models/assets.h @@ -24,3 +24,5 @@ void *assets_get_tex(uint16_t id); // NOTE(zaklaus): client only #define ASSET_SRC_RECT() ((Rectangle){0, 0, 64, 64}) #define ASSET_DST_RECT(x,y) ((Rectangle){x, y, 64, 64}) +#define ASSET_SRC_RECT_TEX(w,h) ((Rectangle){0, 0, (float)w, (float)h}) +#define ASSET_DST_RECT_TEX(x,y,w,h) ((Rectangle){x, y, (float)w, (float)h}) diff --git a/code/games/sandbox/src/renderer.c b/code/games/sandbox/src/renderer.c index a152377..2ccffc2 100644 --- a/code/games/sandbox/src/renderer.c +++ b/code/games/sandbox/src/renderer.c @@ -60,7 +60,8 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr tex.texture.height *= (int32_t)scale; DrawTextureRec(tex.texture, (Rectangle){0, 0, size, -size}, (Vector2){x, y}, ColorAlpha(WHITE, data->tran_time)); } else { - DrawTextureRec(GetBlockImage(entry->blk_id), ASSET_SRC_RECT(), (Vector2){entry->x-(WORLD_BLOCK_SIZE/2), entry->y-(WORLD_BLOCK_SIZE/2)}, ColorAlpha(WHITE, data->tran_time)); + Texture2D tex = GetBlockImage(entry->blk_id); + DrawTextureRec(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), (Vector2){entry->x-tex.width/2.0f, entry->y-(tex.height-WORLD_BLOCK_SIZE/2)}, ColorAlpha(WHITE, data->tran_time)); } }break; case EKIND_VEHICLE: { @@ -72,16 +73,17 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr DrawRectanglePro((Rectangle){x,y,w,h}, (Vector2){w/2.0f,h/2.0f}, zpl_to_degrees(data->heading), ColorAlpha(color, data->tran_time)); }break; case EKIND_DEVICE:{ - float x = data->x - 32.f; - float y = data->y - 32.f; - DrawTexturePro(GetSpriteTexture2D(assets_find(data->asset)), ASSET_SRC_RECT(), ASSET_DST_RECT(x,y), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE)); + Texture2D tex = GetSpriteTexture2D(assets_find(data->asset)); + float x = data->x - tex.width/2; + float y = data->y - (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, ALPHA(WHITE)); if (data->progress_active) { float w = 64.f; float h = 8.f; float p = data->progress_value; float x = data->x - w/2.f; - float y = data->y - 32.f - h; + float y = data->y - (tex.height-WORLD_BLOCK_SIZE/2) - h; DrawRectangleEco(x, y, w, h, ColorAlpha(BLACK, data->tran_time)); DrawRectangleEco(x, y, w*p, h, ColorAlpha(GREEN, data->tran_time)); } @@ -115,7 +117,10 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr if (data->items[data->selected_item].quantity > 0) { asset_id it_kind = data->items[data->selected_item].kind; uint32_t qty = data->items[data->selected_item].quantity; - DrawTexturePro(GetSpriteTexture2D(assets_find(it_kind)), ASSET_SRC_RECT(), ((Rectangle){ix, iy, 32, 32}), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE)); + Texture2D tex = GetSpriteTexture2D(assets_find(it_kind)); + float aspect = tex.width/(float)tex.height; + float size = WORLD_BLOCK_SIZE/2.0f * aspect; + DrawTexturePro(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), ((Rectangle){ix, iy, size, WORLD_BLOCK_SIZE/2.0f}), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE)); if (!inv_is_open) DrawTextEco(zpl_bprintf("%d", qty), x+24, y+24, 8, RAYWHITE, 0.0f); @@ -135,7 +140,10 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr case EKIND_ITEM: { float x = data->x - 32.f; float y = data->y - 32.f; - DrawTexturePro(GetSpriteTexture2D(assets_find(data->asset)), ASSET_SRC_RECT(), ASSET_DST_RECT(x,y), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE)); + Texture2D tex = GetSpriteTexture2D(assets_find(data->asset)); + float aspect = tex.width/(float)tex.height; + float size = WORLD_BLOCK_SIZE/2.0f * aspect; + DrawTexturePro(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), ASSET_DST_RECT_TEX(x,y,size,WORLD_BLOCK_SIZE/2.0f), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE)); if (data->quantity > 1) { DrawTextEco(zpl_bprintf("%d", data->quantity), x, y, 10, ALPHA(RAYWHITE), 0.0f);