#include "SynEngine.hpp" class Cell : public Drawable { private: unsigned int spriteIndex; sf::Vector2f position; sf::Sprite sprite; bool CreateSprite(); public: Cell(); Cell(unsigned int, unsigned int, unsigned int = 0); void Set(unsigned int, unsigned int, unsigned int = 0); void UpdateSprite(unsigned int); void UpdateRotation(unsigned); void Draw(sf::RenderWindow *); ~Cell(); }; Cell::Cell() { spriteIndex = 0; position = sf::Vector2f(0, 0); } Cell::Cell(unsigned int x, unsigned int y, unsigned int index) { Set(x, y, index); } void Cell::Set(unsigned int x, unsigned int y, unsigned int index) { spriteIndex = index; position = sf::Vector2f(x, y); CreateSprite(); } bool Cell::CreateSprite() { GameConfiguration *config = GameManager::GetConfig(); if(!config) return false; sprite = config -> GetSprite(spriteIndex, position); return true; } void Cell::UpdateSprite(unsigned int index) { if(index == spriteIndex) return; spriteIndex = index; sprite.setTextureRect(GameManager::GetConfig() -> GetSpriteRect(spriteIndex)); } void Cell::UpdateRotation(unsigned direction) { sprite.setRotation(direction * 90.0); } void Cell::Draw(sf::RenderWindow *window) { window -> draw(sprite); } Cell::~Cell() { }