Pong problem

Everything is working fine in the game exept one thing.

After a new round if the user was holding down a button, he cant move in that direction. If he lets go then he starts going the opposit direction he was holding. How would i fix this?
You can't honestly expect anyone to help you solve your problem with just that.

Post a link to the example, code, whatever you can.
I thought this would be a common problem but here is the function that handles movement if it helps.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
void Game::MovePlayerPaddle()
{
	if( event.type == SDL_KEYDOWN)
	{
		if( User.yPos > 0 && User.yPos < 480 )
		{
			switch( event.key.keysym.sym )
			{
			case SDLK_UP:
				User.yVel -= 13.f;
				break;
			case SDLK_DOWN:
				User.yVel += 13.f;
				break;
			}
		}
	}
	if( event.type == SDL_KEYUP )
	{
		switch( event.key.keysym.sym )
		{
		case SDLK_UP:
			User.yVel += 13.f;
			break;
		case SDLK_DOWN:
			User.yVel -= 13.f;
			break;
		}
	}
}
You need to zero the yVelocity when a new game starts.

Although that's more of a workaround than a solution. You're better off not using events, and instead just checking the realtime status of the key to determine whether or not it's pressed.
Last edited on
SDL isn't part of the STL so there are a dozen Pong examples, for many different libraries.

You may need to clear the event type, unsure. Assuming both if statements are reoccuring and therefore causing clashes in movement.

And possibly the reason for moving in wrong direction is that:
1
2
3
User.yVel += 13.f;

User.yVel -= 13.f;


Are around the wrong way
Last edited on
@disch i do zero the yVelocity. That doesnt fix it though.

How do i check the realtime status of the key?

@ Turbine

Lol they are not around the wrong way. going up on the y-axis goes down, remember?
Last edited on
Topic archived. No new replies allowed.