custom dim sprites

efd/v1
Dominik Madarász 2022-10-16 01:48:23 +02:00
parent 50967aa046
commit 174e5a0452
17 changed files with 40 additions and 9 deletions

Binary file not shown.

BIN
art/gen/bigtree.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 778 B

After

Width:  |  Height:  |  Size: 824 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
art/gen/furnace.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

After

Width:  |  Height:  |  Size: 278 B

View File

@ -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",

View File

@ -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);

View File

@ -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;
}

View File

@ -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) {

View File

@ -34,6 +34,7 @@ typedef enum {
ASSET_COAL,
ASSET_IRON_ORE,
ASSET_IRON_INGOT,
ASSET_TEST_TALL,
ASSET_BELT,
ASSET_BELT_LEFT,

View File

@ -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),

View File

@ -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),

View File

@ -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,

View File

@ -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})

View File

@ -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);