fp: Allow attacks to interrupt entity

This commit is contained in:
doyle 2023-10-23 20:54:28 +11:00
parent 98bcb9e56f
commit f5de988246
3 changed files with 78 additions and 31 deletions

View File

@ -507,30 +507,7 @@ static void FP_AppendMobSpawnerWaypoints(FP_Game *game, FP_GameEntityHandle src_
}
}
bool FP_Game_KeyBindIsPressed(TELY_PlatformInput const *input, FP_GameControls const *controls, FP_GameKeyBind key_bind)
{
bool result = false;
if (controls->mode == FP_GameControlMode_Keyboard) {
result = TELY_Platform_InputScanCodeIsPressed(input, key_bind.scan_code);
} else {
result = TELY_Platform_InputGamepadKeyIsPressed(input, controls->gamepad_index, key_bind.gamepad_key);
}
return result;
}
bool FP_Game_KeyBindIsDown(TELY_PlatformInput const *input, FP_GameControls const *controls, FP_GameKeyBind key_bind)
{
bool result = false;
if (controls->mode == FP_GameControlMode_Keyboard) {
result = TELY_Platform_InputScanCodeIsDown(input, key_bind.scan_code);
} else {
result = TELY_Platform_InputGamepadKeyIsDown(input, controls->gamepad_index, key_bind.gamepad_key);
}
return result;
}
void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_PlatformInput *input, FP_GameEntity *entity, Dqn_V2 *acceleration_meters_per_s)
static void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_PlatformInput *input, FP_GameEntity *entity, Dqn_V2 *acceleration_meters_per_s)
{
TELY_AssetSpriteSheet *sheet = &game->atlas_sprite_sheet;
FP_GameEntityAction *action = &entity->action;
@ -1323,7 +1300,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform
}
}
void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input, TELY_Audio *audio)
static void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input, TELY_Audio *audio)
{
Dqn_Profiler_ZoneScopeWithIndex("FP_Update", FP_ProfileZone_FPUpdate);
@ -2186,13 +2163,12 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
continue;
}
bool god_mode_override = false;
bool god_mode_override = false;
bool attacker_is_player = false;
if (game->play.god_mode) {
for (FP_GameEntityHandle player : game->play.players) {
if (player == defender->handle) {
god_mode_override = true;
break;
}
god_mode_override |= player == defender->handle;
attacker_is_player |= player == attacker->handle;
}
}
@ -2214,6 +2190,55 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
defender->is_dying = true;
}
// NOTE: Interrupt hit entity =====================================================
if (attacker_is_player) {
switch (defender->type) {
case FP_EntityType_Catfish: {
FP_Game_EntityTransitionState(game, defender, FP_EntityCatfishState_Idle);
defender->last_attack_timestamp = game->play.clock_ms;
} break;
case FP_EntityType_Terry: {
FP_Game_EntityTransitionState(game, defender, FP_EntityTerryState_Idle);
defender->last_attack_timestamp = game->play.clock_ms;
} break;
case FP_EntityType_Perry: {
FP_Game_EntityTransitionState(game, defender, FP_EntityTerryState_Idle);
defender->last_attack_timestamp = game->play.clock_ms;
} break;
case FP_EntityType_Clinger: {
FP_Game_EntityTransitionState(game, defender, FP_EntityClingerState_Idle);
defender->last_attack_timestamp = game->play.clock_ms;
} break;
case FP_EntityType_Smoochie: {
FP_Game_EntityTransitionState(game, defender, FP_EntitySmoochieState_Idle);
defender->last_attack_timestamp = game->play.clock_ms;
} break;
case FP_EntityType_Nil: break;
case FP_EntityType_AirportTerry: break;
case FP_EntityType_AirportTerryPlane: break;
case FP_EntityType_ChurchTerry: break;
case FP_EntityType_ClubTerry: break;
case FP_EntityType_Heart: break;
case FP_EntityType_KennelTerry: break;
case FP_EntityType_Map: break;
case FP_EntityType_MerchantGraveyard: break;
case FP_EntityType_MerchantGym: break;
case FP_EntityType_MerchantPhoneCompany: break;
case FP_EntityType_MerchantTerry: break;
case FP_EntityType_MobSpawner: break;
case FP_EntityType_PortalMonkey: break;
case FP_EntityType_PhoneMessageProjectile: break;
case FP_EntityType_Billboard: break;
case FP_EntityType_Count: break;
}
}
// NOTE: Kickback ======================================================================
#if 0
Dqn_V2 defender_world_pos = Dqn_Rect_Center(defender_box);
@ -2321,7 +2346,7 @@ static Dqn_String8 FP_ScanCodeToLabel(Dqn_Arena *arena, TELY_PlatformInputScanCo
return result;
}
void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, TELY_Audio *audio)
static void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, TELY_Audio *audio)
{
Dqn_Profiler_ZoneScopeWithIndex("FP_Render", FP_ProfileZone_FPRender);
TELY_PlatformInput *input = &platform->input;

View File

@ -3,6 +3,28 @@
#include "feely_pona_unity.h"
#endif
static bool FP_Game_KeyBindIsPressed(TELY_PlatformInput const *input, FP_GameControls const *controls, FP_GameKeyBind key_bind)
{
bool result = false;
if (controls->mode == FP_GameControlMode_Keyboard) {
result = TELY_Platform_InputScanCodeIsPressed(input, key_bind.scan_code);
} else {
result = TELY_Platform_InputGamepadKeyIsPressed(input, controls->gamepad_index, key_bind.gamepad_key);
}
return result;
}
static bool FP_Game_KeyBindIsDown(TELY_PlatformInput const *input, FP_GameControls const *controls, FP_GameKeyBind key_bind)
{
bool result = false;
if (controls->mode == FP_GameControlMode_Keyboard) {
result = TELY_Platform_InputScanCodeIsDown(input, key_bind.scan_code);
} else {
result = TELY_Platform_InputGamepadKeyIsDown(input, controls->gamepad_index, key_bind.gamepad_key);
}
return result;
}
static bool operator==(FP_GameEntityHandle const &lhs, FP_GameEntityHandle const &rhs)
{
bool result = lhs.id == rhs.id;

Binary file not shown.