mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-22 23:18:01 +03:00
parts: fix GetPartsUpperLeftPos{X,Y}
Hitbox is stored in local coordinates. These functions return global coordinates.
This commit is contained in:
+3
-5
@@ -178,13 +178,11 @@ bool PE_IsCursorIn(int parts_no, int mouse_x, int mouse_y, int state)
|
||||
if (!parts)
|
||||
return false;
|
||||
|
||||
// TODO: this could be cached
|
||||
Rectangle hitbox = parts->states[state].common.hitbox;
|
||||
for (struct parts *parent = parts->parent; parent; parent = parent->parent) {
|
||||
hitbox.x += parent->local.pos.x;
|
||||
hitbox.y += parent->local.pos.y;
|
||||
if (parts->parent) {
|
||||
hitbox.x += parts->parent->global.pos.x;
|
||||
hitbox.y += parts->parent->global.pos.y;
|
||||
}
|
||||
|
||||
Point mouse_pos = { mouse_x, mouse_y };
|
||||
return SDL_PointInRect(&mouse_pos, &hitbox);
|
||||
}
|
||||
|
||||
+10
-2
@@ -1441,14 +1441,22 @@ int PE_GetPartsUpperLeftPosX(int parts_no, int state)
|
||||
{
|
||||
if (!parts_state_valid(--state))
|
||||
return 0;
|
||||
return parts_get(parts_no)->states[state].common.hitbox.x;
|
||||
struct parts *parts = parts_get(parts_no);
|
||||
int x = parts->states[state].common.hitbox.x;
|
||||
if (parts->parent)
|
||||
x += parts->parent->global.pos.x;
|
||||
return x;
|
||||
}
|
||||
|
||||
int PE_GetPartsUpperLeftPosY(int parts_no, int state)
|
||||
{
|
||||
if (!parts_state_valid(--state))
|
||||
return 0;
|
||||
return parts_get(parts_no)->states[state].common.hitbox.y;
|
||||
struct parts *parts = parts_get(parts_no);
|
||||
int y = parts->states[state].common.hitbox.y;
|
||||
if (parts->parent)
|
||||
y += parts->parent->global.pos.y;
|
||||
return y;
|
||||
}
|
||||
|
||||
int PE_GetPartsZ(int parts_no)
|
||||
|
||||
Reference in New Issue
Block a user