Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

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   GDNet+   -  Reputation: 521

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: 3558

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

"The best comment is a deleted comment."
website · blog

[maintenance in progress]


#3 phil67rpg   GDNet+   -  Reputation: 521

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: 813

Like
0Likes
Like

Posted 19 October 2012 - 05:38 PM

Hmm. What is the significance of the number 220?

#5 phil67rpg   GDNet+   -  Reputation: 521

Like
0Likes
Like

Posted 19 October 2012 - 05:54 PM

it is the top or bottom of the screen

#6 incertia   Crossbones+   -  Reputation: 522

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.

Current project here

#7 superman3275   Crossbones+   -  Reputation: 1373

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 photo editor.

Here's Breakout:
Breakout!

If you need some photo editing done, contact me:
superman3275@gmail.com
if you want some programming help, or are recruiting for a game development team, either PM me on here or email me up there Posted Image!

#8 phil67rpg   GDNet+   -  Reputation: 521

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   GDNet+   -  Reputation: 521

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