Add support for sprite rendering
parent
11549eb324
commit
91f005b4bb
|
@ -142,6 +142,11 @@ typedef struct {
|
||||||
float durability; // 1.0 - 0.0 (0.0 = broken), we can only ever merge items of the same durability
|
float durability; // 1.0 - 0.0 (0.0 = broken), we can only ever merge items of the same durability
|
||||||
} Item;
|
} Item;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int spritesheet;
|
||||||
|
int frame;
|
||||||
|
} Sprite;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char _unused;
|
char _unused;
|
||||||
} BlockHarvest;
|
} BlockHarvest;
|
||||||
|
@ -266,6 +271,7 @@ typedef struct {
|
||||||
X(Creature)\
|
X(Creature)\
|
||||||
X(SeeksFood)\
|
X(SeeksFood)\
|
||||||
X(SeeksCompanion)\
|
X(SeeksCompanion)\
|
||||||
|
X(Sprite)\
|
||||||
X(StreamInfo)
|
X(StreamInfo)
|
||||||
|
|
||||||
#define X(comp) extern ECS_COMPONENT_DECLARE(comp);
|
#define X(comp) extern ECS_COMPONENT_DECLARE(comp);
|
||||||
|
|
|
@ -66,11 +66,10 @@ void TickDownHealDelay(ecs_iter_t *it) {
|
||||||
HealDelay *h = ecs_field(it, HealDelay, 1);
|
HealDelay *h = ecs_field(it, HealDelay, 1);
|
||||||
|
|
||||||
for (int i = 0; i < it->count; i++) {
|
for (int i = 0; i < it->count; i++) {
|
||||||
--h[i].delay;
|
TICK_VAR(h[i].delay);
|
||||||
|
|
||||||
if (h[i].delay == 0) {
|
if (h[i].delay == 0) {
|
||||||
ecs_remove(it->world, it->entities[i], HealDelay);
|
ecs_remove(it->world, it->entities[i], HealDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,13 @@ pkt_desc pkt_entity_view_desc[] = {
|
||||||
{ PKT_UINT(entity_view, asset) },
|
{ PKT_UINT(entity_view, asset) },
|
||||||
{ PKT_UINT(entity_view, progress_active) },
|
{ PKT_UINT(entity_view, progress_active) },
|
||||||
{ PKT_UINT(entity_view, is_producer) },
|
{ PKT_UINT(entity_view, is_producer) },
|
||||||
|
|
||||||
{ PKT_HALF(entity_view, progress_value) },
|
{ PKT_HALF(entity_view, progress_value) },
|
||||||
|
|
||||||
|
{ PKT_KEEP_IF(entity_view, kind, EKIND_SPRITE, 2) },
|
||||||
|
{ PKT_UINT(entity_view, spritesheet) },
|
||||||
|
{ PKT_UINT(entity_view, frame) },
|
||||||
|
|
||||||
{ PKT_KEEP_IF(entity_view, has_items, true, 3) },
|
{ PKT_KEEP_IF(entity_view, has_items, true, 3) },
|
||||||
{ PKT_UINT(entity_view, has_items) },
|
{ PKT_UINT(entity_view, has_items) },
|
||||||
{ PKT_UINT(entity_view, selected_item) },
|
{ PKT_UINT(entity_view, selected_item) },
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
X(EKIND_PLAYER)\
|
X(EKIND_PLAYER)\
|
||||||
X(EKIND_ITEM)\
|
X(EKIND_ITEM)\
|
||||||
X(EKIND_DEVICE)\
|
X(EKIND_DEVICE)\
|
||||||
|
X(EKIND_SPRITE)\
|
||||||
|
X(EKIND_WEAPON)\
|
||||||
X(EKIND_VEHICLE)\
|
X(EKIND_VEHICLE)\
|
||||||
X(EKIND_DEMO_NPC)\
|
X(EKIND_DEMO_NPC)\
|
||||||
X(EKIND_MONSTER)\
|
X(EKIND_MONSTER)\
|
||||||
|
@ -79,6 +81,10 @@ typedef struct entity_view {
|
||||||
uint32_t progress_active;
|
uint32_t progress_active;
|
||||||
float progress_value;
|
float progress_value;
|
||||||
|
|
||||||
|
// sprite index
|
||||||
|
int spritesheet;
|
||||||
|
int frame;
|
||||||
|
|
||||||
// NOTE(zaklaus): inventory
|
// NOTE(zaklaus): inventory
|
||||||
uint8_t has_items;
|
uint8_t has_items;
|
||||||
Item items[ITEMS_INVENTORY_SIZE];
|
Item items[ITEMS_INVENTORY_SIZE];
|
||||||
|
|
|
@ -76,6 +76,12 @@ entity_view* world_build_entity_view(int64_t e) {
|
||||||
view.is_producer = ecs_get(world_ecs(), e, Producer) != 0;
|
view.is_producer = ecs_get(world_ecs(), e, Producer) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ecs_get(world_ecs(), e, Sprite)) {
|
||||||
|
Sprite const* spr = ecs_get(world_ecs(), e, Sprite);
|
||||||
|
view.spritesheet = spr->spritesheet;
|
||||||
|
view.frame = spr->frame;
|
||||||
|
}
|
||||||
|
|
||||||
view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false;
|
view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false;
|
||||||
|
|
||||||
Inventory* inv = 0;
|
Inventory* inv = 0;
|
||||||
|
|
|
@ -69,6 +69,12 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr
|
||||||
Color color = data->veh_kind == 0 ? RED : data->veh_kind == 1 ? GREEN : BLUE;
|
Color color = data->veh_kind == 0 ? RED : data->veh_kind == 1 ? GREEN : BLUE;
|
||||||
DrawRectanglePro((Rectangle){x,y,w,h}, (Vector2){w/2.0f,h/2.0f}, zpl_to_degrees(data->heading), ColorAlpha(color, data->tran_time));
|
DrawRectanglePro((Rectangle){x,y,w,h}, (Vector2){w/2.0f,h/2.0f}, zpl_to_degrees(data->heading), ColorAlpha(color, data->tran_time));
|
||||||
}break;
|
}break;
|
||||||
|
case EKIND_SPRITE:
|
||||||
|
case EKIND_WEAPON: {
|
||||||
|
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));
|
||||||
|
} break;
|
||||||
case EKIND_DEVICE:{
|
case EKIND_DEVICE:{
|
||||||
float x = data->x - 32.f;
|
float x = data->x - 32.f;
|
||||||
float y = data->y - 32.f;
|
float y = data->y - 32.f;
|
||||||
|
|
|
@ -72,6 +72,12 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr
|
||||||
Color color = data->veh_kind == 0 ? RED : data->veh_kind == 1 ? GREEN : BLUE;
|
Color color = data->veh_kind == 0 ? RED : data->veh_kind == 1 ? GREEN : BLUE;
|
||||||
DrawRectanglePro((Rectangle){x,y,w,h}, (Vector2){w/2.0f,h/2.0f}, zpl_to_degrees(data->heading), ColorAlpha(color, data->tran_time));
|
DrawRectanglePro((Rectangle){x,y,w,h}, (Vector2){w/2.0f,h/2.0f}, zpl_to_degrees(data->heading), ColorAlpha(color, data->tran_time));
|
||||||
}break;
|
}break;
|
||||||
|
case EKIND_SPRITE:
|
||||||
|
case EKIND_WEAPON: {
|
||||||
|
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));
|
||||||
|
} break;
|
||||||
case EKIND_DEVICE:{
|
case EKIND_DEVICE:{
|
||||||
Texture2D tex = GetSpriteTexture2D(assets_find(data->asset));
|
Texture2D tex = GetSpriteTexture2D(assets_find(data->asset));
|
||||||
float x = data->x - tex.width/2;
|
float x = data->x - tex.width/2;
|
||||||
|
|
|
@ -57,6 +57,12 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr
|
||||||
Color color = data->veh_kind == 0 ? RED : data->veh_kind == 1 ? GREEN : BLUE;
|
Color color = data->veh_kind == 0 ? RED : data->veh_kind == 1 ? GREEN : BLUE;
|
||||||
DrawRectanglePro((Rectangle){x,y,w,h}, (Vector2){w/2.0f,h/2.0f}, zpl_to_degrees(data->heading), ColorAlpha(color, data->tran_time));
|
DrawRectanglePro((Rectangle){x,y,w,h}, (Vector2){w/2.0f,h/2.0f}, zpl_to_degrees(data->heading), ColorAlpha(color, data->tran_time));
|
||||||
}break;
|
}break;
|
||||||
|
case EKIND_SPRITE:
|
||||||
|
case EKIND_WEAPON: {
|
||||||
|
float x = data->x;
|
||||||
|
float y = data->y;
|
||||||
|
DrawSpriteEco(&main_sprite_sheet, data->frame, x, y, 0.0f, 2.0f, WHITE);
|
||||||
|
} break;
|
||||||
case EKIND_DEVICE:{
|
case EKIND_DEVICE:{
|
||||||
float x = data->x - 32.f;
|
float x = data->x - 32.f;
|
||||||
float y = data->y - 32.f;
|
float y = data->y - 32.f;
|
||||||
|
|
Loading…
Reference in New Issue