-
Notifications
You must be signed in to change notification settings - Fork 1
/
frame.cpp
47 lines (40 loc) · 1.46 KB
/
frame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "drawable.h"
#include "frame.h"
#include "ioManager.h"
#include "viewport.h"
Frame::Frame( const Frame& frame ) :
screen(frame.screen),
spriteSurface(frame.spriteSurface),
spriteWidth(frame.spriteWidth), spriteHeight(frame.spriteHeight),
spriteSourceX(frame.spriteSourceX), spriteSourceY(frame.spriteSourceY)
{ }
Frame::Frame( SDL_Surface* spr, Uint16 sprite_width, Uint16 sprite_height,
Sint16 src_x, Sint16 src_y) :
screen(IOManager::getInstance().getScreen()),
spriteSurface(spr),
spriteWidth(sprite_width), spriteHeight(sprite_height),
spriteSourceX(src_x), spriteSourceY(src_y) {
}
Frame& Frame::operator=(const Frame& rhs) {
spriteSurface = rhs.spriteSurface;
screen = rhs.screen;
spriteWidth = rhs.spriteWidth;
spriteHeight = rhs.spriteHeight;
spriteSourceX = rhs.spriteSourceX;
spriteSourceY = rhs.spriteSourceY;
return *this;
}
void Frame::draw(Sint16 x, Sint16 y) const {
x -= Viewport::getInstance().X();
y -= Viewport::getInstance().Y();
SDL_Rect src = { spriteSourceX, spriteSourceY,
spriteWidth, spriteHeight
};
SDL_Rect dest = {x, y, spriteWidth, spriteHeight };
SDL_BlitSurface(spriteSurface, &src, screen, &dest);
}
void Frame::draw(Sint16 sx, Sint16 sy, Sint16 dx, Sint16 dy) const {
SDL_Rect src = { sx, sy, spriteWidth, spriteHeight };
SDL_Rect dest = {dx, dy, spriteWidth, spriteHeight };
SDL_BlitSurface(spriteSurface, &src, screen, &dest);
}