Jump to content
  • Advertisement
Sign in to follow this  
Unconquerable

SDL Event Question

This topic is 4500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a pong game and i would like to make 2 player an option. My question is, do i have to have a seperate event to check if player 2 pressed a key? And if so how would i check for both events in the event loop? -Thanks

Share this post


Link to post
Share on other sites
Advertisement
Handling 2 players in pong would be no different than handling one player, you just have an extra set of code for player two. For example if you are using the SDL_GetKeyState function:

Uint8* keys = SDL_GetKeyState(0);
// Player 1 code
if(keys['W'])
{
}
else if(keys['S'])
{
}

// Player 2 code
if(keys['I'])
{
}
else if(keys['K'])
{
}

And that's it. The same applies for using the events when you handle the keysym variable. You just have the code on after each other. You could do as many players as you wanted, aside from the keyboard space constraints [wink]

You might consider letting one player use keyboard and the other the mouse too.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!