48 lines
1.0 KiB
C
48 lines
1.0 KiB
C
|
#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;
|
||
|
};
|
||
|
|