Skip to content

Commit cd5e567

Browse files
committed
Fully implemented MOSprite:GetAllPixelPositions()
1 parent 1b90c30 commit cd5e567

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Source/Entities/MOSprite.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,28 @@ std::vector<Vector>* MOSprite::GetAllPixelPositions(const Vector& origin, float
443443
std::vector<Vector>* posList = new std::vector<Vector>();
444444
CLAMP(m_FrameCount - 1, 0, whichFrame);
445445
BITMAP* sprite = m_aSprite[whichFrame];
446-
for (int y = 0; y < GetSpriteHeight(); y++) {
447-
for (int x = 0; x < GetSpriteWidth(); x++) {
448-
int pixelIndex = GetPixelIndex(x, y, whichFrame);
446+
BITMAP* temp = create_bitmap_ex(8, m_SpriteDiameter * m_Scale, m_SpriteDiameter * m_Scale);
447+
rectfill(temp, 0, 0, temp->w - 1, temp->h - 1, 0);
448+
Vector offset = Vector(temp->w / 2 + m_SpriteOffset.m_X, temp->h / 2 + m_SpriteOffset.m_Y);
449+
450+
if (!hflipped) {
451+
rotate_scaled_sprite(temp, sprite, offset.m_X, offset.m_Y, ftofix(GetAllegroAngle(-m_Rotation.GetDegAngle())), ftofix(m_Scale));
452+
} else {
453+
rotate_scaled_sprite_v_flip(temp, sprite, offset.m_X, offset.m_Y, ftofix(GetAllegroAngle(-m_Rotation.GetDegAngle())) + itofix(128), ftofix(m_Scale));
454+
}
455+
456+
for (int y = 0; y < temp->h; y++) {
457+
for (int x = 0; x < temp->w; x++) {
458+
int pixelIndex = getpixel(temp, x, y);
449459
if (includeTransparency || pixelIndex > 0) {
450-
Vector pixelPos = (Vector(x, y) + m_SpriteOffset).FlipX(hflipped).RadRotate(angle) + origin;
460+
Vector pixelPos = (Vector(x - temp->w / 2, y - temp->h / 2)) + origin;
451461
posList->push_back(pixelPos.GetRounded());
452462
}
453463
}
454464
}
455465

466+
destroy_bitmap(temp);
467+
temp = NULL;
456468
return posList;
457469
}
458470

0 commit comments

Comments
 (0)