-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiframesprite.h
50 lines (43 loc) · 1.56 KB
/
multiframesprite.h
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
46
47
48
49
50
#ifndef MULTIFRAMESPRITE__H
#define MULTIFRAMESPRITE__H
#include <string>
using std::string;
#include <iostream>
#include "sprite.h"
#include "frame.h"
#include "framefactory.h"
#include "gamedata.h"
class MultiFrameSprite : public Sprite {
public:
MultiFrameSprite(const string& n,const string& no, const Vector2f& pos, const Vector2f& vel);
MultiFrameSprite(const MultiFrameSprite& s);
virtual ~MultiFrameSprite() { }
MultiFrameSprite& operator=(const MultiFrameSprite&);
void currentFrame(unsigned c) { currFrame = c; }
unsigned currentFrame() const { return currFrame; }
void change(float d) { dt = d; }
float change() const { return dt; }
void setFrameVector(std::vector<Frame*> f) { frame = f; }
std::vector<Frame*> getFrameVector() const { return frame; }
virtual const Frame* getFrame() const { return frame[currFrame]; }
virtual void setFrame(const Frame* f) { if(f){}}
virtual void draw() const;
virtual void update(Uint32 ticks) {
if(ticks){
std::cout << "Update not implemented for "<< getName() << std::endl;
}
}
unsigned getPixel(Uint32, Uint32) const;
Vector2f getCenter() const {
return Vector2f( X()+frame[currFrame]->getWidth()/2, Y()+frame[currFrame]->getHeight()/2 );
}
private:
float dt;
std::vector<Frame*> frame;
protected:
unsigned currFrame;
void advanceFrame(Uint32 ticks, float change, std::string action);
int getDistance(const MultiFrameSprite*) const;
float diffLDraw; //used this variable bcoz the sprite was changing x position for diff frames in left direction while drawing
};
#endif