@@ -439,46 +439,42 @@ void MOSprite::SetAllSpritePixelIndexes(int whichFrame, int colorIndex, int igno
439
439
}
440
440
}
441
441
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);
460
447
}
448
+ return -1 ;
461
449
}
462
450
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 ) {
464
452
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);
468
460
rectfill (temp, 0 , 0 , temp->w - 1 , temp->h - 1 , 0 );
469
461
Vector tempCentre = Vector (temp->w / 2 , temp->h / 2 );
470
462
Vector spriteCentre = Vector (sprite->w / 2 , sprite->h / 2 );
471
- Vector offset = (tempCentre + (m_SpriteOffset + spriteCentre).GetXFlipped (m_HFlipped).RadRotate (m_Rotation.GetRadAngle ()) - spriteCentre);
472
463
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 );
475
466
} 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
+ }
477
473
}
478
474
479
475
for (int y = 0 ; y < temp->h ; y++) {
480
476
for (int x = 0 ; x < temp->w ; x++) {
481
- int pixelIndex = getpixel (temp, x, y);
477
+ int pixelIndex = _getpixel (temp, x, y);
482
478
if (pixelIndex >= 0 && (pixelIndex != ignoreIndex) != invert) {
483
479
Vector pixelPos = (Vector (x, y) - tempCentre) + origin;
484
480
posList->push_back (pixelPos);
@@ -490,6 +486,40 @@ std::vector<Vector>* MOSprite::GetAllPixelPositions(const Vector& origin, float
490
486
return posList;
491
487
}
492
488
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
+
493
523
void MOSprite::Update () {
494
524
MovableObject::Update ();
495
525
0 commit comments