2020-02-02 15:18:12 +00:00
|
|
|
#ifndef DEF_XSPRITEGROUP_H
|
|
|
|
#define DEF_XSPRITEGROUP_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <mutex>
|
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_image.h"
|
|
|
|
#include "xDrawable.h"
|
|
|
|
#include "xOrchestrable.h"
|
|
|
|
#include "xApplication.h"
|
|
|
|
#include "xSprite.h"
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class xSpriteGroup : public xDrawable, public xOrchestrable {
|
|
|
|
|
|
|
|
public:
|
|
|
|
xSpriteGroup();
|
|
|
|
virtual ~xSpriteGroup();
|
|
|
|
|
|
|
|
// manage sprite list
|
|
|
|
void add(xSprite* sprite);
|
|
|
|
void remove(xSprite* sprite);
|
|
|
|
void clear();
|
|
|
|
|
2020-02-04 19:22:17 +00:00
|
|
|
// apply relative displace for each sprite
|
|
|
|
void displace(SDL_Rect relative_displace);
|
2020-02-04 17:57:31 +00:00
|
|
|
void displace(int x, int y, int w, int h);
|
2020-02-02 15:18:12 +00:00
|
|
|
|
|
|
|
// implement xDrawable
|
|
|
|
virtual void draw(SDL_Renderer* renderer) override;
|
|
|
|
|
|
|
|
// implement xOrchestrable
|
|
|
|
void tick(const uint32_t ticks);
|
|
|
|
|
|
|
|
// animation handles
|
|
|
|
void animate(uint32_t interval);
|
|
|
|
void freeze();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
set<xSprite*> _sprites;
|
|
|
|
|
2020-02-04 17:57:31 +00:00
|
|
|
// if not animated, draw all sprites, else draw one at a time
|
|
|
|
bool _animated = false;
|
|
|
|
// active sprite for animation
|
2020-02-02 15:18:12 +00:00
|
|
|
size_t _active_sprite = 0;
|
2020-02-04 17:57:31 +00:00
|
|
|
uint32_t _animation_interval = 0;
|
2020-02-02 15:18:12 +00:00
|
|
|
|
|
|
|
mutex _mutex;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|