| 1 |
#include "oodle.h" |
| 2 |
|
| 3 |
// Effect code contributed by Keith Bare |
| 4 |
|
| 5 |
CBlackEffect::CBlackEffect(int duration, bool concurrent, const CSurface &fx) |
| 6 |
: CEffect(0, concurrent), duration(duration), black(fx), src(fx) |
| 7 |
{ |
| 8 |
black.fill(COLOR_BLACK); |
| 9 |
black.setAlpha(SDL_SRCALPHA, SDL_ALPHA_OPAQUE); |
| 10 |
} |
| 11 |
|
| 12 |
CBlackEffect* CBlackEffect::getCopy() |
| 13 |
{ |
| 14 |
return new CBlackEffect(*this); |
| 15 |
} |
| 16 |
|
| 17 |
void CBlackEffect::draw(CSurface &s, int x, int y) |
| 18 |
{ |
| 19 |
// Calculate how grey it should be |
| 20 |
/*unsigned int tick = CEffect::ticksElapsed(); |
| 21 |
Uint8 greyness = (Uint8) (254 * (((double)duration-tick) / duration)); |
| 22 |
|
| 23 |
if (((double)duration-tick) <= 0) |
| 24 |
{ |
| 25 |
setConcurrent(); |
| 26 |
greyness = 0; |
| 27 |
} |
| 28 |
|
| 29 |
fx.lock(); |
| 30 |
|
| 31 |
for (int y = 0; y < fx.getHeight(); y++) |
| 32 |
{ |
| 33 |
for (int x = 0; x < fx.getWidth(); x++) |
| 34 |
{ |
| 35 |
CColor pval; |
| 36 |
fx.getPixel(x, y, pval); |
| 37 |
|
| 38 |
// Don't mess with color key pixels |
| 39 |
if (pval.getR() != 255 || pval.getG() != 255 || pval.getB() != 255) |
| 40 |
{ |
| 41 |
if (pval.getR() > greyness) |
| 42 |
{ |
| 43 |
pval.setR(greyness); |
| 44 |
} |
| 45 |
|
| 46 |
if (pval.getG() > greyness) |
| 47 |
{ |
| 48 |
pval.setG(greyness); |
| 49 |
} |
| 50 |
|
| 51 |
if (pval.getB() > greyness) |
| 52 |
{ |
| 53 |
pval.setB(greyness); |
| 54 |
} |
| 55 |
|
| 56 |
fx.setPixel(x, y, pval); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
fx.unlock();*/ |
| 62 |
Uint32 tick = ticksElapsed(); |
| 63 |
if (((double)duration-tick) <= 0) |
| 64 |
{ |
| 65 |
s.blit(black, x, y); |
| 66 |
setConcurrent(); |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
black.setAlpha(SDL_SRCALPHA, 255-(255*(((double)duration - tick) / duration))); |
| 71 |
s.blit(src, x, y); |
| 72 |
s.blit(black, x, y); |
| 73 |
|
| 74 |
} |