fix(player): la resolució del solapament en aterrar usa la base-box, no la hit-box
This commit is contained in:
1 parent
06ff11d563
commit
3a750822f6
1 file changed
+13
-7
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user