]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Sprite.cpp
merged Point into Vector
[l2e.git] / src / graphics / Sprite.cpp
1 /*
2  * Sprite.cpp
3  *
4  *  Created on: Aug 5, 2012
5  *      Author: holy
6  */
7
8 #include "Sprite.h"
9
10 using geometry::Vector;
11
12 namespace graphics {
13
14 void Sprite::Draw(SDL_Surface *dest, const Vector<int> &position, int col, int row) const {
15         SDL_Rect srcRect, destRect;
16         srcRect.x = xOffset + col * Width();
17         srcRect.y = yOffset + row * Height();
18         srcRect.w = Width();
19         srcRect.h = Height();
20         destRect.x = position.X();
21         destRect.y = position.Y();
22         if (surface) {
23                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
24         } else {
25                 destRect.w = Width();
26                 destRect.h = Height();
27                 bool red(true);
28                 while (destRect.w > 1 && destRect.h > 1) {
29                         SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, red ? 0xFF : 0, 0, 0));
30                         ++destRect.x;
31                         ++destRect.y;
32                         destRect.w -= 2;
33                         destRect.h -= 2;
34                         red = !red;
35                 }
36         }
37 }
38
39 }