• Create Account

## dx9 and pong

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

### #1phil67rpg  Members

213
Like
0Likes
Like

Posted 18 October 2012 - 07:49 PM

I am working on a pong game using dx9 and c++.I want to have the computer paddle move up and down on its own.let me know if you need some code or more information.

### #2Bacterius  Members

13100
Like
2Likes
Like

Posted 18 October 2012 - 07:56 PM

How about having the computer predict the location where the ball will go and move its paddle there at a predefined speed (possibly depending on the speed of the ball)?

You can predict the ball's destination by intersecting its velocity vector with the paddle axis (and if the velocity vector is normalized, the distance of the intersection along that vector also happens to give the time to intersection).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #3phil67rpg  Members

213
Like
0Likes
Like

Posted 19 October 2012 - 03:58 PM

here is the code I am using
if(right_paddle>=-220)
{
}
{
}


### #4RulerOfNothing  Members

1369
Like
0Likes
Like

Posted 19 October 2012 - 05:38 PM

Hmm. What is the significance of the number 220?

### #5phil67rpg  Members

213
Like
0Likes
Like

Posted 19 October 2012 - 05:54 PM

it is the top or bottom of the screen

### #6incertia  Members

779
Like
0Likes
Like

Posted 20 October 2012 - 09:16 PM

here is the code I am using

if(right_paddle>=-220)
{
}
{
}


If your paddle position is greater than -220, it's position will be set to -right_paddle_vel. I'm going to assume right_paddle_vel is less than 220, so it seems as if it will be stuck there.
Otherwise, we will keep moving it at a speed of right_paddle_vel.

Maybe you want to do this.

if(paddle_y > ball_y){
}
}


where vel is some positive number.

Edited by incertia, 20 October 2012 - 09:18 PM.

what

### #7superman3275  Members

2061
Like
0Likes
Like

Posted 20 October 2012 - 10:02 PM

m = (y2 - y 1) / (x2 - x1)
All you need is two points, the starting position (x1 + y1) and the ending position (x2 + y2). However, it's pretty easy if you know the velocity to find another point, put it in here, and then use either y = mx + b or y1 - y = m(x1 -x) To find anothe point. Just use some basic math to calculate the ending position of the ball, then move your computer paddle at a predetermined speed to find it (Preferably slower than velx, or else you'll end up having a never ending A.I.)

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

or Personal-Message me on here !

### #8phil67rpg  Members

213
Like
0Likes
Like

Posted 22 October 2012 - 08:02 PM

well I have worked on this problem and have almost finished it.here is the code I am using.
if(right_paddle > screenHeight || right_paddle < -screenHeight)
{
}



### #9phil67rpg  Members

213
Like
0Likes
Like

Posted 23 October 2012 - 08:44 PM

I have managed to get the right paddle to move from the top of the screen to the bottom of the screen but I cant get it to move back from the bottom of the screen to the top of the screen, basically I want some very simple Ai for the computer controlled right paddle.here is the code I am working with.
if(right_paddle > screenHeight || right_paddle < -screenHeight)
{