Controller tweaks (still hit and miss for games)

This commit is contained in:
Amish Naidu 2016-07-24 13:14:38 +05:30
parent 6ad88354bb
commit 51ab2a67f0
3 changed files with 14 additions and 15 deletions

View file

@ -22,6 +22,7 @@ namespace sn
Down,
Left,
Right,
TotalButtons,
};
void strobe(Byte b);
@ -30,7 +31,7 @@ namespace sn
bool m_strobe;
unsigned int m_keyStates;
std::map<Buttons, sf::Keyboard::Key> m_keyBindings;
sf::Keyboard::Key m_keyBindings[TotalButtons];
};
}

View file

@ -3,19 +3,17 @@
namespace sn
{
Controller::Controller() :
m_keyStates(0),
m_keyBindings({
{A, sf::Keyboard::Z},
{B, sf::Keyboard::X},
{Select, sf::Keyboard::RShift},
{Start, sf::Keyboard::Return},
{Up, sf::Keyboard::Up},
{Down, sf::Keyboard::Down},
{Left, sf::Keyboard::Left},
{Right, sf::Keyboard::Right},
})
m_keyStates(0)
{
//TODO Make key bindings user-configurable (or load from a config file)
m_keyBindings[A] = sf::Keyboard::Z;
m_keyBindings[B] = sf::Keyboard::X;
m_keyBindings[Select] = sf::Keyboard::RShift;
m_keyBindings[Start] = sf::Keyboard::Return;
m_keyBindings[Up] = sf::Keyboard::Up;
m_keyBindings[Down] = sf::Keyboard::Down;
m_keyBindings[Left] = sf::Keyboard::Left;
m_keyBindings[Right] = sf::Keyboard::Right;
}
void Controller::strobe(Byte b)
@ -25,9 +23,9 @@ namespace sn
{
m_keyStates = 0;
int shift = 0;
for (auto i : m_keyBindings)
for (int button = A; button < TotalButtons; ++button)
{
m_keyStates |= (sf::Keyboard::isKeyPressed(i.second) << shift);
m_keyStates |= (sf::Keyboard::isKeyPressed(m_keyBindings[static_cast<Buttons>(button)]) << shift);
++shift;
}
}

View file

@ -49,7 +49,7 @@ namespace sn
auto index = (x * m_screenSize.y + y) * 6;
if (index >= m_vertices.getVertexCount())
return;
sf::Vector2f coord2d (x * m_pixelSize, y * m_pixelSize);
//Triangle-1