2012-09-09 20:50:15 +00:00
|
|
|
/*
|
|
|
|
* Sprite.h
|
|
|
|
*
|
2012-12-23 14:50:49 +00:00
|
|
|
* Created on: 11.08.2012
|
2012-09-09 20:50:15 +00:00
|
|
|
* Author: Felix
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DG_SPRITE_H_
|
|
|
|
#define DG_SPRITE_H_
|
|
|
|
|
2012-12-23 14:50:49 +00:00
|
|
|
#include <SFML/System.hpp>
|
2012-09-09 20:50:15 +00:00
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
|
2012-10-12 18:59:33 +00:00
|
|
|
#include "../util/Yaml.h"
|
2012-09-09 20:50:15 +00:00
|
|
|
|
2012-10-12 18:59:33 +00:00
|
|
|
class Yaml;
|
2012-09-14 18:39:56 +00:00
|
|
|
|
2012-09-09 20:50:15 +00:00
|
|
|
/**
|
2012-12-23 14:50:49 +00:00
|
|
|
* An sprite that is rendered in the world.
|
2012-09-09 20:50:15 +00:00
|
|
|
*/
|
2012-12-23 14:50:49 +00:00
|
|
|
class Sprite : public sf::Drawable {
|
|
|
|
// Public types.
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Categories of objects for filtering.
|
|
|
|
* The order of categories is also used for render order (higher number on top).
|
|
|
|
*/
|
|
|
|
enum Category {
|
|
|
|
CATEGORY_WORLD = 1 << 1,
|
|
|
|
CATEGORY_NONSOLID = 1 << 2,
|
|
|
|
CATEGORY_PARTICLE = 1 << 3,
|
|
|
|
CATEGORY_ACTOR = 1 << 4
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Container that carries all data required to construct an object of this class.
|
|
|
|
*/
|
|
|
|
class Data {
|
|
|
|
public:
|
|
|
|
Data(const sf::Vector2f& position, float angle, Category category, unsigned short maskExclude);
|
|
|
|
const sf::Vector2f& position;
|
|
|
|
float angle;
|
|
|
|
Category category;
|
|
|
|
unsigned short mask;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common collision masking values.
|
|
|
|
*/
|
|
|
|
enum Mask : unsigned short {
|
|
|
|
MASK_NONE = 0xffff, //< Disables any collisions.
|
|
|
|
MASK_ALL = 0 //< Enables all collisions.
|
|
|
|
};
|
|
|
|
|
2012-09-16 18:45:12 +00:00
|
|
|
// Public functions.
|
2012-09-09 20:50:15 +00:00
|
|
|
public:
|
2012-12-23 14:50:49 +00:00
|
|
|
Sprite(const Data& data, const Yaml& config);
|
2012-09-09 20:50:15 +00:00
|
|
|
virtual ~Sprite() = 0;
|
|
|
|
|
2012-12-23 14:50:49 +00:00
|
|
|
sf::Vector2f getPosition() const;
|
|
|
|
sf::Vector2f getSpeed() const;
|
|
|
|
float getAngle() const;
|
|
|
|
bool getDelete() const;
|
|
|
|
Category getCategory() const;
|
|
|
|
sf::Vector2f getSize() const;
|
|
|
|
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
|
|
|
|
|
|
|
virtual void onCollide(Sprite& other);
|
|
|
|
|
|
|
|
// Public variables.
|
|
|
|
public:
|
|
|
|
static const std::string KEY_SIZE;
|
|
|
|
static const std::string KEY_RADIUS;
|
|
|
|
static const std::string KEY_TEXTURE;
|
|
|
|
|
2012-09-16 18:45:12 +00:00
|
|
|
// Protected functions.
|
|
|
|
protected:
|
2012-12-23 14:50:49 +00:00
|
|
|
friend class World;
|
|
|
|
|
|
|
|
void setDelete(bool value);
|
|
|
|
void setSpeed(sf::Vector2f direction, float speed);
|
|
|
|
void setAngle(float angle);
|
|
|
|
void setPosition(const sf::Vector2f& position);
|
2012-09-09 20:50:15 +00:00
|
|
|
|
2012-09-16 18:45:12 +00:00
|
|
|
// Private variables.
|
|
|
|
private:
|
2012-12-23 14:50:49 +00:00
|
|
|
std::unique_ptr<sf::Shape> mShape;
|
2012-09-09 20:50:15 +00:00
|
|
|
std::shared_ptr<sf::Texture> mTexture;
|
2012-12-23 14:50:49 +00:00
|
|
|
sf::Vector2f mSpeed;
|
|
|
|
Category mCategory;
|
|
|
|
unsigned short mMask;
|
|
|
|
bool mDelete;
|
2012-09-09 20:50:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* DG_SPRITE_H_ */
|