dx9 and pong

Started by
7 comments, last by phil67rpg 11 years, 6 months ago
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.
Advertisement
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.”

here is the code I am using

if(right_paddle>=-220)
{
right_paddle=-right_paddle_vel;
}
if(right_paddle<=220)
{
right_paddle+=right_paddle_vel;
}
Hmm. What is the significance of the number 220?
it is the top or bottom of the screen

here is the code I am using

if(right_paddle>=-220)
{
right_paddle=-right_paddle_vel;
}
if(right_paddle<=220)
{
right_paddle+=right_paddle_vel;
}



Your paddle appears to be doing the following:
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){
paddle_y -= vel;
}
else if(paddle_y < ball_y){
paddle_y += vel;
}


where vel is some positive number.
what
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:

hobohm.business@gmail.com

or Personal-Message me on here !

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)
{
right_paddle+=right_paddle;
}

right_paddle+=5;

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)
{
right_paddle+=right_paddle;
}

right_paddle+=5;

This topic is closed to new replies.

Advertisement