From e0681e6f70b62c62f8941c97e876394e573d96a4 Mon Sep 17 00:00:00 2001 From: doyle Date: Sun, 22 Oct 2023 17:24:40 +1100 Subject: [PATCH] fp: Draw a shadow on terry/perry --- Data/Textures/atlas.png | 4 +- Data/Textures/atlas.txt | 4 +- Data/Textures/atlas/shadow_long_circle.png | 4 +- Data/Textures/atlas/shadow_tight_circle.png | 4 +- feely_pona.cpp | 18 +++- feely_pona_entity.cpp | 93 ++++++++++++++++++--- feely_pona_entity.h | 1 + feely_pona_entity_create.cpp | 1 + feely_pona_game.h | 1 + 9 files changed, 111 insertions(+), 19 deletions(-) diff --git a/Data/Textures/atlas.png b/Data/Textures/atlas.png index b68c307..1fa157b 100644 --- a/Data/Textures/atlas.png +++ b/Data/Textures/atlas.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1123b9d2d9202ce98919e445fc4aab7ae821ebe16485e24c0d3695cc875cc503 -size 15439150 +oid sha256:5e37949880028de417355bb2b2cfba5d62996ead8a3518ed3b4a9583c274b481 +size 15251464 diff --git a/Data/Textures/atlas.txt b/Data/Textures/atlas.txt index 8227dc7..b4b1269 100644 --- a/Data/Textures/atlas.txt +++ b/Data/Textures/atlas.txt @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:60ef08c75c9f5a877e887ab4ea723859e5283fe57343fe86fa31218d73ee54fa -size 14169 +oid sha256:49fa211b91a2075bd5f761386ac2e05efa68dce6d8f6e12fc0e7ad0c8c4232c7 +size 14174 diff --git a/Data/Textures/atlas/shadow_long_circle.png b/Data/Textures/atlas/shadow_long_circle.png index 2c749c6..408c8b2 100644 --- a/Data/Textures/atlas/shadow_long_circle.png +++ b/Data/Textures/atlas/shadow_long_circle.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3d8f14083ed6e30db4bc87c75608d8d144d86afef5348e8cfa0de06fbf2b6e35 -size 7473 +oid sha256:f4f4d22a21181ea2fe167e5ae9f6fcfcb94b9b74ca577b01853f92ae8048b626 +size 6750 diff --git a/Data/Textures/atlas/shadow_tight_circle.png b/Data/Textures/atlas/shadow_tight_circle.png index 18b06d2..c3f127b 100644 --- a/Data/Textures/atlas/shadow_tight_circle.png +++ b/Data/Textures/atlas/shadow_tight_circle.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5ba23018e116c842e42fe05b851c91ba1d9ba0cb75e3c0fc6008e424fbe9f398 -size 4892 +oid sha256:16517125b798ac2e1b9e18447bbe80723e6c010268ad22136fb1c0cf56cf818a +size 3772 diff --git a/feely_pona.cpp b/feely_pona.cpp index 04aa210..79824d5 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -2342,6 +2342,22 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, } } + if (entity->flags & FP_GameEntityFlag_HasShadow) { + TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.shadow_tight_circle); + Dqn_Rect tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; + Dqn_Rect shadow_rect = {}; + shadow_rect.size = tex_rect.size * .5f; + shadow_rect.pos = Dqn_V2_InitNx2(world_hit_box.pos.x - (shadow_rect.size.w * .5f) + (shadow_rect.size.w * .2f), world_hit_box.pos.y + world_hit_box.size.h); + + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + tex_rect, + shadow_rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, .8f)); + } + // NOTE: Render entity sprites ============================================================= if (entity->action.sprite.anim) { FP_GameEntityAction const *action = &entity->action; @@ -2384,7 +2400,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, Dqn_Rect dest_rect = {}; dest_rect.size = src_rect.size * size_scale; - dest_rect.pos = world_pos - (dest_rect.size * .5f); + dest_rect.pos = world_pos - (dest_rect.size * .5f) + render_data.offset; if (sprite.flip & TELY_AssetFlip_X) dest_rect.size.w *= -1.f; // NOTE: Flip the texture horizontally diff --git a/feely_pona_entity.cpp b/feely_pona_entity.cpp index 2b2afff..1aa8cf8 100644 --- a/feely_pona_entity.cpp +++ b/feely_pona_entity.cpp @@ -22,6 +22,8 @@ static Dqn_f32 FP_Entity_CalcSpriteScaleForDesiredHeight(FP_Game *game, FP_Meter static FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, uint32_t raw_state, FP_GameDirection direction) { FP_EntityRenderData result = {}; + result.sheet = &game->atlas_sprite_sheet; + switch (type) { case FP_EntityType_Nil: { } break; @@ -39,10 +41,43 @@ static FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType case FP_EntityTerryState_Attack: { switch (direction) { - case FP_GameDirection_Up: result.anim_name = g_anim_names.terry_attack_up; result.height.meters *= 1.5f; break; - case FP_GameDirection_Down: result.anim_name = g_anim_names.terry_attack_down; result.height.meters *= 1.6f; break; - case FP_GameDirection_Left: result.anim_name = g_anim_names.terry_attack_side; result.height.meters *= 1.5f; break; - case FP_GameDirection_Right: result.anim_name = g_anim_names.terry_attack_side; result.height.meters *= 1.5f; result.flip = TELY_AssetFlip_X; break; + case FP_GameDirection_Up: { + result.anim_name = g_anim_names.terry_attack_up; + result.height.meters *= 1.5f; + + TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); + Dqn_Rect tex_rect = result.sheet->rects.data[sprite_anim->index]; + result.offset = Dqn_V2_InitNx2(0, -tex_rect.size.h * .2f); + } break; + + case FP_GameDirection_Down: { + result.anim_name = g_anim_names.terry_attack_down; + result.height.meters *= 1.6f; + + TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); + Dqn_Rect tex_rect = result.sheet->rects.data[sprite_anim->index]; + result.offset = Dqn_V2_InitNx2(0, -tex_rect.size.h * .2f); + } break; + + case FP_GameDirection_Left: { + result.anim_name = g_anim_names.terry_attack_side; + result.height.meters *= 1.5f; + + TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); + Dqn_Rect tex_rect = result.sheet->rects.data[sprite_anim->index]; + result.offset = Dqn_V2_InitNx2(0, -tex_rect.size.h * .2f); + } break; + + case FP_GameDirection_Right: { + result.anim_name = g_anim_names.terry_attack_side; + result.height.meters *= 1.5f; + result.flip = TELY_AssetFlip_X; + + TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); + Dqn_Rect tex_rect = result.sheet->rects.data[sprite_anim->index]; + result.offset = Dqn_V2_InitNx2(0, -tex_rect.size.h * .2f); + } break; + case FP_GameDirection_Count: DQN_INVALID_CODE_PATH; break; } } break; @@ -69,7 +104,13 @@ static FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType case FP_EntityTerryState_Run: { switch (direction) { - case FP_GameDirection_Up: result.anim_name = g_anim_names.terry_walk_up; break; + case FP_GameDirection_Up: { + result.anim_name = g_anim_names.terry_walk_up; + + TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); + Dqn_Rect tex_rect = result.sheet->rects.data[sprite_anim->index]; + result.offset = Dqn_V2_InitNx2(tex_rect.size.w * .3f, 0.f); + } break; case FP_GameDirection_Down: result.anim_name = g_anim_names.terry_walk_down; break; case FP_GameDirection_Left: result.anim_name = g_anim_names.terry_walk_left; break; case FP_GameDirection_Right: result.anim_name = g_anim_names.terry_walk_right; break; @@ -93,10 +134,43 @@ static FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType case FP_EntityTerryState_Attack: { switch (direction) { - case FP_GameDirection_Up: result.anim_name = g_anim_names.perry_attack_up; result.height.meters *= 1.5f; break; - case FP_GameDirection_Down: result.anim_name = g_anim_names.perry_attack_down; result.height.meters *= 1.6f; break; - case FP_GameDirection_Left: result.anim_name = g_anim_names.perry_attack_side; result.height.meters *= 1.5f; break; - case FP_GameDirection_Right: result.anim_name = g_anim_names.perry_attack_side; result.height.meters *= 1.5f; result.flip = TELY_AssetFlip_X; break; + case FP_GameDirection_Up: { + result.anim_name = g_anim_names.perry_attack_up; + result.height.meters *= 1.5f; + + TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); + Dqn_Rect tex_rect = result.sheet->rects.data[sprite_anim->index]; + result.offset = Dqn_V2_InitNx2(0, -tex_rect.size.h * .1f); + } break; + + case FP_GameDirection_Down: { + result.anim_name = g_anim_names.perry_attack_down; + result.height.meters *= 1.6f; + + TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); + Dqn_Rect tex_rect = result.sheet->rects.data[sprite_anim->index]; + result.offset = Dqn_V2_InitNx2(0, -tex_rect.size.h * .1f); + } break; + + case FP_GameDirection_Left: { + result.anim_name = g_anim_names.perry_attack_side; + result.height.meters *= 1.5f; + + TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); + Dqn_Rect tex_rect = result.sheet->rects.data[sprite_anim->index]; + result.offset = Dqn_V2_InitNx2(0, -tex_rect.size.h * .1f); + } break; + + case FP_GameDirection_Right: { + result.anim_name = g_anim_names.perry_attack_side; + result.height.meters *= 1.5f; + result.flip = TELY_AssetFlip_X; + + TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); + Dqn_Rect tex_rect = result.sheet->rects.data[sprite_anim->index]; + result.offset = Dqn_V2_InitNx2(0, -tex_rect.size.h * .1f); + } break; + case FP_GameDirection_Count: DQN_INVALID_CODE_PATH; break; } } break; @@ -332,7 +406,6 @@ static FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType case FP_EntityType_Count: DQN_INVALID_CODE_PATH; break; } - result.sheet = &game->atlas_sprite_sheet; TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(result.sheet, result.anim_name); if (sprite_anim) { result.sheet_rect = result.sheet->rects.data[sprite_anim->index]; diff --git a/feely_pona_entity.h b/feely_pona_entity.h index f9f3eb8..585694f 100644 --- a/feely_pona_entity.h +++ b/feely_pona_entity.h @@ -148,6 +148,7 @@ struct FP_EntityRenderData Dqn_Rect sheet_rect; Dqn_V2 render_size; TELY_AssetAnimatedSprite sprite; + Dqn_V2 offset; }; Dqn_usize const FP_TERRY_MOBILE_DATA_PER_RANGE_ATTACK = DQN_KILOBYTES(5); diff --git a/feely_pona_entity_create.cpp b/feely_pona_entity_create.cpp index 917ee99..6bffd68 100644 --- a/feely_pona_entity_create.cpp +++ b/feely_pona_entity_create.cpp @@ -190,6 +190,7 @@ static FP_GameEntityHandle FP_Entity_CreateTerryInternal(FP_Game *game, Dqn_V2 p entity->flags |= FP_GameEntityFlag_Attackable; entity->flags |= FP_GameEntityFlag_CameraTracking; entity->flags |= FP_GameEntityFlag_RecoversHP; + entity->flags |= FP_GameEntityFlag_HasShadow; entity->terry_mobile_data_plan_cap = DQN_KILOBYTES(6); entity->terry_mobile_data_plan = entity->terry_mobile_data_plan_cap; entity->faction = FP_GameEntityFaction_Friendly; diff --git a/feely_pona_game.h b/feely_pona_game.h index 49f1f92..8a6a1f9 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -24,6 +24,7 @@ enum FP_GameEntityFlag FP_GameEntityFlag_Foe = 1 << 16, FP_GameEntityFlag_NoClip = 1 << 17, FP_GameEntityFlag_RecoversHP = 1 << 18, + FP_GameEntityFlag_HasShadow = 1 << 19, }; enum FP_GameShapeType