Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Wake

Pages: [1]
1
Hi, so I made a std::unordered_map to contain my user input key bindings. I have a struct called "Bindings" that contains the following members.
Code: [Select]
struct Binding
{
Binding() {}

Binding(InputType inputTypes, sf::Event::EventType eventType1, sf::Event::EventType eventType2,
    sf::Keyboard::Key keyCode1, sf::Keyboard::Key keyCode2,
sf::Mouse::Button mouseCode1, sf::Mouse::Button mouseCode2)
            : my_InputTypes{ inputTypes }, m_enumEventType1 {eventType1}, m_enumEventType2 { eventType2 },
        m_keyCode1{ keyCode1 }, m_keyCode2{ keyCode2 }, m_mouseCode1{ mouseCode1 },
    m_mouseCode2{ mouseCode2 }{}

InputType my_InputTypes;
sf::Event::EventType m_enumEventType1;
sf::Event::EventType m_enumEventType2;
sf::Keyboard::Key m_keyCode1;
sf::Keyboard::Key m_keyCode2;
sf::Mouse::Button m_mouseCode1;
sf::Mouse::Button m_mouseCode2;


};

using BindingMap = std::unordered_map<std::string, Binding >;

I read a .csv file to enter my bindings.
Code: [Select]
void EventManager::LoadBindings()
{
std::ifstream keyBindings("Keys.csv");

if (!keyBindings.is_open()) { std::cout << "Error loading Keys.csv..."; }

int number_of_lines = 0;
std::string lineCount;

while (std::getline(keyBindings, lineCount))
++number_of_lines;
std::cout << "Number of lines in .csv file: " << number_of_lines << '\n';

keyBindings.close();
keyBindings.open("Keys.csv");

std::string mapKey;
std::string myInputType;
std::string eventType1;
std::string eventType2;
std::string keyCode1;
std::string keyCode2;
std::string mouseCode1;
std::string mouseCode2;

for (int i=0; i <= (number_of_lines-1); ++i)
{
std::getline(keyBindings, mapKey,',');
std::getline(keyBindings, myInputType,',');
std::getline(keyBindings, eventType1,',');
std::getline(keyBindings, eventType2, ',');
std::getline(keyBindings, keyCode1,',');
std::getline(keyBindings, keyCode2,',');
std::getline(keyBindings, mouseCode1,',');
std::getline(keyBindings, mouseCode2,'\n');

std::cout << mapKey << "|"
<< stoi(myInputType) << "|"
<< stoi(eventType1) << "|"
<< stoi(eventType2) << "|"
<< stoi(keyCode1) << "|"
<< stoi(keyCode2) << "|"
<< stoi(mouseCode1) << "|"
<< stoi(mouseCode2) << '\n';

m_bindingMap.insert(std::pair <std::string, Binding>
(mapKey, { static_cast<InputType>(stoi(myInputType)),
   static_cast<sf::Event::EventType>(stoi(eventType1)),
static_cast<sf::Event::EventType>(stoi(eventType2)),
       static_cast<sf::Keyboard::Key>(stoi(keyCode1)),
               static_cast<sf::Keyboard::Key>(stoi(keyCode2)),
   static_cast<sf::Mouse::Button>(stoi(mouseCode1)),
   static_cast<sf::Mouse::Button>(stoi(mouseCode2))}));

}
keyBindings.close();
PrintMap();
}

void EventManager::PrintMap()
{
for (auto element : m_bindingMap)
{
std::cout << element.first << " :: " << static_cast<int>(element.second.my_InputTypes)
   << " :: " << static_cast<int>(element.second.m_enumEventType1)
   << " :: " << static_cast<int>(element.second.m_enumEventType1)
                       << " :: " << static_cast<int>(element.second.m_keyCode1)
                       << " :: " << static_cast<int>(element.second.m_keyCode2)
                       << " :: " << static_cast<int>(element.second.m_mouseCode1)
                       << " :: " << static_cast<int>(element.second.m_mouseCode2)
   << std::endl;
}
}
The map works perfectly and is tested... Now, I'm trying to make a multikey bool that flags "true" if 2 or more buttons are pressed at the same time.
Code: [Select]
bool EventManager::TestEvent(Binding binding, sf::Event event)
{
//MultiKeyEvents
if ((binding.my_InputTypes == InputType::MultikeyEvent) &&
(binding.m_enumEventType1 == event.KeyPressed) &&
(binding.m_enumEventType2 == event.MouseButtonPressed) &&
(binding.m_keyCode1 == event.key.code) &&
(binding.m_mouseCode1 == event.mouseButton.button))
{
return (true);
}

return (false);
}

For this example, the keycode = 0 for "A" and the mouse button code = 0 for "Left Mouse Button". I'm trying to register "true" when they are both pressed together. However, with this if statement it will register "true" if I press "A" or the "Left Mouse Button" separately. What am I missing here!? I only want it to be "true" if they are both pressed at the same time.

2
Hi,

Please see the images below;

#Image 1: Collision.hp - I have a sf::SoundBuffer m_SoundBuffer; & sf::Sound m_Sound member variables.

#Image 2: Collision.cpp - In the Collision Class Constructor, I'm loading the .wav to the m_SoundBuffer and setting it to m_Sound;

#Image 3: Collision.cpp - I want the void function to play the sound if (bool m_IsColliding == true).

Result = The sound doesn't play when colliding with the item! :/


3
Hi,

Please see the attached images below.

Image #1 shows how I set the origin of the sf::RectangleShape.
I want it to be in the dead center. So half of x & y.

Image #2 shows how I'm trying to set the position of the text to the origin of the sf::RectangleShape.

Image #3 shows that the text is nowhere near the text box. What happened?

I saw you can set an origin for the sf::Text. Should I make it half the font size for x & y? Does that even matter?

Best,
Wake

4
Hi,

Please see the attached images.

So, I've built a collision class and I want to display a rectangle object with some text in it when there is a collision between the player and the pickup item.

I got the rectangle shape to appear and disappear perfectly on collision, however when I do the same process for the sf::Text, I get an error in Virtual Studio 2019 that states:

"Unhandled exception at 0x00007FFAB2D169DB (sfml-graphics-d-2.dll) in RPG.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF."

The text draws perfectly in the main function, however, I'd like to return this from the Collision class and create a switch for different messages depending on the item being picked up.

Best,
Wake

Pages: [1]