-
Notifications
You must be signed in to change notification settings - Fork 0
/
singleframesprite.cpp
39 lines (31 loc) · 1.06 KB
/
singleframesprite.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
#include <iostream>
#include <cmath>
#include "singleframesprite.h"
#include "viewport.h"
SingleFrameSprite::SingleFrameSprite(const string& n,const string& no, const Vector2f& pos, const Vector2f& vel) :
Sprite(n,no,pos,vel),
frame()
{ }
SingleFrameSprite::SingleFrameSprite(const SingleFrameSprite& s) :
Sprite(s.getName(),s.getNumber(),s.getPosition(),s.getVelocity()),
frame(s.frame)
{ }
SingleFrameSprite& SingleFrameSprite::operator=(const SingleFrameSprite& rhs) {
setName( rhs.getName() );
setPosition(rhs.getPosition());
setVelocity(rhs.getVelocity());
setMaxVelocity(rhs.getMaxVelocity());
Location(rhs.Location());
setDirection(rhs.getDirection());
frame = rhs.frame;
return *this;
}
void SingleFrameSprite::draw() const {
Uint32 x = static_cast<Uint32>(X());
Uint32 y = static_cast<Uint32>(Y());
frame->draw(x, y - frame->getHeight());
}
unsigned SingleFrameSprite::getPixel(Uint32 i, Uint32 j) const {
Uint32 *pixels = static_cast<Uint32 *>(frame->getSurface()->pixels);
return pixels[ ( j * frame->getWidth() ) + i ];
}