Debian Codegraph @

src/effect/EffectDisintegrate.cpp

raw
1 /*
2 * Copyright (C) 2004 Ivo Danihelka ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9 #include "EffectDisintegrate.h"
10
11 #include "SurfaceLock.h"
12 #include "PixelTool.h"
13 #include "Random.h"
14
15 const char *EffectDisintegrate::NAME = "disintegrate";
16 //-----------------------------------------------------------------
17 /**
18 * Start as not disintegrated.
19 */
20 EffectDisintegrate::EffectDisintegrate()
21 {
22 m_disint = DISINT_START;
23 }
24 //-----------------------------------------------------------------
25 void
26 EffectDisintegrate::updateEffect()
27 {
28 if (m_disint > 0) {
29 m_disint -= DISINT_SPEED;
30 if (m_disint < 0) {
31 m_disint = 0;
32 }
33 }
34 }
35 //-----------------------------------------------------------------
36 /**
37 * Returns true for object for who the disint effect is finished.
38 */
39 bool
40 EffectDisintegrate::isDisintegrated() const
41 {
42 return 0 == m_disint;
43 }
44 //-----------------------------------------------------------------
45 bool
46 EffectDisintegrate::isInvisible() const
47 {
48 return isDisintegrated();
49 }
50 //-----------------------------------------------------------------
51 /**
52 * Disintegration effect.
53 * Draw only some pixels.
54 */
55 void
56 EffectDisintegrate::blit(SDL_Surface *screen, SDL_Surface *surface,
57 int x, int y)
58 {
59 SurfaceLock lock1(screen);
60 SurfaceLock lock2(surface);
61
62 for (int py = 0; py < surface->h; ++py) {
63 for (int px = 0; px < surface->w; ++px) {
64 if (Random::aByte(py * surface->w + px) < m_disint) {
65 SDL_Color pixel = PixelTool::getColor(surface, px, py);
66 if (pixel.unused == 255) {
67 PixelTool::putColor(screen, x + px, y + py, pixel);
68 }
69 }
70 }
71 }
72 }
73