Add hp, Add attack collision detection, Add destroy on death
This commit was merged in pull request #3.
This commit is contained in:
@@ -815,6 +815,36 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
|
||||
entity->local_pos += delta_pos;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Attack collisions =================================================================
|
||||
{
|
||||
// NOTE: Check if there's an active attack box
|
||||
if (entity->attack_box_size.x != 0 && entity->attack_box_size.y != 0) {
|
||||
Dqn_Rect entity_attack_box = {};
|
||||
// NOTE: Convert from centre origin to top-left origin
|
||||
entity_attack_box.pos = entity->local_pos + entity->attack_box_offset - (entity->attack_box_size * 0.5f);
|
||||
entity_attack_box.size = entity->attack_box_size;
|
||||
|
||||
for (FP_GameEntityIterator target_it = {}; FP_Game_DFSPreOrderWalkEntityTree(game, &target_it, game->root_entity);) {
|
||||
FP_GameEntity *target = target_it.entity;
|
||||
if (target->handle == entity->handle)
|
||||
continue;
|
||||
|
||||
// TODO(josh): This check should be updated based on an entity attackable flag
|
||||
if (target->flags & FP_GameEntityFlag_Attackable) {
|
||||
Dqn_Rect target_world_hit_box = FP_Game_CalcEntityWorldHitBox(game, target->handle);
|
||||
|
||||
if (Dqn_Rect_Intersects(entity_attack_box, target_world_hit_box)) {
|
||||
target->hp -= 1;
|
||||
|
||||
if (target->hp <= 0) {
|
||||
FP_Game_DeleteEntity(game, target->handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Move entity by mouse ==============================================================
|
||||
if (game->active_entity == entity->handle && entity->flags & FP_GameEntityFlag_MoveByMouse) {
|
||||
|
||||
Reference in New Issue
Block a user