mirror of
https://github.com/dylanbenzi/pacmen-sfml.git
synced 2026-11-27 08:26:59 +00:00
add base support for entity animation and drawing
This commit is contained in:
+21
-10
@@ -1,16 +1,21 @@
|
||||
#ifndef ENTITY_H
|
||||
#define ENTITY_H
|
||||
|
||||
#include "MazeMap.h"
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/PrimitiveType.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Graphics/RenderStates.hpp>
|
||||
#include <SFML/Graphics/RenderTarget.hpp>
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/Graphics/Transformable.hpp>
|
||||
#include <SFML/Graphics/VertexArray.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum class MovementDir {
|
||||
STATIC,
|
||||
@@ -20,23 +25,29 @@ enum class MovementDir {
|
||||
RIGHT
|
||||
};
|
||||
|
||||
class Entity : public sf::Drawable, public sf::Transformable {
|
||||
struct EntityAnimation {
|
||||
std::string name;
|
||||
std::vector<sf::Sprite> sprites;
|
||||
};
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
//Entity(TileMap& map) : map(map) {};
|
||||
Entity() : movementSpeed(5) {};
|
||||
|
||||
bool loadTexture(const std::filesystem::path& texturePath, sf::Vector2u graphicTileSize, int tiles);
|
||||
void setAnimationTiles(sf::Texture& textureSheet, sf::Vector2i pixelLocation, const std::string& animationName, sf::Vector2i tileSize, unsigned int animationTiles, unsigned int pixelGap);
|
||||
|
||||
sf::Sprite* getActiveSprite() { return activeSprite; };
|
||||
|
||||
void setActiveSprite(const std::string& animationName, int animationTile);
|
||||
|
||||
void setTextureFrame(const sf::IntRect& rectangle);
|
||||
protected:
|
||||
//TileMap map;
|
||||
sf::Vector2i tileSize;
|
||||
|
||||
sf::VertexArray vertexArray;
|
||||
sf::Texture texture;
|
||||
std::vector<EntityAnimation> animations;
|
||||
|
||||
int animationTiles;
|
||||
int movementSpeed = 5;
|
||||
sf::Sprite* activeSprite;
|
||||
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
int movementSpeed;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user