00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "WavyPicture.h"
00010
00011 #include "TimerAgent.h"
00012
00013 #include <math.h>
00014
00015
00016
00017
00018
00019
00020 WavyPicture::WavyPicture(const Path &file, const V2 &loc)
00021 : Picture(file, loc)
00022 {
00023 m_amp = 0;
00024 m_periode = m_surface->w;
00025 m_speed = 0;
00026 }
00027
00028
00029
00030
00031
00032 void
00033 WavyPicture::drawOn(SDL_Surface *screen)
00034 {
00035 if (m_amp == 0) {
00036 Picture::drawOn(screen);
00037 return;
00038 }
00039
00040
00041
00042 SDL_Rect dest_rect;
00043 SDL_Rect line_rect;
00044 line_rect.w = m_surface->w;
00045 line_rect.h = 1;
00046 SDL_Rect pad;
00047 pad.h = 1;
00048
00049 float shift = TimerAgent::agent()->getCycles() * m_speed;
00050
00051 for (int py = 0; py < m_surface->h; ++py) {
00052
00053 Sint16 shiftX = static_cast<Sint16>(0.5 +
00054 m_amp * sin(py / m_periode + shift));
00055 line_rect.x = shiftX;
00056 line_rect.y = py;
00057 dest_rect.x = m_loc.getX();
00058 dest_rect.y = m_loc.getY() + py;
00059 SDL_BlitSurface(m_surface, &line_rect, screen, &dest_rect);
00060
00061 pad.x = (shiftX < 0) ? 0 : m_surface->w - shiftX;
00062 pad.y = py;
00063 pad.w = abs(shiftX);
00064 dest_rect.x = m_loc.getX() + pad.x;
00065 dest_rect.y = m_loc.getY() + py;
00066 SDL_BlitSurface(m_surface, &pad, screen, &dest_rect);
00067 }
00068 }
00069
00070