Hello, everybody :]
I'm trying to get used to 2D game programming using the SFML library. My latest little tester program is just a skeleton at this point to enable one to shoot a little dot in four directions, depending on the last direction they moved in was.
I've noticed that when I move, I can only move in one direction at a time and it will also lock up sometimes if I press more than one key. I would like to know how I can change my code (or what I can add to it) to enable me to move in more than one direction and also to be able to move and fire my bullet at the same time. Below is the code for the part of my program that accepts input for the player structure:
void getInput(int &x, int &y, bool &shot, int &timer, int &direc)
{
App.GetEvent(Event);
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Up))
{
y--;
if (!shot)
direc = 1;
}
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Right))
{
x++;
if (!shot)
direc = 2;
}
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Left))
{
x--;
if (!shot)
direc = 4;
}
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Down))
{
y++;
if (!shot)
direc = 3;
}
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Space))
{
if (timer <= 0)
{
shot = true;
timer = 500;
}
}
}
I would greatly appreciate any help in figuring out how to fix this. Thank you very much.
Colton