| 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 "EffectZx.h" |
| 10 |
|
| 11 |
#include "SurfaceLock.h" |
| 12 |
#include "PixelTool.h" |
| 13 |
#include "PixelIterator.h" |
| 14 |
#include "Random.h" |
| 15 |
|
| 16 |
const char *EffectZx::NAME = "zx"; |
| 17 |
const double EffectZx::STRIPE_STANDARD = 38.5; |
| 18 |
const double EffectZx::STRIPE_NARROW = 3.4; |
| 19 |
//----------------------------------------------------------------- |
| 20 |
/** |
| 21 |
* Read colors from all four corners. |
| 22 |
*/ |
| 23 |
EffectZx::EffectZx() |
| 24 |
{ |
| 25 |
m_zx = ZX1; |
| 26 |
m_phase = 0; |
| 27 |
m_countHeight = 0; |
| 28 |
m_stripeHeight = STRIPE_STANDARD; |
| 29 |
} |
| 30 |
//----------------------------------------------------------------- |
| 31 |
/** |
| 32 |
* Update sprite height as ZX Spectrum does. |
| 33 |
*/ |
| 34 |
void |
| 35 |
EffectZx::updateEffect() |
| 36 |
{ |
| 37 |
m_phase = (m_phase + 1) % 500; |
| 38 |
if (m_phase == 1) { |
| 39 |
m_zx = ZX1; |
| 40 |
m_stripeHeight = STRIPE_STANDARD; |
| 41 |
} |
| 42 |
else if (2 <= m_phase && m_phase <= 51) { |
| 43 |
m_stripeHeight = (m_stripeHeight * 3 |
| 44 |
* (0.97 + Random::randomReal(0.06)) |
| 45 |
+ STRIPE_STANDARD) / 4.0; |
| 46 |
} |
| 47 |
else if (m_phase == 52) { |
| 48 |
m_zx = ZX3; |
| 49 |
m_stripeHeight = STRIPE_NARROW; |
| 50 |
} |
| 51 |
else { |
| 52 |
m_stripeHeight = (m_stripeHeight * 3 |
| 53 |
* (0.95 + Random::randomReal(0.1)) |
| 54 |
+ STRIPE_NARROW) / 4.0; |
| 55 |
} |
| 56 |
} |
| 57 |
//----------------------------------------------------------------- |
| 58 |
/** |
| 59 |
* Draw ZX spectrum loading. |
| 60 |
*/ |
| 61 |
void |
| 62 |
EffectZx::blit(SDL_Surface *screen, SDL_Surface *surface, int x, int y) |
| 63 |
{ |
| 64 |
SurfaceLock lock1(screen); |
| 65 |
SurfaceLock lock2(surface); |
| 66 |
|
| 67 |
Uint32 colorZX1 = PixelTool::convertColor(screen->format, |
| 68 |
PixelTool::getColor(surface, 0, 0)); |
| 69 |
Uint32 colorZX2 = PixelTool::convertColor(screen->format, |
| 70 |
PixelTool::getColor(surface, 0, surface->h - 1)); |
| 71 |
Uint32 colorZX3 = PixelTool::convertColor(screen->format, |
| 72 |
PixelTool::getColor(surface, surface->w - 1, 0)); |
| 73 |
Uint32 colorZX4 = PixelTool::convertColor(screen->format, |
| 74 |
PixelTool::getColor(surface, surface->w - 1, surface->h - 1)); |
| 75 |
|
| 76 |
PixelIterator pit(surface); |
| 77 |
for (int py = 0; py < surface->h; ++py) { |
| 78 |
m_countHeight++; |
| 79 |
if (m_countHeight > m_stripeHeight) { |
| 80 |
m_countHeight -= m_stripeHeight; |
| 81 |
switch (m_zx) { |
| 82 |
case ZX1: |
| 83 |
m_zx = ZX2; |
| 84 |
break; |
| 85 |
case ZX2: |
| 86 |
m_zx = ZX1; |
| 87 |
break; |
| 88 |
case ZX3: |
| 89 |
m_zx = ZX4; |
| 90 |
break; |
| 91 |
default: |
| 92 |
m_zx = ZX3; |
| 93 |
break; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
Uint32 usedColor; |
| 98 |
switch (m_zx) { |
| 99 |
case ZX1: |
| 100 |
usedColor = colorZX1; |
| 101 |
break; |
| 102 |
case ZX2: |
| 103 |
usedColor = colorZX2; |
| 104 |
break; |
| 105 |
case ZX3: |
| 106 |
usedColor = colorZX3; |
| 107 |
break; |
| 108 |
default: |
| 109 |
usedColor = colorZX4; |
| 110 |
break; |
| 111 |
} |
| 112 |
|
| 113 |
for (int px = 0; px < surface->w; ++px) { |
| 114 |
if (!pit.isTransparent()) { |
| 115 |
PixelTool::putPixel(screen, |
| 116 |
x + px, y + py, usedColor); |
| 117 |
} |
| 118 |
pit.inc(); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|