Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


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.

  • You cannot reply to this topic
8 replies to this topic

#1 phil67rpg   Members   -  Reputation: 100

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.

Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 11538

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.”


#3 phil67rpg   Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 October 2012 - 03:58 PM

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;
  }


#4 RulerOfNothing   Members   -  Reputation: 1315

Like
0Likes
Like

Posted 19 October 2012 - 05:38 PM

Hmm. What is the significance of the number 220?

#5 phil67rpg   Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 October 2012 - 05:54 PM

it is the top or bottom of the screen

#6 incertia   Crossbones+   -  Reputation: 779

Like
0Likes
Like

Posted 20 October 2012 - 09:16 PM

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.

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

what

#7 superman3275   Crossbones+   -  Reputation: 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 ph34r.png!

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 smile.png!


#8 phil67rpg   Members   -  Reputation: 100

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



#9 phil67rpg   Members   -  Reputation: 100

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





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.



PARTNERS