pong and dx9

Page 1 of 1

2 Replies - 2879 Views - Last Post: 10 December 2012 - 04:39 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=296462&amp;s=20a361a1d71738b6a09661615662d194&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 pbivens

Reputation: -2
• 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

Reputation: 3
• 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;"

#3 LittleGyros

Reputation: 3
• 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..