This repository has been archived on 2019-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
dungeon-gunner/source/abstract/Sprite.h

79 lines
2 KiB
C
Raw Normal View History

/*
* Sprite.h
*
2012-12-23 14:50:49 +00:00
* Created on: 11.08.2012
* Author: Felix
*/
#ifndef DG_SPRITE_H_
#define DG_SPRITE_H_
#include <memory>
#include <SFML/Graphics.hpp>
/**
2012-12-23 14:50:49 +00:00
* An sprite that is rendered in the world.
*/
2012-12-23 14:50:49 +00:00
class Sprite : public sf::Drawable {
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
};
/**
* Common collision masking values.
*/
enum Mask : unsigned short {
2013-03-03 20:27:40 +00:00
MASK_ALL = 0xffff, //< Enables all collisions.
MASK_NONE = 0 //< Disables any collisions.
2012-12-23 14:50:49 +00:00
};
2012-09-16 18:45:12 +00:00
// Public functions.
public:
explicit Sprite(const sf::Vector2f& position, Category category,
unsigned short mask, const sf::Vector2f& size,
const std::string& texture, const sf::Vector2f& direction);
virtual ~Sprite() = default;
2012-12-23 14:50:49 +00:00
sf::Vector2f getPosition() const;
sf::Vector2f getSpeed() const;
sf::Vector2f getDirection() const;
2012-12-23 14:50:49 +00:00
bool getDelete() const;
Category getCategory() const;
sf::Vector2f getSize() const;
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
2013-03-03 20:27:40 +00:00
bool collisionEnabled(Category category) const;
bool isInside(const sf::FloatRect& rect) const;
2012-12-23 14:50:49 +00:00
virtual bool testCollision(std::shared_ptr<Sprite> other,
sf::Vector2f& offsetFirst, const sf::Vector2f& offsetSecond) = 0;
2013-03-03 20:27:40 +00:00
virtual void onCollide(std::shared_ptr<Sprite> other);
2012-12-23 14:50:49 +00:00
2012-09-16 18:45:12 +00:00
protected:
2012-12-23 14:50:49 +00:00
void setDelete(bool value);
void setSpeed(sf::Vector2f direction, float speed);
void setDirection(const sf::Vector2f& direction);
2012-12-23 14:50:49 +00:00
void setPosition(const sf::Vector2f& position);
2013-03-03 20:27:40 +00:00
2012-09-16 18:45:12 +00:00
private:
friend class CollisionModel;
2013-03-03 20:27:40 +00:00
friend class World;
sf::RectangleShape mShape;
std::shared_ptr<sf::Texture> mTexture;
2012-12-23 14:50:49 +00:00
sf::Vector2f mSpeed;
Category mCategory;
unsigned short mMask;
bool mDelete;
};
#endif /* DG_SPRITE_H_ */