| 1 |
#include "oodle.h" |
| 2 |
|
| 3 |
CPixelExplodeEffect::CPixelExplodeEffect(int duration, bool concurrent, CRect r, CSprite &s) |
| 4 |
: CExplodeEffect(s, duration, minVel, randVel, r, concurrent) |
| 5 |
{ |
| 6 |
} |
| 7 |
|
| 8 |
CPixelExplodeEffect::CPixelExplodeEffect(CExplodeEffect &e) |
| 9 |
: CExplodeEffect(e) |
| 10 |
{ |
| 11 |
for (list<CParticle*>::iterator i = pieces.begin(); i != pieces.end(); ++i) |
| 12 |
{ |
| 13 |
pieces.push_back( new CPixel(*((CPixel*)(*i))) ); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
CExplodeEffect *CPixelExplodeEffect::getCopy() |
| 18 |
{ |
| 19 |
return new CPixelExplodeEffect(*this); |
| 20 |
} |
| 21 |
|
| 22 |
void CPixelExplodeEffect::initialize() |
| 23 |
{ |
| 24 |
CEffect::initialize(); |
| 25 |
int sHeight = s.getCurrentFrame()->getHeight(); |
| 26 |
int sWidth = s.getCurrentFrame()->getWidth(); |
| 27 |
CVector center = CVector(sWidth/2, sHeight/2); |
| 28 |
CSurface *frame; |
| 29 |
|
| 30 |
// If the sprite's frame changes before it is unlocked, we may be |
| 31 |
// screwed. It shouldn't ever happen though, as s.update() should |
| 32 |
// never be called before frame is unlocked. |
| 33 |
frame = s.getCurrentFrame(); |
| 34 |
frame->lock(); |
| 35 |
|
| 36 |
for (int x = 0; x < sWidth; x++ ) |
| 37 |
{ |
| 38 |
for (int y = 0; y < sHeight; y++) |
| 39 |
{ |
| 40 |
CVector p(x,y); |
| 41 |
CVector vel = (p - center); |
| 42 |
vel.setMag(100*(rand()%50/50.)+25); |
| 43 |
vel.setDir( vel.getDirRad() + (rand()%50/50.) * (rand()%50/50. > .5 ? -1 : 1)); |
| 44 |
|
| 45 |
CColor pcolor; |
| 46 |
frame->getPixel(x, y, pcolor); |
| 47 |
CPixel* pixel = new CPixel(vel, CVector(x,y), pcolor); |
| 48 |
|
| 49 |
pieces.push_back( pixel ); |
| 50 |
numPieces++; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
// See the note above. |
| 55 |
frame->unlock(); |
| 56 |
} |
| 57 |
|
| 58 |
void CPixelExplodeEffect::doUpdate() |
| 59 |
{ |
| 60 |
CTimer timer; |
| 61 |
for (list<CParticle*>::iterator i = pieces.begin(); i != pieces.end(); ++i) |
| 62 |
{ |
| 63 |
unsigned int t = ticksElapsed(); |
| 64 |
if (t > duration) { setDone(); return; } |
| 65 |
|
| 66 |
(*i)->update(); |
| 67 |
} |
| 68 |
if (gone >= numPieces) { |
| 69 |
setDone(); |
| 70 |
} |
| 71 |
} |