| 1 |
#include "oodle.h" |
| 2 |
|
| 3 |
CSpriteExplodeEffect::CSpriteExplodeEffect(CSprite &s, int duration, double minVel, double randVel, const CRect &r, int xPieces, int yPieces, bool concurrent) |
| 4 |
: CExplodeEffect(s, duration, minVel, randVel, r, concurrent), xPieces(xPieces), yPieces(yPieces) |
| 5 |
{ |
| 6 |
} |
| 7 |
|
| 8 |
CSpriteExplodeEffect::CSpriteExplodeEffect(const CSpriteExplodeEffect &e) |
| 9 |
: CExplodeEffect(e) |
| 10 |
{ |
| 11 |
for (list<CParticle*>::iterator i = pieces.begin(); i != pieces.end(); ++i) |
| 12 |
{ |
| 13 |
pieces.push_back( new CSprite(*((CSprite*)(*i))) ); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
CExplodeEffect *CSpriteExplodeEffect::getCopy() |
| 18 |
{ |
| 19 |
return new CSpriteExplodeEffect(*this); |
| 20 |
} |
| 21 |
|
| 22 |
void CSpriteExplodeEffect::initialize() |
| 23 |
{ |
| 24 |
CEffect::initialize(); |
| 25 |
/*int xPieces = 4; |
| 26 |
int yPieces = 4;*/ |
| 27 |
int sHeight = s.getCurrentFrame()->getHeight(); |
| 28 |
int sWidth = s.getCurrentFrame()->getWidth(); |
| 29 |
int xSzPiece = sWidth / xPieces; |
| 30 |
int ySzPiece = sHeight / yPieces; |
| 31 |
CVector center = CVector(sWidth / xSzPiece, sHeight / ySzPiece); |
| 32 |
|
| 33 |
for (int x = 0; x < sWidth; x = min(sWidth, x + xSzPiece) ) |
| 34 |
{ |
| 35 |
for (int y = 0; y < sHeight; y = min(sHeight, y + ySzPiece) ) |
| 36 |
{ |
| 37 |
CVector p(x,y); |
| 38 |
CVector vel = (p - center); |
| 39 |
vel.setMag(randVel*(rand()%50/50.)+minVel); |
| 40 |
vel.setDir( vel.getDirRad() + (rand()%50/50.) * (rand()%50/50. > .5 ? -1 : 1)); |
| 41 |
|
| 42 |
CSprite* sprite = new CSprite(vel, CVector(x,y), s.getCurrentFrame()->getSection(x, y, min(sWidth - x, xSzPiece), min(sHeight - y, ySzPiece)), "static"); |
| 43 |
sprite->setRect(s.getRect()); |
| 44 |
//cout << "width = " << min(sWidth - x, xSzPiece) << ", height = " << min(sHeight - y, ySzPiece) << endl; |
| 45 |
//cout << "x: " << x << " y: " << y << endl; |
| 46 |
pieces.push_back( sprite ); |
| 47 |
numPieces++; |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
void CSpriteExplodeEffect::doUpdate() |
| 53 |
{ |
| 54 |
for (list<CParticle*>::iterator i = pieces.begin(); i != pieces.end(); ++i) |
| 55 |
{ |
| 56 |
unsigned int t = ticksElapsed(); |
| 57 |
if (t > 1000) { setDone(); return; } |
| 58 |
|
| 59 |
((CSprite*)(*i))->setScale( (1000-t) / (1000.) ); |
| 60 |
((CSprite*)(*i))->setRot( (1000-t) / (1000.) * 2 * PI); |
| 61 |
(*i)->update(); |
| 62 |
} |
| 63 |
if (gone >= numPieces) { |
| 64 |
setDone(); |
| 65 |
} |
| 66 |
} |