| 1 |
#include "oodle.h" |
| 2 |
|
| 3 |
// Effect code contributed by Keith Bare |
| 4 |
|
| 5 |
CExplodeEffect::CExplodeEffect(CSprite &s, int duration, double minVel, double randVel, const CRect &r, bool concurrent) |
| 6 |
: CEffect(0, concurrent), s(s), duration(duration), gone(0), r(r), numPieces(0), |
| 7 |
minVel(minVel), randVel(randVel) |
| 8 |
{ |
| 9 |
} |
| 10 |
|
| 11 |
CExplodeEffect::~CExplodeEffect() |
| 12 |
{ |
| 13 |
for (list<CParticle*>::iterator i = pieces.begin(); i != pieces.end(); ++i) |
| 14 |
{ |
| 15 |
delete (*i); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
void CExplodeEffect::draw(CSurface &s, int x, int y) |
| 20 |
{ |
| 21 |
for (list<CParticle*>::iterator i = pieces.begin(); i != pieces.end(); ++i) |
| 22 |
{ |
| 23 |
(*i)->setPosRel(x, y); |
| 24 |
(*i)->draw(s); |
| 25 |
if (r != CRect(0,0,0,0)) |
| 26 |
{ |
| 27 |
if ( !r.contains((*i)->getPos()) ) |
| 28 |
{ |
| 29 |
gone++; |
| 30 |
//cout << "out of bounds for {" << this << "} = {" << *i << "} [" << gone << "/" << numPieces << "]" << endl; |
| 31 |
delete *i; |
| 32 |
list<CParticle*>::iterator tmp = i; |
| 33 |
tmp++; |
| 34 |
pieces.erase(i); |
| 35 |
i = tmp; |
| 36 |
} |
| 37 |
else |
| 38 |
{ |
| 39 |
(*i)->setPosRel(-x, -y); |
| 40 |
} |
| 41 |
} |
| 42 |
else |
| 43 |
{ |
| 44 |
(*i)->setPosRel(-x, -y); |
| 45 |
} |
| 46 |
} |
| 47 |
} |