Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

EffectZx.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
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  * Read colors from all four corners.
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  * Update sprite height as ZX Spectrum does.
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  * Draw ZX spectrum loading.
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 

Generated on Wed Jun 1 09:54:30 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2