fp: Use switch statement for state machine
This commit is contained in:
parent
468c9995bd
commit
858a66786a
469
feely_pona.cpp
469
feely_pona.cpp
@ -293,167 +293,172 @@ void TELY_DLL_Init(void *user_data)
|
||||
|
||||
FP_GameEntityActionSprite FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_GameEntity *entity, Dqn_V2 dir_vector)
|
||||
{
|
||||
FP_GameEntityAction *action = &entity->action;
|
||||
bool 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 entity_has_velocity = entity->velocity.x || entity->velocity.y;
|
||||
FP_GameEntityAction *action = &entity->action;
|
||||
bool 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 entity_has_velocity = entity->velocity.x || entity->velocity.y;
|
||||
FP_GameEntityActionSprite result = {};
|
||||
|
||||
switch (entity->type) {
|
||||
case FP_EntityType_Nil: {
|
||||
} break;
|
||||
|
||||
case FP_EntityType_Terry: {
|
||||
FP_EntityTerryState *state = DQN_CAST(FP_EntityTerryState *) & action->state;
|
||||
TELY_AssetSpriteSheet *sheet = &game->terry_sprite_sheet;
|
||||
result.sheet = sheet;
|
||||
|
||||
if (*state == FP_EntityTerryState_Nil)
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle);
|
||||
switch (*state) {
|
||||
case FP_EntityTerryState_Nil: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle);
|
||||
} break;
|
||||
|
||||
if (*state == FP_EntityTerryState_Idle) {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_walk_idle);
|
||||
case FP_EntityTerryState_Idle: {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_walk_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: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackUp);
|
||||
} break;
|
||||
|
||||
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: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackUp);
|
||||
} break;
|
||||
case FP_GameDirection_Left: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide);
|
||||
} break;
|
||||
|
||||
case FP_GameDirection_Left: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide);
|
||||
} break;
|
||||
case FP_GameDirection_Right: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide);
|
||||
} break;
|
||||
|
||||
case FP_GameDirection_Right: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide);
|
||||
} break;
|
||||
|
||||
case FP_GameDirection_Down: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackDown);
|
||||
} break;
|
||||
case FP_GameDirection_Down: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackDown);
|
||||
} break;
|
||||
}
|
||||
} else if (dir_vector.x || dir_vector.y) {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Run);
|
||||
}
|
||||
} else if (dir_vector.x || dir_vector.y) {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Run);
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
if (*state == FP_EntityTerryState_AttackSide) {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_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_EntityTerryState_Idle);
|
||||
action->flip_on_x = false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
else if (!FP_Game_EntityActionHasFailed(action) && we_are_clicked_entity) {
|
||||
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) ||
|
||||
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
|
||||
Dqn_f32 t01 = action->timer_s / action->end_at_s;
|
||||
if (t01 > 0.5f)
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackB);
|
||||
else
|
||||
action->flags |= FP_GameEntityActionFlag_Failed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (*state == FP_EntityTerryState_AttackUp) {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_attack_up);
|
||||
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_AttackDown) {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_walk_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 = {};
|
||||
switch (entity->direction) {
|
||||
case FP_GameDirection_Up: desired_action_name = g_anim_names.terry_walk_up; break;
|
||||
case FP_GameDirection_Down: desired_action_name = g_anim_names.terry_walk_down; 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;
|
||||
}
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, desired_action_name);
|
||||
|
||||
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: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackUp);
|
||||
} break;
|
||||
|
||||
case FP_GameDirection_Left: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide);
|
||||
} break;
|
||||
|
||||
case FP_GameDirection_Right: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide);
|
||||
} break;
|
||||
|
||||
case FP_GameDirection_Down: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackDown);
|
||||
} break;
|
||||
}
|
||||
} else if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_LeftShift) ||
|
||||
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_A)) {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Dash);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Also handles state transition
|
||||
if (action->sprite.anim->label != result.anim->label) {
|
||||
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result);
|
||||
}
|
||||
|
||||
if (!entity_has_velocity /*&& !has_collision*/) {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle);
|
||||
}
|
||||
}
|
||||
|
||||
if (*state == FP_EntityTerryState_Dash) {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_walk_right);
|
||||
|
||||
if (action->flags & FP_GameEntityActionFlag_StateTransition) {
|
||||
FP_Game_EntityActionReset(action, result.anim->count * result.anim->seconds_per_frame, result);
|
||||
|
||||
Dqn_V2 dash_dir = {};
|
||||
switch (entity->direction) {
|
||||
case FP_GameDirection_Up: dash_dir.y = -1.f; break;
|
||||
case FP_GameDirection_Down: dash_dir.y = +1.f; break;
|
||||
case FP_GameDirection_Left: dash_dir.x = -1.f; break;
|
||||
case FP_GameDirection_Right: dash_dir.x = +1.f; break;
|
||||
}
|
||||
|
||||
Dqn_V2 dash_acceleration = dash_dir * 400'000'000.f;
|
||||
Dqn_f32 t = DQN_CAST(Dqn_f32)DQN_SQUARED(input->delta_s);
|
||||
entity->velocity = (dash_acceleration * t) + entity->velocity * 2.0f;
|
||||
|
||||
} else if (action_has_finished) {
|
||||
if (entity_has_velocity) {
|
||||
// TODO(doyle): Not sure if this branch triggers properly.
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Run);
|
||||
} else {
|
||||
case FP_EntityTerryState_AttackUp: {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_attack_up);
|
||||
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);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case FP_EntityTerryState_AttackDown: {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_walk_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);
|
||||
}
|
||||
} break;
|
||||
|
||||
case FP_EntityTerryState_AttackSide: {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_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_EntityTerryState_Idle);
|
||||
action->flip_on_x = false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
else if (!FP_Game_EntityActionHasFailed(action) && we_are_clicked_entity) {
|
||||
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) ||
|
||||
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
|
||||
Dqn_f32 t01 = action->timer_s / action->end_at_s;
|
||||
if (t01 > 0.5f)
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackB);
|
||||
else
|
||||
action->flags |= FP_GameEntityActionFlag_Failed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} break;
|
||||
|
||||
case FP_EntityTerryState_Run: {
|
||||
Dqn_String8 desired_action_name = {};
|
||||
switch (entity->direction) {
|
||||
case FP_GameDirection_Up: desired_action_name = g_anim_names.terry_walk_up; break;
|
||||
case FP_GameDirection_Down: desired_action_name = g_anim_names.terry_walk_down; 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;
|
||||
}
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, desired_action_name);
|
||||
|
||||
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: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackUp);
|
||||
} break;
|
||||
|
||||
case FP_GameDirection_Left: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide);
|
||||
} break;
|
||||
|
||||
case FP_GameDirection_Right: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackSide);
|
||||
} break;
|
||||
|
||||
case FP_GameDirection_Down: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_AttackDown);
|
||||
} break;
|
||||
}
|
||||
} else if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_LeftShift) ||
|
||||
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_A)) {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Dash);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Also handles state transition
|
||||
if (action->sprite.anim->label != result.anim->label) {
|
||||
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result);
|
||||
}
|
||||
|
||||
if (!entity_has_velocity /*&& !has_collision*/) {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle);
|
||||
}
|
||||
} break;
|
||||
|
||||
case FP_EntityTerryState_Dash: {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_walk_right);
|
||||
|
||||
if (action->flags & FP_GameEntityActionFlag_StateTransition) {
|
||||
FP_Game_EntityActionReset(action, result.anim->count * result.anim->seconds_per_frame, result);
|
||||
|
||||
Dqn_V2 dash_dir = {};
|
||||
switch (entity->direction) {
|
||||
case FP_GameDirection_Up: dash_dir.y = -1.f; break;
|
||||
case FP_GameDirection_Down: dash_dir.y = +1.f; break;
|
||||
case FP_GameDirection_Left: dash_dir.x = -1.f; break;
|
||||
case FP_GameDirection_Right: dash_dir.x = +1.f; break;
|
||||
}
|
||||
|
||||
Dqn_V2 dash_acceleration = dash_dir * 400'000'000.f;
|
||||
Dqn_f32 t = DQN_CAST(Dqn_f32)DQN_SQUARED(input->delta_s);
|
||||
entity->velocity = (dash_acceleration * t) + entity->velocity * 2.0f;
|
||||
|
||||
} else if (action_has_finished) {
|
||||
if (entity_has_velocity) {
|
||||
// TODO(doyle): Not sure if this branch triggers properly.
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Run);
|
||||
} else {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryState_Idle);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
if (*state == FP_EntityTerryState_AttackUp ||
|
||||
@ -479,91 +484,97 @@ FP_GameEntityActionSprite FP_EntityActionStateMachine(FP_Game *game, TELY_Platfo
|
||||
TELY_AssetSpriteSheet *sheet = &game->smoochie_sprite_sheet;
|
||||
result.sheet = sheet;
|
||||
|
||||
if (*state == FP_EntitySmoochieState_Nil)
|
||||
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Idle);
|
||||
|
||||
if (*state == FP_EntitySmoochieState_Idle) {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.smoochie_walk_down);
|
||||
|
||||
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;
|
||||
|
||||
case FP_GameDirection_Down: {
|
||||
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) {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.smoochie_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) {
|
||||
switch (*state) {
|
||||
case FP_EntitySmoochieState_Nil: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Idle);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
if (*state == FP_EntitySmoochieState_AttackSide) {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, 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;
|
||||
}
|
||||
}
|
||||
case FP_EntitySmoochieState_Idle: {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.smoochie_walk_down);
|
||||
|
||||
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.anim = TELY_Asset_GetSpriteAnimation(sheet, desired_action_name);
|
||||
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)) {
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
case FP_GameDirection_Down: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_AttackDown);
|
||||
} break;
|
||||
case FP_GameDirection_Down: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_AttackDown);
|
||||
} break;
|
||||
}
|
||||
} else if (dir_vector.x || dir_vector.y) {
|
||||
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Run);
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
// NOTE: Also handles state transition
|
||||
if (action->sprite.anim->label != result.anim->label) {
|
||||
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result);
|
||||
}
|
||||
case FP_EntitySmoochieState_AttackDown: {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.smoochie_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_EntitySmoochieState_Idle);
|
||||
}
|
||||
} break;
|
||||
|
||||
if (!entity_has_velocity /*&& !has_collision*/) {
|
||||
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Idle);
|
||||
}
|
||||
case FP_EntitySmoochieState_AttackSide: {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, 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;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, desired_action_name);
|
||||
|
||||
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;
|
||||
|
||||
case FP_GameDirection_Down: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_AttackDown);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Also handles state transition
|
||||
if (action->sprite.anim->label != result.anim->label) {
|
||||
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result);
|
||||
}
|
||||
|
||||
if (!entity_has_velocity /*&& !has_collision*/) {
|
||||
FP_Game_EntityActionSetState(action, FP_EntitySmoochieState_Idle);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
if (*state == FP_EntitySmoochieState_AttackSide || *state == FP_EntitySmoochieState_AttackDown) {
|
||||
@ -579,7 +590,6 @@ FP_GameEntityActionSprite FP_EntityActionStateMachine(FP_Game *game, TELY_Platfo
|
||||
} else {
|
||||
entity->attack_box_size = {};
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case FP_EntityType_Merchant: {
|
||||
@ -587,14 +597,17 @@ FP_GameEntityActionSprite FP_EntityActionStateMachine(FP_Game *game, TELY_Platfo
|
||||
TELY_AssetSpriteSheet *sheet = &game->terry_merchant_sprite_sheet;
|
||||
result.sheet = sheet;
|
||||
|
||||
if (*state == FP_EntityTerryMerchantState_Nil)
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryMerchantState_Idle);
|
||||
switch (*state) {
|
||||
case FP_EntityTerryMerchantState_Nil: {
|
||||
FP_Game_EntityActionSetState(action, FP_EntityTerryMerchantState_Idle);
|
||||
} break;
|
||||
|
||||
if (*state == FP_EntityTerryMerchantState_Idle) {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_merchant);
|
||||
if (action->flags & FP_GameEntityActionFlag_StateTransition) {
|
||||
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result);
|
||||
}
|
||||
case FP_EntityTerryMerchantState_Idle: {
|
||||
result.anim = TELY_Asset_GetSpriteAnimation(sheet, g_anim_names.terry_merchant);
|
||||
if (action->flags & FP_GameEntityActionFlag_StateTransition) {
|
||||
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, result);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user