fp: Collect coins on entity defeat

This commit is contained in:
doyle 2023-10-06 21:57:34 +11:00
parent b5c8c45769
commit a591254d5b
3 changed files with 22 additions and 5 deletions

View File

@ -641,7 +641,11 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform
Dqn_Rect entity_hit_box = FP_Game_CalcEntityWorldHitBox(game, entity->handle);
Dqn_V2 projectile_pos = entity_hit_box.pos + entity->attack_box_offset;
Dqn_V2 projectile_acceleration = FP_Game_MetersToPixelsV2(game, dir_vector * 0.25f);
FP_Entity_CreatePhoneMessageProjectile(game, projectile_pos, projectile_acceleration, "Phone Message Projectile");
FP_Entity_CreatePhoneMessageProjectile(game,
entity->handle,
projectile_pos,
projectile_acceleration,
"Phone Message Projectile");
} else {
entity->attack_box_size = entity->local_hit_box_size;
TELY_Audio_Play(audio, game->audio[FP_GameAudio_TerryHit], 1.f);
@ -1739,7 +1743,7 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
if (entity->type == FP_EntityType_Terry) {
entity->terry_mobile_data_plan =
DQN_MIN(entity->terry_mobile_data_plan + (FP_TERRY_MOBILE_DATA_PER_RANGE_ATTACK * .25f * PHYSICS_STEP),
DQN_MIN(entity->terry_mobile_data_plan + DQN_CAST(Dqn_usize)(FP_TERRY_MOBILE_DATA_PER_RANGE_ATTACK * .25f * PHYSICS_STEP),
entity->terry_mobile_data_plan_cap);
}
@ -1888,9 +1892,15 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
// NOTE: Do HP =========================================================================
defender->hp -= 1;
if (defender->hp <= 0)
if (defender->hp <= 0) {
defender->is_dying = true;
FP_GameEntity *coin_receiver = FP_Game_GetEntity(game, attacker->projectile_owner);
if (FP_Game_IsNilEntity(coin_receiver))
coin_receiver = attacker;
coin_receiver->coins += 1;
}
// NOTE: Kickback ======================================================================
#if 0
Dqn_V2 defender_world_pos = Dqn_Rect_Center(defender_box);
@ -2209,6 +2219,9 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
"%$$$d/%$$$d",
player->terry_mobile_data_plan,
player->terry_mobile_data_plan_cap);
next_pos.y += TELY_Render_FontHeight(renderer, &platform->assets);
TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "$%I64u", player->coins);
TELY_Render_PopFont(renderer);
}

View File

@ -666,7 +666,7 @@ static FP_GameEntityHandle FP_Entity_CreateAirportTerry(FP_Game *game, Dqn_V2 po
return result;
}
static FP_GameEntityHandle FP_Entity_CreatePhoneMessageProjectile(FP_Game *game, Dqn_V2 pos, Dqn_V2 velocity, DQN_FMT_STRING_ANNOTATE char const *fmt, ...)
static FP_GameEntityHandle FP_Entity_CreatePhoneMessageProjectile(FP_Game *game, FP_GameEntityHandle owner, Dqn_V2 pos, Dqn_V2 velocity, DQN_FMT_STRING_ANNOTATE char const *fmt, ...)
{
va_list args;
va_start(args, fmt);
@ -688,6 +688,7 @@ static FP_GameEntityHandle FP_Entity_CreatePhoneMessageProjectile(FP_Game *game,
entity->attack_box_offset = entity->local_hit_box_offset;
entity->attack_box_size = entity->local_hit_box_size;
entity->ttl_end_timestamp = game->clock_ms + 1000;
entity->projectile_owner = owner;
uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER;
FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite);

View File

@ -190,11 +190,14 @@ struct FP_GameEntity
Dqn_V2 local_pos;
Dqn_f64 alive_time_s;
Dqn_FArray<FP_GameShape, 4> shapes;
Dqn_FArray<FP_GameEntityHandle, 4> projectiles;
FP_GameEntityHandle projectile_owner;
uint64_t ttl_end_timestamp;
FP_SentinelList<FP_GameEntityHandle> buildings_visited;
Dqn_usize terry_mobile_data_plan;
Dqn_usize terry_mobile_data_plan_cap;
Dqn_usize coins;
};
struct FP_GameEntityIterator