00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "EffectZx.h"
00010
00011 #include "SurfaceLock.h"
00012 #include "PixelTool.h"
00013 #include "PixelIterator.h"
00014 #include "Random.h"
00015
00016 const double EffectZx::STRIPE_STANDARD = 38.5;
00017 const double EffectZx::STRIPE_NARROW = 3.4;
00018
00019
00020
00021
00022 EffectZx::EffectZx()
00023 {
00024 m_zx = ZX1;
00025 m_phase = 0;
00026 m_countHeight = 0;
00027 m_stripeHeight = STRIPE_STANDARD;
00028 }
00029
00030
00031
00032
00033 void
00034 EffectZx::updateEffect()
00035 {
00036 m_phase = (m_phase + 1) % 500;
00037 if (m_phase == 1) {
00038 m_zx = ZX1;
00039 m_stripeHeight = STRIPE_STANDARD;
00040 }
00041 else if (2 <= m_phase && m_phase <= 51) {
00042 m_stripeHeight = (m_stripeHeight * 3
00043 * (0.97 + Random::randomReal(0.06))
00044 + STRIPE_STANDARD) / 4.0;
00045 }
00046 else if (m_phase == 52) {
00047 m_zx = ZX3;
00048 m_stripeHeight = STRIPE_NARROW;
00049 }
00050 else {
00051 m_stripeHeight = (m_stripeHeight * 3
00052 * (0.95 + Random::randomReal(0.1))
00053 + STRIPE_NARROW) / 4.0;
00054 }
00055 }
00056
00057
00058
00059
00060 void
00061 EffectZx::blit(SDL_Surface *screen, SDL_Surface *surface, int x, int y)
00062 {
00063 SurfaceLock lock1(screen);
00064 SurfaceLock lock2(surface);
00065
00066 Uint32 colorZX1 = PixelTool::convertColor(screen->format,
00067 PixelTool::getColor(surface, 0, 0));
00068 Uint32 colorZX2 = PixelTool::convertColor(screen->format,
00069 PixelTool::getColor(surface, 0, surface->h - 1));
00070 Uint32 colorZX3 = PixelTool::convertColor(screen->format,
00071 PixelTool::getColor(surface, surface->w - 1, 0));
00072 Uint32 colorZX4 = PixelTool::convertColor(screen->format,
00073 PixelTool::getColor(surface, surface->w - 1, surface->h - 1));
00074
00075 PixelIterator pit(surface);
00076 for (int py = 0; py < surface->h; ++py) {
00077 m_countHeight++;
00078 if (m_countHeight > m_stripeHeight) {
00079 m_countHeight -= m_stripeHeight;
00080 switch (m_zx) {
00081 case ZX1:
00082 m_zx = ZX2;
00083 break;
00084 case ZX2:
00085 m_zx = ZX1;
00086 break;
00087 case ZX3:
00088 m_zx = ZX4;
00089 break;
00090 default:
00091 m_zx = ZX3;
00092 break;
00093 }
00094 }
00095
00096 Uint32 usedColor;
00097 switch (m_zx) {
00098 case ZX1:
00099 usedColor = colorZX1;
00100 break;
00101 case ZX2:
00102 usedColor = colorZX2;
00103 break;
00104 case ZX3:
00105 usedColor = colorZX3;
00106 break;
00107 default:
00108 usedColor = colorZX4;
00109 break;
00110 }
00111
00112 for (int px = 0; px < surface->w; ++px) {
00113 if (!pit.isTransparent()) {
00114 PixelTool::putPixel(screen,
00115 x + px, y + py, usedColor);
00116 }
00117 pit.inc();
00118 }
00119 }
00120 }
00121