From 3a750822f6fc8306952950e4b083359e9172defd Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 25 Apr 2026 12:23:21 +0200 Subject: [PATCH] =?UTF-8?q?fix(player):=20la=20resoluci=C3=B3=20del=20sola?= =?UTF-8?q?pament=20en=20aterrar=20usa=20la=20base-box,=20no=20la=20hit-bo?= =?UTF-8?q?x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game/entities/player.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 2cb5664..1e1136d 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -515,10 +515,16 @@ void Player::resolveLandingOverlap() { if (all_players_ == nullptr) { return; } for (Player* other : *all_players_) { if (other == nullptr || other == this) { continue; } - const SDL_FRect MY_HIT = getHitBox(); - const SDL_FRect OT_HIT = other->getHitBox(); + // Usem la BASE-box (16×16, el cos sencer) per al test, no la + // hit-box (8×8 de contacte). Volem separar els cossos + // visualment: si fem servir només la hit-box, dos jugadors + // poden quedar amb les base-boxes solapades a mig sprite (un + // dins de l'altre) tot i tenir les hit-boxes ja apartades. La + // base-box dóna la separació real del cos. + const SDL_FRect MY_BOX = getBaseBox(); + const SDL_FRect OT_BOX = other->getBaseBox(); SDL_FRect inter; - if (!SDL_GetRectIntersectionFloat(&MY_HIT, &OT_HIT, &inter)) { continue; } + if (!SDL_GetRectIntersectionFloat(&MY_BOX, &OT_BOX, &inter)) { continue; } // Eix de separació: el que té els centres més separats. És // l'axis-aligned MTV "natural" — equivalent a empentar l'altre @@ -527,10 +533,10 @@ void Player::resolveLandingOverlap() { // li cau una mica per sobre i a la dreta, l'altre va cap a la // dreta-baix; si li cau directament al damunt (dx≈0), l'altre // s'aparta verticalment. - const float MCX = MY_HIT.x + (MY_HIT.w * 0.5F); - const float MCY = MY_HIT.y + (MY_HIT.h * 0.5F); - const float OCX = OT_HIT.x + (OT_HIT.w * 0.5F); - const float OCY = OT_HIT.y + (OT_HIT.h * 0.5F); + const float MCX = MY_BOX.x + (MY_BOX.w * 0.5F); + const float MCY = MY_BOX.y + (MY_BOX.h * 0.5F); + const float OCX = OT_BOX.x + (OT_BOX.w * 0.5F); + const float OCY = OT_BOX.y + (OT_BOX.h * 0.5F); const float DX = OCX - MCX; const float DY = OCY - MCY; float push_x = 0.0F;