Compare commits

...

3 Commits

4 changed files with 334 additions and 375 deletions

2
External/tely vendored

@ -1 +1 @@
Subproject commit b135bb46769657e730b49c173db7476160855984 Subproject commit 96ddc4d93441f1fdccf04d9f7faed96de7971c52

View File

@ -83,7 +83,8 @@ TELY_AssetSpriteSheet FP_LoadSpriteSheetFromSpec(TELY_Platform *platform, TELY_A
anim->label = Dqn_String8_Copy(allocator, anim_name); anim->label = Dqn_String8_Copy(allocator, anim_name);
anim->index = DQN_CAST(uint16_t)sprite_rect_index; anim->index = DQN_CAST(uint16_t)sprite_rect_index;
anim->count = DQN_CAST(uint16_t)frame_count.value; anim->count = DQN_CAST(uint16_t)frame_count.value;
anim->seconds_per_frame = 1.f / frames_per_second.value; anim->ms_per_frame = DQN_CAST(uint32_t)(1000.f / frames_per_second.value);
DQN_ASSERT(anim->ms_per_frame != 0);
} else { } else {
DQN_ASSERTF(line_splits.size == 4, "Expected 4 splits for sprite frame lines"); DQN_ASSERTF(line_splits.size == 4, "Expected 4 splits for sprite frame lines");
Dqn_String8ToU64Result x = Dqn_String8_ToU64(line_splits.data[0], 0); Dqn_String8ToU64Result x = Dqn_String8_ToU64(line_splits.data[0], 0);
@ -106,6 +107,7 @@ TELY_AssetSpriteSheet FP_LoadSpriteSheetFromSpec(TELY_Platform *platform, TELY_A
DQN_ASSERT(result.rects.size == sprite_rect_index); DQN_ASSERT(result.rects.size == sprite_rect_index);
DQN_ASSERT(result.anims.size == sprite_anim_index); DQN_ASSERT(result.anims.size == sprite_anim_index);
return result; return result;
} }
@ -139,26 +141,26 @@ void TELY_DLL_Init(void *user_data)
sheet->sprite_size = Dqn_V2I_InitNx2(50, 37); sheet->sprite_size = Dqn_V2I_InitNx2(50, 37);
TELY_AssetSpriteAnimation hero_anims[] = { TELY_AssetSpriteAnimation hero_anims[] = {
{DQN_STRING8("Everything"), /*index*/ 0, /*count*/ sheet->sprite_count, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Everything"), /*index*/ 0, /*count*/ sheet->sprite_count, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Idle"), /*index*/ 0, /*count*/ 3, /*seconds_per_frame*/ 1 / 4.f}, {DQN_STRING8("Idle"), /*index*/ 0, /*count*/ 3, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 4.f)},
{DQN_STRING8("Run"), /*index*/ 8, /*count*/ 6, /*seconds_per_frame*/ 1 / 8.f}, {DQN_STRING8("Run"), /*index*/ 8, /*count*/ 6, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 8.f)},
{DQN_STRING8("Jump"), /*index*/ 14, /*count*/ 10, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Jump"), /*index*/ 14, /*count*/ 10, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Floor slide"), /*index*/ 24, /*count*/ 5, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Floor slide"), /*index*/ 24, /*count*/ 5, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Unknown"), /*index*/ 29, /*count*/ 9, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Unknown"), /*index*/ 29, /*count*/ 9, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Attack A"), /*index*/ 42, /*count*/ 7, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Attack A"), /*index*/ 42, /*count*/ 7, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Attack B"), /*index*/ 49, /*count*/ 4, /*seconds_per_frame*/ 1 / 8.f}, {DQN_STRING8("Attack B"), /*index*/ 49, /*count*/ 4, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 8.f)},
{DQN_STRING8("Attack C"), /*index*/ 53, /*count*/ 6, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Attack C"), /*index*/ 53, /*count*/ 6, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Hurt A"), /*index*/ 59, /*count*/ 5, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Hurt A"), /*index*/ 59, /*count*/ 5, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Hurt B"), /*index*/ 64, /*count*/ 5, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Hurt B"), /*index*/ 64, /*count*/ 5, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Unsheath sword"), /*index*/ 69, /*count*/ 4, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Unsheath sword"), /*index*/ 69, /*count*/ 4, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Sheath sword"), /*index*/ 73, /*count*/ 4, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Sheath sword"), /*index*/ 73, /*count*/ 4, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Air drift"), /*index*/ 77, /*count*/ 2, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Air drift"), /*index*/ 77, /*count*/ 2, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Air drop"), /*index*/ 79, /*count*/ 2, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Air drop"), /*index*/ 79, /*count*/ 2, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Ladder climb"), /*index*/ 81, /*count*/ 4, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Ladder climb"), /*index*/ 81, /*count*/ 4, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Chi push"), /*index*/ 85, /*count*/ 8, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Chi push"), /*index*/ 85, /*count*/ 8, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Leap slice A"), /*index*/ 93, /*count*/ 7, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Leap slice A"), /*index*/ 93, /*count*/ 7, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Leap slice B"), /*index*/ 100, /*count*/ 3, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Leap slice B"), /*index*/ 100, /*count*/ 3, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
{DQN_STRING8("Leap slice C"), /*index*/ 103, /*count*/ 6, /*seconds_per_frame*/ 1 / 12.f}, {DQN_STRING8("Leap slice C"), /*index*/ 103, /*count*/ 6, /*ms_per_frame*/ DQN_CAST(uint32_t)(1000.f / 12.f)},
}; };
game->hero_sprite_anims = Dqn_Slice_Alloc<TELY_AssetSpriteAnimation>(&platform->arena, DQN_ARRAY_UCOUNT(hero_anims), Dqn_ZeroMem_No); game->hero_sprite_anims = Dqn_Slice_Alloc<TELY_AssetSpriteAnimation>(&platform->arena, DQN_ARRAY_UCOUNT(hero_anims), Dqn_ZeroMem_No);
@ -168,34 +170,8 @@ void TELY_DLL_Init(void *user_data)
// NOTE: Load sprite sheets ==================================================================== // NOTE: Load sprite sheets ====================================================================
{ {
game->terry_sprite_sheet = FP_LoadSpriteSheetFromSpec(platform, assets, &platform->arena, DQN_STRING8("terry_resized_25%")); game->terry_sprite_sheet = FP_LoadSpriteSheetFromSpec(platform, assets, &platform->arena, DQN_STRING8("terry_resized_25%"));
game->terry_action_mappings = Dqn_Slice_CopyArray<FP_ActionToAnimationMapping>(&platform->arena, {
{&game->terry_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->terry_sprite_sheet, g_anim_names.terry_walk_idle)},
{&game->terry_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->terry_sprite_sheet, g_anim_names.terry_walk_up)},
{&game->terry_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->terry_sprite_sheet, g_anim_names.terry_walk_down)},
{&game->terry_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->terry_sprite_sheet, g_anim_names.terry_walk_left)},
{&game->terry_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->terry_sprite_sheet, g_anim_names.terry_walk_right)},
{&game->terry_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->terry_sprite_sheet, g_anim_names.terry_attack_up)},
{&game->terry_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->terry_sprite_sheet, g_anim_names.terry_attack_side)},
{&game->terry_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->terry_sprite_sheet, g_anim_names.terry_attack_down)},
});
game->terry_merchant_sprite_sheet = FP_LoadSpriteSheetFromSpec(platform, assets, &platform->arena, DQN_STRING8("terry_merchant_resized_25%")); game->terry_merchant_sprite_sheet = FP_LoadSpriteSheetFromSpec(platform, assets, &platform->arena, DQN_STRING8("terry_merchant_resized_25%"));
game->terry_merchant_action_mappings = Dqn_Slice_CopyArray<FP_ActionToAnimationMapping>(&platform->arena, {
{&game->terry_merchant_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->terry_merchant_sprite_sheet, g_anim_names.terry_merchant)},
});
game->smoochie_sprite_sheet = FP_LoadSpriteSheetFromSpec(platform, assets, &platform->arena, DQN_STRING8("smoochie_resized_25%")); game->smoochie_sprite_sheet = FP_LoadSpriteSheetFromSpec(platform, assets, &platform->arena, DQN_STRING8("smoochie_resized_25%"));
game->smoochie_action_mappings = Dqn_Slice_CopyArray<FP_ActionToAnimationMapping>(&platform->arena, {
{&game->smoochie_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->smoochie_sprite_sheet, g_anim_names.smoochie_walk_down)},
{&game->smoochie_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->smoochie_sprite_sheet, g_anim_names.smoochie_walk_up)},
{&game->smoochie_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->smoochie_sprite_sheet, g_anim_names.smoochie_walk_down)},
{&game->smoochie_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->smoochie_sprite_sheet, g_anim_names.smoochie_walk_left)},
{&game->smoochie_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->smoochie_sprite_sheet, g_anim_names.smoochie_walk_right)},
{&game->smoochie_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->smoochie_sprite_sheet, g_anim_names.smoochie_attack_down)},
{&game->smoochie_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->smoochie_sprite_sheet, g_anim_names.smoochie_attack_side)},
{&game->smoochie_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->smoochie_sprite_sheet, g_anim_names.smoochie_attack_heart)},
{&game->smoochie_sprite_sheet, TELY_Asset_GetSpriteAnimation(&game->smoochie_sprite_sheet, g_anim_names.smoochie_death)},
});
} }
game->entities = Dqn_VArray_Init<FP_GameEntity>(&platform->arena, 1024 * 8); game->entities = Dqn_VArray_Init<FP_GameEntity>(&platform->arena, 1024 * 8);
@ -207,7 +183,6 @@ void TELY_DLL_Init(void *user_data)
FP_GameEntity *entity = FP_Game_MakeEntityPointerF(game, "Terry"); FP_GameEntity *entity = FP_Game_MakeEntityPointerF(game, "Terry");
entity->type = FP_EntityType_Terry; entity->type = FP_EntityType_Terry;
entity->local_pos = Dqn_V2_InitNx2(1334, 396); entity->local_pos = Dqn_V2_InitNx2(1334, 396);
entity->action_to_anim_mapping = game->terry_action_mappings;
entity->size_scale = Dqn_V2_InitNx1(0.25f); entity->size_scale = Dqn_V2_InitNx1(0.25f);
entity->local_hit_box_size = Dqn_V2_InitNx2(428, 471) * entity->size_scale; entity->local_hit_box_size = Dqn_V2_InitNx2(428, 471) * entity->size_scale;
entity->flags |= FP_GameEntityFlag_Clickable; entity->flags |= FP_GameEntityFlag_Clickable;
@ -227,7 +202,6 @@ void TELY_DLL_Init(void *user_data)
entity->local_pos = Dqn_V2_InitNx2(1000, 124); entity->local_pos = Dqn_V2_InitNx2(1000, 124);
entity->local_hit_box_size = Dqn_V2_InitNx2(50, 50); entity->local_hit_box_size = Dqn_V2_InitNx2(50, 50);
entity->size_scale = Dqn_V2_InitNx1(0.25f); entity->size_scale = Dqn_V2_InitNx1(0.25f);
entity->action_to_anim_mapping = game->terry_merchant_action_mappings;
entity->flags |= FP_GameEntityFlag_Clickable; entity->flags |= FP_GameEntityFlag_Clickable;
entity->flags |= FP_GameEntityFlag_MoveByKeyboard; entity->flags |= FP_GameEntityFlag_MoveByKeyboard;
entity->flags |= FP_GameEntityFlag_MoveByMouse; entity->flags |= FP_GameEntityFlag_MoveByMouse;
@ -318,108 +292,97 @@ void TELY_DLL_Init(void *user_data)
game->test_audio = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa")); game->test_audio = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa"));
} }
FP_ActionToAnimationMapping FP_Game_GetActionAnimMappingWithName(FP_Game *game, FP_GameEntityHandle entity_handle, Dqn_String8 name) void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_GameEntity *entity, Dqn_V2 dir_vector)
{
FP_GameEntity *entity = FP_Game_GetEntity(game, entity_handle);
FP_ActionToAnimationMapping result = {};
for (FP_ActionToAnimationMapping const &mapping : entity->action_to_anim_mapping) {
if (mapping.anim.label == name) {
result = mapping;
break;
}
}
return result;
}
FP_ActionToAnimationMapping FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_GameEntity *entity, Dqn_V2 dir_vector)
{ {
FP_GameEntityAction *action = &entity->action; FP_GameEntityAction *action = &entity->action;
bool we_are_clicked_entity = entity->handle == game->clicked_entity; bool const we_are_clicked_entity = entity->handle == game->clicked_entity;
bool action_has_finished = action->timer_s != FP_GAME_ENTITY_ACTION_INFINITE_TIMER && action->timer_s >= action->end_at_s; bool const entity_has_velocity = entity->velocity.x || entity->velocity.y;
bool entity_has_velocity = entity->velocity.x || entity->velocity.y; bool const entering_new_state = action->state != action->next_state;
FP_ActionToAnimationMapping result = {}; bool const action_has_finished = !entering_new_state && game->clock_ms >= action->end_at_clock_ms;
action->state = action->next_state;
switch (entity->type) { switch (entity->type) {
case FP_EntityType_Nil: {
} break;
case FP_EntityType_Terry: { case FP_EntityType_Terry: {
FP_EntityTerryState *state = DQN_CAST(FP_EntityTerryState *) & action->state; FP_EntityTerryState *state = DQN_CAST(FP_EntityTerryState *) & action->state;
if (*state == FP_EntityTerryState_Nil) TELY_AssetSpriteSheet *sheet = &game->terry_sprite_sheet;
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle);
if (*state == FP_EntityTerryState_Idle) { switch (*state) {
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, g_anim_names.terry_walk_idle); case FP_EntityTerryState_Nil: {
action->next_state = FP_EntityTerryState_Idle;
} break;
if (action->flags & FP_GameEntityActionFlag_StateTransition) { case FP_EntityTerryState_Idle: {
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result); if (entering_new_state) {
} else if (we_are_clicked_entity) { TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.terry_walk_idle, TELY_AssetFlip_No);
uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER;
FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
}
if (we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) || if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) ||
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) { TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
switch (entity->direction) { switch (entity->direction) {
case FP_GameDirection_Up: { case FP_GameDirection_Up: {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackUp); action->next_state = FP_EntityTerryState_AttackUp;
} break; } break;
case FP_GameDirection_Left: { case FP_GameDirection_Left: {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide); action->next_state = FP_EntityTerryState_AttackSide;
} break; } break;
case FP_GameDirection_Right: { case FP_GameDirection_Right: {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide); action->next_state = FP_EntityTerryState_AttackSide;
} break; } break;
case FP_GameDirection_Down: { case FP_GameDirection_Down: {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackDown); action->next_state = FP_EntityTerryState_AttackDown;
} break; } break;
} }
} else if (dir_vector.x || dir_vector.y) { } else if (dir_vector.x || dir_vector.y) {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Run); action->next_state = FP_EntityTerryState_Run;
} }
} }
} break;
case FP_EntityTerryState_AttackUp: {
if (entering_new_state) {
TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.terry_attack_up, TELY_AssetFlip_No);
uint64_t duration_ms = sprite.anim->count * sprite.anim->ms_per_frame;
FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
} }
if (*state == FP_EntityTerryState_AttackSide) { if (action_has_finished) {
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, g_anim_names.terry_attack_side); action->next_state = FP_EntityTerryState_Idle;
action->flip_on_x = entity->direction == FP_GameDirection_Right; }
} break;
if (action->flags & FP_GameEntityActionFlag_StateTransition) { case FP_EntityTerryState_AttackDown: {
FP_Game_EntityActionReset(action, result.anim.count * result.anim.seconds_per_frame, result); if (entering_new_state) {
} else if (action_has_finished) { TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.terry_attack_down, TELY_AssetFlip_No);
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle); uint64_t duration_ms = sprite.anim->count * sprite.anim->ms_per_frame;
action->flip_on_x = false; FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
} }
#if 0 if (action_has_finished)
else if (!FP_Game_EntityActionHasFailed(action) && we_are_clicked_entity) { action->next_state = FP_EntityTerryState_Idle;
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) || } break;
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
Dqn_f32 t01 = action->timer_s / action->end_at_s; case FP_EntityTerryState_AttackSide: {
if (t01 > 0.5f) if (entering_new_state) {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackB); TELY_AssetFlip flip = entity->direction == FP_GameDirection_Right ? TELY_AssetFlip_X : TELY_AssetFlip_No;
else TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.terry_attack_side, flip);
action->flags |= FP_GameEntityActionFlag_Failed; uint64_t duration_ms = sprite.anim->count * sprite.anim->ms_per_frame;
} FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
}
#endif
} }
if (*state == FP_EntityTerryState_AttackUp) { if (action_has_finished)
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, g_anim_names.terry_attack_up); action->next_state = FP_EntityTerryState_Idle;
if (action->flags & FP_GameEntityActionFlag_StateTransition) { } break;
FP_Game_EntityActionReset(action, result.anim.count * result.anim.seconds_per_frame, result);
} else if (action_has_finished) {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle);
}
}
if (*state == FP_EntityTerryState_AttackDown) { case FP_EntityTerryState_Run: {
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, g_anim_names.terry_attack_down);
if (action->flags & FP_GameEntityActionFlag_StateTransition) {
FP_Game_EntityActionReset(action, result.anim.count * result.anim.seconds_per_frame, result);
} else if (action_has_finished) {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle);
}
}
if (*state == FP_EntityTerryState_Run) {
Dqn_String8 desired_action_name = {}; Dqn_String8 desired_action_name = {};
switch (entity->direction) { switch (entity->direction) {
case FP_GameDirection_Up: desired_action_name = g_anim_names.terry_walk_up; break; case FP_GameDirection_Up: desired_action_name = g_anim_names.terry_walk_up; break;
@ -427,49 +390,50 @@ FP_ActionToAnimationMapping FP_EntityActionStateMachine(FP_Game *game, TELY_Plat
case FP_GameDirection_Left: desired_action_name = g_anim_names.terry_walk_left; break; case FP_GameDirection_Left: desired_action_name = g_anim_names.terry_walk_left; break;
case FP_GameDirection_Right: desired_action_name = g_anim_names.terry_walk_right; break; case FP_GameDirection_Right: desired_action_name = g_anim_names.terry_walk_right; break;
} }
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, desired_action_name);
if (entering_new_state || action->sprite.anim->label != desired_action_name) {
TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, desired_action_name, TELY_AssetFlip_No);
uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER;
FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
}
if (we_are_clicked_entity) { if (we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) || if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) ||
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) { TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
switch (entity->direction) { switch (entity->direction) {
case FP_GameDirection_Up: { case FP_GameDirection_Up: {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackUp); action->next_state = FP_EntityTerryState_AttackUp;
} break; } break;
case FP_GameDirection_Left: { case FP_GameDirection_Left: {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide); action->next_state = FP_EntityTerryState_AttackSide;
} break; } break;
case FP_GameDirection_Right: { case FP_GameDirection_Right: {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide); action->next_state = FP_EntityTerryState_AttackSide;
} break; } break;
case FP_GameDirection_Down: { case FP_GameDirection_Down: {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackDown); action->next_state = FP_EntityTerryState_AttackDown;
} break; } break;
} }
} else if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_LeftShift) || } else if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_LeftShift) ||
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_A)) { TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_A)) {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Dash); action->next_state = FP_EntityTerryState_Dash;
} }
} }
// NOTE: Also handles state transition
if (action->mapping.anim.label != result.anim.label) {
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result);
}
if (!entity_has_velocity /*&& !has_collision*/) { if (!entity_has_velocity /*&& !has_collision*/) {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle); action->next_state = FP_EntityTerryState_Idle;
}
} }
} break;
if (*state == FP_EntityTerryState_Dash) { case FP_EntityTerryState_Dash: {
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, g_anim_names.terry_walk_right);
if (action->flags & FP_GameEntityActionFlag_StateTransition) { if (entering_new_state) {
FP_Game_EntityActionReset(action, result.anim.count * result.anim.seconds_per_frame, result); TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.terry_walk_right, TELY_AssetFlip_No);
uint64_t duration_ms = sprite.anim->count * sprite.anim->ms_per_frame;
FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
Dqn_V2 dash_dir = {}; Dqn_V2 dash_dir = {};
switch (entity->direction) { switch (entity->direction) {
@ -482,15 +446,17 @@ FP_ActionToAnimationMapping FP_EntityActionStateMachine(FP_Game *game, TELY_Plat
Dqn_V2 dash_acceleration = dash_dir * 400'000'000.f; Dqn_V2 dash_acceleration = dash_dir * 400'000'000.f;
Dqn_f32 t = DQN_CAST(Dqn_f32)DQN_SQUARED(input->delta_s); Dqn_f32 t = DQN_CAST(Dqn_f32)DQN_SQUARED(input->delta_s);
entity->velocity = (dash_acceleration * t) + entity->velocity * 2.0f; entity->velocity = (dash_acceleration * t) + entity->velocity * 2.0f;
}
} else if (action_has_finished) { if (action_has_finished) {
if (entity_has_velocity) { if (entity_has_velocity) {
// TODO(doyle): Not sure if this branch triggers properly. // TODO(doyle): Not sure if this branch triggers properly.
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Run); action->next_state = FP_EntityTerryState_Run;
} else { } else {
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle); action->next_state = FP_EntityTerryState_Idle;
} }
} }
} break;
} }
if (*state == FP_EntityTerryState_AttackUp || if (*state == FP_EntityTerryState_AttackUp ||
@ -513,64 +479,20 @@ FP_ActionToAnimationMapping FP_EntityActionStateMachine(FP_Game *game, TELY_Plat
case FP_EntityType_Smoochie: { case FP_EntityType_Smoochie: {
FP_EntitySmoochieState *state = DQN_CAST(FP_EntitySmoochieState *) & action->state; FP_EntitySmoochieState *state = DQN_CAST(FP_EntitySmoochieState *) & action->state;
if (*state == FP_EntitySmoochieState_Nil) TELY_AssetSpriteSheet *sheet = &game->smoochie_sprite_sheet;
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Idle);
if (*state == FP_EntitySmoochieState_Idle) { switch (*state) {
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, g_anim_names.smoochie_walk_down); case FP_EntitySmoochieState_Nil: {
action->next_state = FP_EntitySmoochieState_Idle;
if (action->flags & FP_GameEntityActionFlag_StateTransition) {
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result);
} else if (we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) ||
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
switch (entity->direction) {
case FP_GameDirection_Up: /*FALLTHRU*/
case FP_GameDirection_Right: /*FALLTHRU*/
case FP_GameDirection_Left: {
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_AttackSide);
} break; } break;
case FP_GameDirection_Down: { case FP_EntitySmoochieState_Idle: {
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_AttackDown);
} break;
}
} else if (dir_vector.x || dir_vector.y) {
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Run);
}
}
}
if (*state == FP_EntitySmoochieState_AttackDown) { if (entering_new_state) {
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, g_anim_names.smoochie_attack_down); TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.smoochie_walk_down, TELY_AssetFlip_No);
if (action->flags & FP_GameEntityActionFlag_StateTransition) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER;
FP_Game_EntityActionReset(action, result.anim.count * result.anim.seconds_per_frame, result); FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
} else if (action_has_finished) {
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Idle);
} }
}
if (*state == FP_EntitySmoochieState_AttackSide) {
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, g_anim_names.smoochie_attack_side);
action->flip_on_x = entity->direction == FP_GameDirection_Right;
if (action->flags & FP_GameEntityActionFlag_StateTransition) {
FP_Game_EntityActionReset(action, result.anim.count * result.anim.seconds_per_frame, result);
} else if (action_has_finished) {
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Idle);
action->flip_on_x = false;
}
}
if (*state == FP_EntitySmoochieState_Run) {
Dqn_String8 desired_action_name = {};
switch (entity->direction) {
case FP_GameDirection_Up: desired_action_name = g_anim_names.smoochie_walk_up; break;
case FP_GameDirection_Down: desired_action_name = g_anim_names.smoochie_walk_down; break;
case FP_GameDirection_Left: desired_action_name = g_anim_names.smoochie_walk_left; break;
case FP_GameDirection_Right: desired_action_name = g_anim_names.smoochie_walk_right; break;
}
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, desired_action_name);
if (we_are_clicked_entity) { if (we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) || if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) ||
@ -580,24 +502,83 @@ FP_ActionToAnimationMapping FP_EntityActionStateMachine(FP_Game *game, TELY_Plat
case FP_GameDirection_Up: /*FALLTHRU*/ case FP_GameDirection_Up: /*FALLTHRU*/
case FP_GameDirection_Right: /*FALLTHRU*/ case FP_GameDirection_Right: /*FALLTHRU*/
case FP_GameDirection_Left: { case FP_GameDirection_Left: {
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_AttackSide); action->next_state = FP_EntitySmoochieState_AttackSide;
} break; } break;
case FP_GameDirection_Down: { case FP_GameDirection_Down: {
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_AttackDown); action->next_state = FP_EntitySmoochieState_AttackDown;
} break;
}
} else if (dir_vector.x || dir_vector.y) {
action->next_state = FP_EntitySmoochieState_Run;
}
}
} break;
case FP_EntitySmoochieState_AttackDown: {
if (entering_new_state) {
TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.smoochie_attack_down, TELY_AssetFlip_No);
uint64_t duration_ms = sprite.anim->count * sprite.anim->ms_per_frame;
FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
}
if (action_has_finished) {
action->next_state = FP_EntitySmoochieState_Idle;
}
} break;
case FP_EntitySmoochieState_AttackSide: {
if (entering_new_state) {
TELY_AssetFlip flip = entity->direction == FP_GameDirection_Right ? TELY_AssetFlip_X : TELY_AssetFlip_No;
TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.smoochie_attack_side, flip);
uint64_t duration_ms = sprite.anim->count * sprite.anim->ms_per_frame;
FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
}
if (action_has_finished)
action->next_state = FP_EntitySmoochieState_Idle;
} break;
case FP_EntitySmoochieState_AttackHeart: {
} break;
case FP_EntitySmoochieState_Run: {
Dqn_String8 desired_action_name = {};
switch (entity->direction) {
case FP_GameDirection_Up: desired_action_name = g_anim_names.smoochie_walk_up; break;
case FP_GameDirection_Down: desired_action_name = g_anim_names.smoochie_walk_down; break;
case FP_GameDirection_Left: desired_action_name = g_anim_names.smoochie_walk_left; break;
case FP_GameDirection_Right: desired_action_name = g_anim_names.smoochie_walk_right; break;
}
if (entering_new_state || action->sprite.anim->label != desired_action_name) {
TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, desired_action_name, TELY_AssetFlip_No);
uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER;
FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
}
if (we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) ||
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
switch (entity->direction) {
case FP_GameDirection_Up: /*FALLTHRU*/
case FP_GameDirection_Right: /*FALLTHRU*/
case FP_GameDirection_Left: {
action->next_state = FP_EntitySmoochieState_AttackSide;
} break;
case FP_GameDirection_Down: {
action->next_state = FP_EntitySmoochieState_AttackDown;
} break; } break;
} }
} }
} }
// NOTE: Also handles state transition
if (action->mapping.anim.label != result.anim.label) {
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result);
}
if (!entity_has_velocity /*&& !has_collision*/) { if (!entity_has_velocity /*&& !has_collision*/) {
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Idle); action->next_state = FP_EntitySmoochieState_Idle;
} }
} break;
} }
if (*state == FP_EntitySmoochieState_AttackSide || *state == FP_EntitySmoochieState_AttackDown) { if (*state == FP_EntitySmoochieState_AttackSide || *state == FP_EntitySmoochieState_AttackDown) {
@ -613,26 +594,28 @@ FP_ActionToAnimationMapping FP_EntityActionStateMachine(FP_Game *game, TELY_Plat
} else { } else {
entity->attack_box_size = {}; entity->attack_box_size = {};
} }
} break; } break;
case FP_EntityType_Merchant: { case FP_EntityType_Merchant: {
FP_EntityTerryMerchantState *state = DQN_CAST(FP_EntityTerryMerchantState *)&action->state; FP_EntityTerryMerchantState *state = DQN_CAST(FP_EntityTerryMerchantState *)&action->state;
if (*state == FP_EntityTerryMerchantState_Nil) TELY_AssetSpriteSheet *sheet = &game->terry_merchant_sprite_sheet;
FP_Game_EntityActionSetState(action, FP_EntityTerryMerchantState_Idle);
if (*state == FP_EntityTerryMerchantState_Idle) { switch (*state) {
result = FP_Game_GetActionAnimMappingWithName(game, entity->handle, g_anim_names.terry_merchant); case FP_EntityTerryMerchantState_Nil: {
if (action->flags & FP_GameEntityActionFlag_StateTransition) { action->next_state = FP_EntityTerryMerchantState_Idle;
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result); } break;
case FP_EntityTerryMerchantState_Idle: {
if (entering_new_state) {
TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.terry_merchant, TELY_AssetFlip_No);
uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER;
FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite);
} }
} break;
} }
} break; } break;
} }
// NOTE: Tick entity action ================================================================
action->timer_s += DQN_CAST(Dqn_f32)input->delta_s;
return result;
} }
void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer, TELY_PlatformInput *input) void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer, TELY_PlatformInput *input)
@ -642,6 +625,7 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer,
if (TELY_Platform_InputKeyIsReleased(input->mouse_left)) if (TELY_Platform_InputKeyIsReleased(input->mouse_left))
game->clicked_entity = game->prev_active_entity; game->clicked_entity = game->prev_active_entity;
game->clock_ms = DQN_CAST(uint64_t)(platform->input.timer_s * 1000.f);
Dqn_V2 dir_vector = {}; Dqn_V2 dir_vector = {};
// NOTE: Keyboard movement input // NOTE: Keyboard movement input
@ -887,7 +871,7 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer,
} }
// NOTE: Handle input on entity ============================================================ // NOTE: Handle input on entity ============================================================
FP_ActionToAnimationMapping action_to_anim_mapping = FP_EntityActionStateMachine(game, input, entity, dir_vector); FP_EntityActionStateMachine(game, input, entity, dir_vector);
// NOTE: Mob spawner ======================================================================= // NOTE: Mob spawner =======================================================================
if (entity->flags & FP_GameEntityFlag_MobSpawner) { if (entity->flags & FP_GameEntityFlag_MobSpawner) {
@ -1036,27 +1020,28 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
} }
// NOTE: Render entity sprites ============================================================= // NOTE: Render entity sprites =============================================================
if (entity->action.mapping.anim.label.size) { if (entity->action.sprite.anim) {
FP_GameEntityAction const *action = &entity->action; FP_GameEntityAction const *action = &entity->action;
TELY_AssetSpriteSheet const *sprite_sheet = action->mapping.sheet; TELY_AssetAnimatedSprite const sprite = action->sprite;
TELY_AssetSpriteAnimation const *sprite_anim = &action->mapping.anim;
uint16_t anim_frame = DQN_CAST(uint16_t)(action->timer_s / sprite_anim->seconds_per_frame) % sprite_anim->count;
Dqn_usize sprite_index = sprite_anim->index + anim_frame; uint64_t elapsed_ms = game->clock_ms - action->started_at_clock_ms;
uint16_t anim_frame = DQN_CAST(uint16_t)(elapsed_ms / sprite.anim->ms_per_frame) % sprite.anim->count;
Dqn_usize sprite_index = sprite.anim->index + anim_frame;
Dqn_Rect src_rect = {}; Dqn_Rect src_rect = {};
switch (sprite_sheet->type) { switch (sprite.sheet->type) {
case TELY_AssetSpriteSheetType_Uniform: { case TELY_AssetSpriteSheetType_Uniform: {
Dqn_usize sprite_sheet_row = sprite_index / sprite_sheet->sprites_per_row; Dqn_usize sprite_sheet_row = sprite_index / sprite.sheet->sprites_per_row;
Dqn_usize sprite_sheet_column = sprite_index % sprite_sheet->sprites_per_row; Dqn_usize sprite_sheet_column = sprite_index % sprite.sheet->sprites_per_row;
src_rect.pos.x = DQN_CAST(Dqn_f32)(sprite_sheet_column * sprite_sheet->sprite_size.w); src_rect.pos.x = DQN_CAST(Dqn_f32)(sprite_sheet_column * sprite.sheet->sprite_size.w);
src_rect.pos.y = DQN_CAST(Dqn_f32)(sprite_sheet_row * sprite_sheet->sprite_size.y); src_rect.pos.y = DQN_CAST(Dqn_f32)(sprite_sheet_row * sprite.sheet->sprite_size.y);
src_rect.size.w = DQN_CAST(Dqn_f32)sprite_sheet->sprite_size.w; src_rect.size.w = DQN_CAST(Dqn_f32)sprite.sheet->sprite_size.w;
src_rect.size.h = DQN_CAST(Dqn_f32)sprite_sheet->sprite_size.h; src_rect.size.h = DQN_CAST(Dqn_f32)sprite.sheet->sprite_size.h;
} break; } break;
case TELY_AssetSpriteSheetType_Rects: { case TELY_AssetSpriteSheetType_Rects: {
DQN_ASSERT(sprite_index < sprite_sheet->rects.size); DQN_ASSERT(sprite_index < sprite.sheet->rects.size);
src_rect = sprite_sheet->rects.data[sprite_index]; src_rect = sprite.sheet->rects.data[sprite_index];
} break; } break;
} }
@ -1064,10 +1049,13 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
dest_rect.size = src_rect.size * entity->size_scale; dest_rect.size = src_rect.size * entity->size_scale;
dest_rect.pos = world_pos - (dest_rect.size * .5f); dest_rect.pos = world_pos - (dest_rect.size * .5f);
if (action->flip_on_x) if (sprite.flip & TELY_AssetFlip_X)
dest_rect.size.w *= -1.f; // NOTE: Flip the texture horizontally dest_rect.size.w *= -1.f; // NOTE: Flip the texture horizontally
TELY_Render_TextureColourV4(renderer, sprite_sheet->tex_handle, src_rect, dest_rect, TELY_COLOUR_WHITE_V4); if (sprite.flip & TELY_AssetFlip_Y)
dest_rect.size.h *= -1.f; // NOTE: Flip the texture vertically
TELY_Render_TextureColourV4(renderer, sprite.sheet->tex_handle, src_rect, dest_rect, TELY_COLOUR_WHITE_V4);
} }
// NOTE: Render attack box ================================================================= // NOTE: Render attack box =================================================================

View File

@ -425,32 +425,16 @@ static Dqn_Rect FP_Game_CalcEntityWorldBoundingBox(FP_Game *game, FP_GameEntityH
return result; return result;
} }
// Transition the action into the desire state and set the flag to indicate it
// has just transitioned
static void FP_Game_EntityActionSetState(FP_GameEntityAction *action, uint32_t state)
{
if (!action)
return;
action->state = state;
action->flags |= FP_GameEntityActionFlag_StateTransition;
}
// Reset the timers and animation for the current action and set the duration // Reset the timers and animation for the current action and set the duration
// for the new action. // for the new action.
static void FP_Game_EntityActionReset(FP_GameEntityAction *action, Dqn_f32 new_action_duration, FP_ActionToAnimationMapping mapping) static void FP_Game_EntityActionReset(FP_Game *game, FP_GameEntityHandle entity_handle, uint64_t duration_ms, TELY_AssetAnimatedSprite sprite)
{ {
if (!action) FP_GameEntity *entity = FP_Game_GetEntity(game, entity_handle);
if (!entity)
return; return;
action->mapping = mapping; entity->action.sprite = sprite;
action->timer_s = 0.f; entity->action.started_at_clock_ms = game->clock_ms;
action->end_at_s = new_action_duration; entity->action.end_at_clock_ms = DQN_MAX(duration_ms, game->clock_ms + duration_ms);
action->flags = 0;
}
static bool FP_Game_EntityActionHasFailed(FP_GameEntityAction const *action)
{
bool result = action ? action->flags & FP_GameEntityActionFlag_Failed : true;
return result;
} }
static Dqn_V2I FP_Game_WorldPosToTilePos(FP_Game *game, Dqn_V2 world_pos) static Dqn_V2I FP_Game_WorldPosToTilePos(FP_Game *game, Dqn_V2 world_pos)
@ -674,7 +658,6 @@ static FP_GameEntityHandle FP_Game_EntityAddMob(FP_Game *game, Dqn_V2 pos)
entity->type = FP_EntityType_Smoochie; entity->type = FP_EntityType_Smoochie;
entity->local_pos = pos; entity->local_pos = pos;
entity->size_scale = Dqn_V2_InitNx1(.25f); entity->size_scale = Dqn_V2_InitNx1(.25f);
entity->action_to_anim_mapping = game->smoochie_action_mappings;
entity->local_hit_box_size = Dqn_V2_InitNx2(428, 471) * entity->size_scale; entity->local_hit_box_size = Dqn_V2_InitNx2(428, 471) * entity->size_scale;
entity->flags |= FP_GameEntityFlag_Clickable; entity->flags |= FP_GameEntityFlag_Clickable;
entity->flags |= FP_GameEntityFlag_MoveByKeyboard; entity->flags |= FP_GameEntityFlag_MoveByKeyboard;

View File

@ -60,27 +60,20 @@ struct FP_GameEntitySpawnList
FP_GameEntitySpawnList *prev; FP_GameEntitySpawnList *prev;
}; };
enum FP_GameEntityActionFlag struct FP_GameEntityActionSprite
{
FP_GameEntityActionFlag_StateTransition = 1 << 0,
FP_GameEntityActionFlag_Failed = 1 << 1,
};
struct FP_ActionToAnimationMapping
{ {
TELY_AssetSpriteSheet *sheet; TELY_AssetSpriteSheet *sheet;
TELY_AssetSpriteAnimation anim; TELY_AssetSpriteAnimation *anim;
}; };
Dqn_f32 const FP_GAME_ENTITY_ACTION_INFINITE_TIMER = -1.f; uint64_t const FP_GAME_ENTITY_ACTION_INFINITE_TIMER = UINT64_MAX;
struct FP_GameEntityAction struct FP_GameEntityAction
{ {
bool flip_on_x;
uint32_t state; uint32_t state;
uint32_t flags; // Bit flags corresponding with `FP_GameEntityActionFlag` uint32_t next_state;
FP_ActionToAnimationMapping mapping; TELY_AssetAnimatedSprite sprite;
Dqn_f32 timer_s; uint64_t started_at_clock_ms;
Dqn_f32 end_at_s; uint64_t end_at_clock_ms;
}; };
enum FP_GameDirection enum FP_GameDirection
@ -103,8 +96,6 @@ struct FP_GameEntity
Dqn_String8 name; Dqn_String8 name;
FP_GameEntityHandle handle; FP_GameEntityHandle handle;
// TODO(doyle): Deprecate this, it is over engineered and doesn't work
Dqn_Slice<FP_ActionToAnimationMapping> action_to_anim_mapping;
Dqn_V2 size_scale; Dqn_V2 size_scale;
FP_GameEntityAction action; FP_GameEntityAction action;
Dqn_V2 velocity; Dqn_V2 velocity;
@ -168,13 +159,8 @@ struct FP_Game
Dqn_VArray<FP_GameEntity> entities; Dqn_VArray<FP_GameEntity> entities;
TELY_AssetSpriteSheet terry_sprite_sheet; TELY_AssetSpriteSheet terry_sprite_sheet;
Dqn_Slice<FP_ActionToAnimationMapping> terry_action_mappings;
TELY_AssetSpriteSheet smoochie_sprite_sheet; TELY_AssetSpriteSheet smoochie_sprite_sheet;
Dqn_Slice<FP_ActionToAnimationMapping> smoochie_action_mappings;
TELY_AssetSpriteSheet terry_merchant_sprite_sheet; TELY_AssetSpriteSheet terry_merchant_sprite_sheet;
Dqn_Slice<FP_ActionToAnimationMapping> terry_merchant_action_mappings;
FP_GameEntity *root_entity; FP_GameEntity *root_entity;
FP_GameEntity *entity_free_list; FP_GameEntity *entity_free_list;
@ -190,6 +176,8 @@ struct FP_Game
FP_GameCamera camera; FP_GameCamera camera;
TELY_RFui rfui; TELY_RFui rfui;
uint64_t clock_ms;
}; };
struct FP_GameAStarNode struct FP_GameAStarNode