From 19f8649870b3fe4d8581f4e0bfccf001f275eb49 Mon Sep 17 00:00:00 2001 From: doyle Date: Sat, 7 Oct 2023 15:29:56 +1100 Subject: [PATCH] fp: Add terry ghosting --- Data/Textures/atlas.png | 4 ++-- Data/Textures/atlas.txt | 4 ++-- Data/Textures/atlas/terry_ghost_1.png | 3 +++ Data/Textures/atlas/terry_ghost_2.png | 3 +++ Data/Textures/atlas/terry_ghost_3.png | 3 +++ Data/Textures/atlas/terry_ghost_4.png | 3 +++ Data/Textures/atlas/terry_ghost_5.png | 3 +++ Data/Textures/sprite_spec.txt | 4 ++-- feely_pona.cpp | 25 +++++++++++++++++++++++-- feely_pona.h | 1 + feely_pona_entity_create.cpp | 11 ++++++++++- feely_pona_game.cpp | 1 + feely_pona_game.h | 1 + 13 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 Data/Textures/atlas/terry_ghost_1.png create mode 100644 Data/Textures/atlas/terry_ghost_2.png create mode 100644 Data/Textures/atlas/terry_ghost_3.png create mode 100644 Data/Textures/atlas/terry_ghost_4.png create mode 100644 Data/Textures/atlas/terry_ghost_5.png diff --git a/Data/Textures/atlas.png b/Data/Textures/atlas.png index a5651e0..d13eded 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:5a7814629aaa53c134869cfa1208360edd24eb50db83aad445092d5bc6770dca -size 7090720 +oid sha256:aeca74a8c298d875aa01540d3762b3a1bacfbcc70267391e29fbc1a6b93e5d7a +size 6912274 diff --git a/Data/Textures/atlas.txt b/Data/Textures/atlas.txt index d7e9b8f..133ac45 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:e180b08d05e746ad49f01ff474c4755ac41d846c7f0520e1b4717ff653377cf2 -size 4579 +oid sha256:e6cf67979c23805f643207db91d3e43dba4cfbc23a13b6e3cc7060b0d160ed58 +size 4683 diff --git a/Data/Textures/atlas/terry_ghost_1.png b/Data/Textures/atlas/terry_ghost_1.png new file mode 100644 index 0000000..4c168a1 --- /dev/null +++ b/Data/Textures/atlas/terry_ghost_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa7680d3d1dd01d921e8f7f7fb495d847e25bfc7af3bf0a2a9e0495908254e64 +size 11479 diff --git a/Data/Textures/atlas/terry_ghost_2.png b/Data/Textures/atlas/terry_ghost_2.png new file mode 100644 index 0000000..9334475 --- /dev/null +++ b/Data/Textures/atlas/terry_ghost_2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c4262424e54a5ad6dafaf8de43a7ef8ef0fa91ec516842a318ce6d225e6f72a +size 11882 diff --git a/Data/Textures/atlas/terry_ghost_3.png b/Data/Textures/atlas/terry_ghost_3.png new file mode 100644 index 0000000..735e11c --- /dev/null +++ b/Data/Textures/atlas/terry_ghost_3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e409314aaab9c13ec5b20bdf20ac94dcef6828ae7765fed6561dca999cf9556 +size 11628 diff --git a/Data/Textures/atlas/terry_ghost_4.png b/Data/Textures/atlas/terry_ghost_4.png new file mode 100644 index 0000000..25976ab --- /dev/null +++ b/Data/Textures/atlas/terry_ghost_4.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b5aff01bd7160c6927fd1798704e29a0ec11e2e9d5adf953e7ce539bd260c503 +size 12962 diff --git a/Data/Textures/atlas/terry_ghost_5.png b/Data/Textures/atlas/terry_ghost_5.png new file mode 100644 index 0000000..3f9e0a2 --- /dev/null +++ b/Data/Textures/atlas/terry_ghost_5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d12b5e6e62afd10d5054bbbb601bc6b39f2b28ce4f2f53f21711e3a6587a6748 +size 12094 diff --git a/Data/Textures/sprite_spec.txt b/Data/Textures/sprite_spec.txt index 43b316c..b811995 100644 --- a/Data/Textures/sprite_spec.txt +++ b/Data/Textures/sprite_spec.txt @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:44384e83bfbc0eef71126c2b4ee0aeb83ea41507391b20f22eeb56facc637e09 -size 1333 +oid sha256:72dfbef497c6c9198bd957cb8e518dee78529559a8228a3c278589fc38459c65 +size 1350 diff --git a/feely_pona.cpp b/feely_pona.cpp index 9c1ee6f..2647498 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -599,10 +599,31 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform uint64_t duration_ms = 250; FP_Game_EntityActionReset(game, entity->handle, duration_ms, render_data.sprite); *acceleration_meters_per_s *= 35.f; + + #if 0 + FP_GameRenderSprite *cosmetic_sprite = Dqn_FArray_Make(&entity->extra_cosmetic_anims, Dqn_ZeroMem_Yes); + if (cosmetic_sprite) { + cosmetic_sprite->asset = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.terry_ghost, TELY_AssetFlip_No); + cosmetic_sprite->started_at_clock_ms = game->clock_ms; + cosmetic_sprite->height.meters = entity->sprite_height.meters; + + uint32_t max_rng_dist_x = DQN_CAST(uint32_t)(FP_Game_MetersToPixelsNx1(game, entity->sprite_height.meters) * 1.f); + uint32_t rng_x = Dqn_PCG32_Range(&game->rng, DQN_CAST(uint32_t)0, max_rng_dist_x); + cosmetic_sprite->offset.x = rng_x - (max_rng_dist_x * .5f); + + uint32_t max_rng_dist_y = DQN_CAST(uint32_t)(FP_Game_MetersToPixelsNx1(game, entity->sprite_height.meters) * .25f); + uint32_t rng_y = Dqn_PCG32_Range(&game->rng, DQN_CAST(uint32_t)0, max_rng_dist_y); + cosmetic_sprite->offset.y = -DQN_CAST(Dqn_f32)rng_y; + } + #endif } - if (action_has_finished) + entity->action.sprite_alpha = Dqn_PCG32_NextF32(&game->rng); + + if (action_has_finished) { FP_Game_EntityTransitionState(game, entity, FP_EntityTerryState_Run); + entity->action.sprite_alpha = 1.f; + } } break; } @@ -2062,7 +2083,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) dest_rect, Dqn_V2_Zero /*rotate origin*/, 0.f /*rotate radians*/, - TELY_COLOUR_WHITE_V4); + TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, entity->action.sprite_alpha)); } DQN_FOR_UINDEX(anim_index, entity->extra_cosmetic_anims.size) { diff --git a/feely_pona.h b/feely_pona.h index 6b40d0f..a958cb7 100644 --- a/feely_pona.h +++ b/feely_pona.h @@ -93,6 +93,7 @@ struct FP_GlobalAnimations Dqn_String8 terry_attack_phone_side = DQN_STRING8("terry_attack_phone_side"); Dqn_String8 terry_attack_phone_down = DQN_STRING8("terry_attack_phone_down"); Dqn_String8 terry_attack_phone_message = DQN_STRING8("terry_attack_phone_message"); + Dqn_String8 terry_ghost = DQN_STRING8("terry_ghost"); Dqn_String8 terry_walk_idle = DQN_STRING8("terry_walk_idle"); Dqn_String8 terry_walk_up = DQN_STRING8("terry_walk_up"); Dqn_String8 terry_walk_down = DQN_STRING8("terry_walk_down"); diff --git a/feely_pona_entity_create.cpp b/feely_pona_entity_create.cpp index 1bcb885..216c636 100644 --- a/feely_pona_entity_create.cpp +++ b/feely_pona_entity_create.cpp @@ -58,8 +58,17 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u } } break; - case FP_EntityTerryState_Run: /*FALLTHRU*/ case FP_EntityTerryState_Dash: { + switch (direction) { + case FP_GameDirection_Up: result.anim_name = g_anim_names.terry_ghost; break; + case FP_GameDirection_Down: result.anim_name = g_anim_names.terry_ghost; break; + case FP_GameDirection_Left: result.anim_name = g_anim_names.terry_ghost; break; + case FP_GameDirection_Right: result.anim_name = g_anim_names.terry_ghost; result.flip = TELY_AssetFlip_X; break; + case FP_GameDirection_Count: DQN_INVALID_CODE_PATH; break; + } + } break; + + case FP_EntityTerryState_Run: { switch (direction) { case FP_GameDirection_Up: result.anim_name = g_anim_names.terry_walk_up; break; case FP_GameDirection_Down: result.anim_name = g_anim_names.terry_walk_down; break; diff --git a/feely_pona_game.cpp b/feely_pona_game.cpp index 600502e..395d0cd 100644 --- a/feely_pona_game.cpp +++ b/feely_pona_game.cpp @@ -223,6 +223,7 @@ static FP_GameEntity *FP_Game_MakeEntityPointerFV(FP_Game *game, DQN_FMT_STRING_ result->parent = FP_Game_ActiveParentEntityPointer(game); result->name = TELY_ChunkPool_AllocFmtFV(game->chunk_pool, fmt, args); result->buildings_visited = FP_SentinelList_Init(game->chunk_pool); + result->action.sprite_alpha = 1.f; // NOTE: Attach entity as a child to the parent FP_GameEntity *parent = result->parent; diff --git a/feely_pona_game.h b/feely_pona_game.h index 68a7b36..01683c3 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -120,6 +120,7 @@ struct FP_GameEntityAction uint32_t state; uint32_t next_state; TELY_AssetAnimatedSprite sprite; + Dqn_f32 sprite_alpha; uint64_t started_at_clock_ms; uint64_t end_at_clock_ms; };