Skip to content

Commit e4bacc0

Browse files
committed
Updated changelog, added Materal::GetColorIndex(), updated MOSprite bitmap manipulation functions sorry i can't remember all the the changes but they're good i promise
1 parent 2f53be3 commit e4bacc0

File tree

1 file changed

+57
-27
lines changed

1 file changed

+57
-27
lines changed

Source/Entities/MOSprite.cpp

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -439,46 +439,42 @@ void MOSprite::SetAllSpritePixelIndexes(int whichFrame, int colorIndex, int igno
439439
}
440440
}
441441

442-
void MOSprite::SetPixelIndex(int x, int y, unsigned int whichFrame, int colorIndex, int ignoreIndex, bool invert) {
443-
if (!m_SpriteModified) {
444-
std::vector<BITMAP*> spriteList;
445-
446-
for (BITMAP* sprite: m_aSprite) {
447-
BITMAP* spriteCopy = create_bitmap_ex(8, sprite->w, sprite->h);
448-
rectfill(spriteCopy, 0, 0, spriteCopy->w - 1, spriteCopy->h - 1, 0);
449-
draw_sprite(spriteCopy, sprite, 0, 0);
450-
spriteList.push_back(spriteCopy);
451-
}
452-
453-
m_aSprite = spriteList;
454-
m_SpriteModified = true;
455-
}
456-
457-
BITMAP* targetSprite = m_aSprite[CLAMP(m_FrameCount - 1, 0, whichFrame)];
458-
if (ignoreIndex < 0 || (getpixel(targetSprite, x, y) == ignoreIndex) != invert) {
459-
putpixel(targetSprite, x, y, colorIndex);
442+
int MOSprite::GetSpritePixelIndex(int x, int y, int whichFrame) const {
443+
unsigned int clampedFrame = std::max(std::min(whichFrame, static_cast<int>(m_FrameCount) - 1), 0);
444+
BITMAP* targetSprite = m_aSprite[clampedFrame];
445+
if (is_inside_bitmap(targetSprite, x, y, 0)) {
446+
return _getpixel(targetSprite, x, y);
460447
}
448+
return -1;
461449
}
462450

463-
std::vector<Vector>* MOSprite::GetAllPixelPositions(const Vector& origin, float angle, bool hflipped, unsigned int whichFrame, int ignoreIndex, bool invert) {
451+
std::vector<Vector>* MOSprite::GetAllSpritePixelPositions(const Vector& origin, float angle, bool hflipped, int whichFrame, int ignoreIndex, bool invert, bool includeChildren) {
464452
std::vector<Vector>* posList = new std::vector<Vector>();
465-
CLAMP(m_FrameCount - 1, 0, whichFrame);
466-
BITMAP* sprite = m_aSprite[whichFrame];
467-
BITMAP* temp = create_bitmap_ex(8, m_SpriteDiameter, m_SpriteDiameter);
453+
unsigned int clampedFrame = std::max(std::min(whichFrame, static_cast<int>(m_FrameCount) - 1), 0);
454+
int spriteSize = m_SpriteDiameter;
455+
if (includeChildren && dynamic_cast<MOSRotating*>(this)) {
456+
spriteSize = dynamic_cast<MOSRotating*>(this)->GetDiameter();
457+
}
458+
BITMAP* sprite = m_aSprite[clampedFrame];
459+
BITMAP* temp = create_bitmap_ex(8, spriteSize, spriteSize);
468460
rectfill(temp, 0, 0, temp->w - 1, temp->h - 1, 0);
469461
Vector tempCentre = Vector(temp->w / 2, temp->h / 2);
470462
Vector spriteCentre = Vector(sprite->w / 2, sprite->h / 2);
471-
Vector offset = (tempCentre + (m_SpriteOffset + spriteCentre).GetXFlipped(m_HFlipped).RadRotate(m_Rotation.GetRadAngle()) - spriteCentre);
472463

473-
if (!hflipped) {
474-
rotate_scaled_sprite(temp, sprite, offset.m_X, offset.m_Y, ftofix(GetAllegroAngle(-m_Rotation.GetDegAngle())), ftofix(m_Scale));
464+
if (includeChildren) {
465+
Draw(temp, m_Pos - tempCentre);
475466
} else {
476-
rotate_scaled_sprite_v_flip(temp, sprite, offset.m_X, offset.m_Y, ftofix(GetAllegroAngle(-m_Rotation.GetDegAngle())) + itofix(128), ftofix(m_Scale));
467+
Vector offset = (tempCentre + (m_SpriteOffset + spriteCentre).GetXFlipped(m_HFlipped).RadRotate(m_Rotation.GetRadAngle()) - spriteCentre);
468+
if (!hflipped) {
469+
rotate_scaled_sprite(temp, sprite, offset.m_X, offset.m_Y, ftofix(GetAllegroAngle(-m_Rotation.GetDegAngle())), ftofix(m_Scale));
470+
} else {
471+
rotate_scaled_sprite_v_flip(temp, sprite, offset.m_X, offset.m_Y, ftofix(GetAllegroAngle(-m_Rotation.GetDegAngle())) + itofix(128), ftofix(m_Scale));
472+
}
477473
}
478474

479475
for (int y = 0; y < temp->h; y++) {
480476
for (int x = 0; x < temp->w; x++) {
481-
int pixelIndex = getpixel(temp, x, y);
477+
int pixelIndex = _getpixel(temp, x, y);
482478
if (pixelIndex >= 0 && (pixelIndex != ignoreIndex) != invert) {
483479
Vector pixelPos = (Vector(x, y) - tempCentre) + origin;
484480
posList->push_back(pixelPos);
@@ -490,6 +486,40 @@ std::vector<Vector>* MOSprite::GetAllPixelPositions(const Vector& origin, float
490486
return posList;
491487
}
492488

489+
bool MOSprite::SetSpritePixelIndex(int x, int y, int whichFrame, int colorIndex, int ignoreIndex, bool invert) {
490+
if (!m_SpriteModified) {
491+
std::vector<BITMAP*> spriteList;
492+
493+
for (BITMAP* sprite : m_aSprite) {
494+
BITMAP* spriteCopy = create_bitmap_ex(8, sprite->w, sprite->h);
495+
rectfill(spriteCopy, 0, 0, spriteCopy->w - 1, spriteCopy->h - 1, 0);
496+
draw_sprite(spriteCopy, sprite, 0, 0);
497+
spriteList.push_back(spriteCopy);
498+
}
499+
500+
m_aSprite = spriteList;
501+
m_SpriteModified = true;
502+
}
503+
504+
unsigned int clampedFrame = std::max(std::min(whichFrame, static_cast<int>(m_FrameCount) - 1), 0);
505+
BITMAP* targetSprite = m_aSprite[clampedFrame];
506+
if (is_inside_bitmap(targetSprite, x, y, 0) && (ignoreIndex < 0 || (_getpixel(targetSprite, x, y) != ignoreIndex) != invert)) {
507+
_putpixel(targetSprite, x, y, colorIndex);
508+
return true;
509+
}
510+
return false;
511+
}
512+
513+
void MOSprite::SetAllSpritePixelIndexes(int whichFrame, int colorIndex, int ignoreIndex, bool invert) {
514+
unsigned int clampedFrame = std::max(std::min(whichFrame, static_cast<int>(m_FrameCount) - 1), 0);
515+
BITMAP* targetSprite = m_aSprite[clampedFrame];
516+
for (int y = 0; y < targetSprite->h; y++) {
517+
for (int x = 0; x < targetSprite->w; x++) {
518+
SetSpritePixelIndex(x, y, clampedFrame, colorIndex, ignoreIndex, invert);
519+
}
520+
}
521+
}
522+
493523
void MOSprite::Update() {
494524
MovableObject::Update();
495525

0 commit comments

Comments
 (0)