project-kyoku/src/classicgame/classicspritefactory.h

48 lines
1.0 KiB
C
Raw Normal View History

2021-06-16 13:11:00 -04:00
#pragma once
#include <memory>
#include "classicinputtype.h"
#include "classicsprite.h"
class ClassicSpriteFactory
{
public:
inline ClassicSpriteFactory(const std::string& font_filename)
{
_font.loadFromFile(font_filename);
}
inline std::shared_ptr<ClassicSprite> create(Action action)
{
sf::RectangleShape sprite;
sprite.setSize({20.f, 20.f});
switch (action)
{
case Action::PRESS_UP:
sprite.setFillColor(sf::Color(255, 0, 0));
break;
case Action::PRESS_DOWN:
sprite.setFillColor(sf::Color(0, 255, 0));
break;
case Action::PRESS_LEFT:
sprite.setFillColor(sf::Color(0, 0, 255));
break;
case Action::PRESS_RIGHT:
sprite.setFillColor(sf::Color(255, 0, 255));
break;
default: // yellow
sprite.setFillColor(sf::Color(255, 239, 0));
}
return std::make_shared<ClassicSprite>(sprite, _font);
}
private:
sf::Font _font;
};