2 Replies - 1979 Views - Last Post: 10 December 2012 - 04:39 PM Rate Topic: -----

#1 pbivens  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 28
  • Joined: 29-January 12

pong and dx9

Posted 20 October 2012 - 02:43 PM

I am working on a pong game using c++ and dx9.I want the ball to bounce off the screen walls.here is the code I am working on.Right now the ball is going off the screen.
		ball_move_x += ball_vel;

		if(ball_move_x>=screen_width)
		{
		ball_move_x -= ball_vel;
		}


I think I have to reverse the velocity of the ball when it hits the screen side.
Is This A Good Question/Topic? 0
  • +

Replies To: pong and dx9

#2 Nano511  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 145
  • Joined: 07-October 12

Re: pong and dx9

Posted 28 October 2012 - 05:14 PM

yeah when the ball hits the wall just do "ball_vel = -ball_vel;"
Was This Post Helpful? 0
  • +
  • -

#3 LittleGyros  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 14
  • Joined: 05-January 10

Re: pong and dx9

Posted 10 December 2012 - 04:39 PM

Yes it's right to invert the x-velocity, but i'd also go one step back before doing this.
xPos += xVel;
if(xPos >= screenWidth)
{
   xPos -= xVel;
   xVel = -xVel;
}



this way you're avoiding some strange ball/wall interaction..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1