|
-
Nov 2nd, 2005, 02:09 PM
#1
Thread Starter
Fanatic Member
Making a pong computer
Hello,
I'm finished with my two player pong game. I have no idea how to make a computer to follow the label towards the ball... does anyone know how?
I searched up examples and tried figuring it out but their code was very confusing
-
Nov 2nd, 2005, 02:22 PM
#2
Re: Making a pong computer
Moved to Games and Graphics.
-
Nov 2nd, 2005, 06:12 PM
#3
Frenzied Member
Re: Making a pong computer
 Originally Posted by paralinx
I searched up examples and tried figuring it out but their code was very confusing 
How so?
Just make the paddle's vertical position equal to the ball's vertical position and you can never lose. 
If you are going to limit the speed of the computer's paddle then the simplest method is to test if the ball is above or below the paddle and then move the paddle in the appropriate direction.
This does make it difficult to deal with balls that have a high vertical speed.
Another option is calculate the path of the ball, where it bounces off the walls and where it will cross the paddle's path.
Then you place the paddle there and wait for the ball.
This is for defensive AI.
Offensive AI would need to decide how to play the ball back to the player.
Will it go fast and straight?
Will it bounce up and down rapidly?
-
Nov 2nd, 2005, 06:14 PM
#4
Fanatic Member
Re: Making a pong computer
That shouldn't be too hard. In each loop cycle, simply subtract the paddle's Yval by the Ball's Yval. If the value is negative, move the paddle up, and if the value is positive, move the paddle down (assuming the scale is with 0,0 on the top left corner). The most advance AI will keep with the ball exactly (although that would make it actually impossible to beat), and a lesser difficulty will have a slower moving paddle, or not start calculating until the ball is halfway towards them or something like that.
-
Nov 4th, 2005, 09:55 AM
#5
Addicted Member
Re: Making a pong computer
This is how i would do it.
VB Code:
DAmount = ball.top - paddle.top
if DAmount <0 then
paddle.top = paddle.top - 10
elseif DAmount >0 then
paddle.top = paddle.top + 10
end if
-
Nov 4th, 2005, 02:30 PM
#6
Frenzied Member
Re: Making a pong computer
Or just:
paddle.top = ball.top
-
Nov 7th, 2005, 09:43 AM
#7
Re: Making a pong computer
 Originally Posted by jeroen79
Or just:
paddle.top = ball.top

not a great method because the paddle would appear to jump at the start!
-
Nov 7th, 2005, 12:45 PM
#8
Frenzied Member
Re: Making a pong computer
That's a matter of setting things up properly.
-
Nov 7th, 2005, 12:49 PM
#9
Re: Making a pong computer
yea, but evan so its not the best method in the world no offence intended its just clumsy programming
Pino
-
Nov 7th, 2005, 02:05 PM
#10
Frenzied Member
Re: Making a pong computer
How is it clumsy?
You want the paddle to follow the ball.
This will make it do just that with minimal effort.
Of course, this will make the game very un-fun as you can't beat the AI.
But that is a different thing.
-
Nov 7th, 2005, 02:15 PM
#11
Re: Making a pong computer
It is clumsy as it does not take into account things such as the speed of the bat, size of the bat/ball, time to change direction, prediction of ball position, etc.
As you pointed out, it would also be no fun to play against.
-
Nov 8th, 2005, 04:24 PM
#12
Frenzied Member
Re: Making a pong computer
Actually, it doesn't need all those things.
The difference with other methods is that this one assumes total and direct control over the bat's position.
Other methods have direct and total control over the bat's position but can merely control the speed (up to a limit) and direction of the bat
So the 'clumsy' method would be suited for the gods while us mere mortals have to do with other methods of control.
Just to illustrate that in some cases lesser performance actually requires more work in software.
-
Nov 8th, 2005, 04:58 PM
#13
Fanatic Member
Re: Making a pong computer
That was incredibly vague, what the heck are you talking about?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|