| 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 "WavyPicture.h" |
| 10 |
|
| 11 |
#include "TimerAgent.h" |
| 12 |
|
| 13 |
#include <math.h> |
| 14 |
|
| 15 |
//----------------------------------------------------------------- |
| 16 |
/** |
| 17 |
* Load surface. |
| 18 |
* Default is no waves. |
| 19 |
*/ |
| 20 |
WavyPicture::WavyPicture(const Path &file, const V2 &loc) |
| 21 |
: Picture(file, loc) |
| 22 |
{ |
| 23 |
m_amp = 0; |
| 24 |
m_periode = m_surface->w; |
| 25 |
m_speed = 0; |
| 26 |
} |
| 27 |
//----------------------------------------------------------------- |
| 28 |
/** |
| 29 |
* Blit entire surface to [x,y]. |
| 30 |
* Do vertical waves with phase shift. |
| 31 |
*/ |
| 32 |
void |
| 33 |
WavyPicture::drawOn(SDL_Surface *screen) |
| 34 |
{ |
| 35 |
if (m_amp == 0) { |
| 36 |
Picture::drawOn(screen); |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
//NOTE: Wamp = Wamp_in_orig/2.0 |
| 41 |
//NOTE: Wspeed = 1.0/Wspd_in_orig |
| 42 |
SDL_Rect dest_rect; |
| 43 |
SDL_Rect line_rect; |
| 44 |
line_rect.w = m_surface->w; |
| 45 |
line_rect.h = 1; |
| 46 |
SDL_Rect pad; |
| 47 |
pad.h = 1; |
| 48 |
|
| 49 |
float shift = TimerAgent::agent()->getCycles() * m_speed; |
| 50 |
|
| 51 |
for (int py = 0; py < m_surface->h; ++py) { |
| 52 |
//NOTE: C99 has lrintf and sinf |
| 53 |
Sint16 shiftX = static_cast<Sint16>(0.5 + |
| 54 |
m_amp * sin(py / m_periode + shift)); |
| 55 |
line_rect.x = shiftX; |
| 56 |
line_rect.y = py; |
| 57 |
dest_rect.x = m_loc.getX(); |
| 58 |
dest_rect.y = m_loc.getY() + py; |
| 59 |
SDL_BlitSurface(m_surface, &line_rect, screen, &dest_rect); |
| 60 |
|
| 61 |
pad.x = (shiftX < 0) ? 0 : m_surface->w - shiftX; |
| 62 |
pad.y = py; |
| 63 |
pad.w = abs(shiftX); |
| 64 |
dest_rect.x = m_loc.getX() + pad.x; |
| 65 |
dest_rect.y = m_loc.getY() + py; |
| 66 |
SDL_BlitSurface(m_surface, &pad, screen, &dest_rect); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|