visual c++ breakout ball fire

hello i was wondering if anyone could help me, i am a college student and am having a little bit of trouble sorting out my code.basically i have the space bar set so when it is pressed the ball moves along the x axis at a velocity of 1.0f and along the y axis at 1.5f like this.
1
2
3
4
5
if( keys[VK_SPACE])// space bar is the fire key
	{
		ball.v.y = 1.5f;
		ball.v.x = 1.0f;
	}


however everytime you press the space it will reset the ball and it will start moving in that velocity again so you can actually play the game without using the bat at the bottom of the screen just the space bar



is there any way i can fix this? thank you
Only check for the space button when it's legal for the ball to fire.

ie:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
if( BallIsOnPaddle )
{
  if( SpaceIsPressed )
  {
    // set velocity
  }
}

// -- or you can combine them with an &&

if( BallIsOnPaddle && SpaceIsPressed )
{
  // set velocity
}
Topic archived. No new replies allowed.