Thread: Trajectory
View Single Post
  #1 (permalink)  
Old 10-12-2008, 08:40 PM
JDCAce's Avatar
JDCAce JDCAce is offline
Member
 
Join Date: Oct 2008
Location: Columbus, GA, US
Posts: 29
JDCAce is on a distinguished road
Send a message via AIM to JDCAce Send a message via MSN to JDCAce Send a message via Yahoo to JDCAce Send a message via Skype™ to JDCAce
Trajectory
I'm making a pong-like applet. This is my first attempt at game programming. I would like my pong ball to ricochet off the paddle at an angle determined by its line of entry (i.e. if it hits straight on, it would fly straight off; if it hits at a 30-degree angle, it would fly off at a 60-degree angle). Imagine a horizontal line with a y value of wherever the ball hit. The angle with sides of that line and the line of entry should be reflected, or mirrored, about that imaginary line. Anyway, you probably know how trajectory works.

This is probably asking too much for now, but I would also like the speed and direction of the paddle's movement to factor in to the trajectory. Many pong-like games I've played have included this. For instance, if the paddle where moving down when the ball hit it, the speed at which the ball is moving down would increase (or the speed at which the ball is moving up would decrease).

I don't feel like I'm making myself clear. Let me know if you don't understand what I'm trying to say.

--------------------------------------------------------------------------

The following is a description of my program, just in case you need it:

My program, as of now, has one ball and one paddle. The paddle follows the y-position of the mouse, while if the x-position is on the left side of the window, the paddle is on the left side, and vice-versa. (That is, the paddle follows the mouse freely up and down while the paddle "snaps" to either the left side or the right side.)

The ball has two speed variables, xSpeed and ySpeed. xSpeed governs how fast the ball moves horizontally (measured in pixels per repaint) and ySpeed measures how fast the ball moves vertically (measured in pixels per repaint). A negative xSpeed denotes travel leftward, while a negative ySpeed denotes travel upward.

Every time the ball collides with a paddle, it reverses xSpeed, but ySpeed remains unchanged. (ySpeed is determined randomly among -1, 0, or 1 when the ball is first set in motion.) A hitCounter increments when the ball hits a paddle. (It is reset if the ball makes it past the paddle.) When the hitCounter reaches a multiple of 5 (5, 10, 15, ...) the xSpeed is incremented (to a maximum of 10).
__________________
"Things are made of littler things that jiggle."
Reply With Quote
Sponsored Links