Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (565) Games in Android Showcase (151) games submitted by our members Games in WIP (606) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Pong  (Read 1506 times) 0 Members and 1 Guest are viewing this topic.
CoffeeMonster

Senior Newbie

Coffee games rock!

 « Posted 2007-08-11 09:45:24 »

Hello,

I want to get back into Java Midlets games using MIDP which I enjoyed at Uni because it was relatively simple, but not Flash
Anyway, I've set up Eclipse etc, an improvement over JBuilder at any rate, and I wanted to make a simple Pong game for starters. This is actually a lot simpler than the game I made at Uni (which was a paratrooper type game), but I realised I have no idea how to make the ball bounce off at an angle, you know when it bounces of the edge of the paddle? How is that done? It doesn't just bounce "flat" , IYSMWIM. I suppose I could just hard code angles at certain points, but I assume there is better mathematical way to do it?

Cheers,
CoffeeMonster

--

CoffeeMonster

Senior Newbie

 « Reply #1 - Posted 2007-08-11 11:52:03 »

Calculate the distance from where the ball hits to the centre of the paddle. If you multiply this value by 2 and divide by the length of the panel you will end up with a number between -1 and 1. Then multiply this by some angle constant, say 30 degrees, then apply this angle to the ball. Then the ball angle will change by 30degrees if the ball hits the end, 0 at the centre and a smoot change in angles at other points on the paddle.

This will give you a linear change in angle with respect to the location the ball hits, which seems right to me, but you could make it quadratic by simply squaring the [-1,1] number. Then just mess around with the constant until it feels right.

SimonH
 « Reply #2 - Posted 2007-08-11 13:23:22 »

People make games and games make people
keldon85

Senior Devvie

Medals: 1

 « Reply #3 - Posted 2007-08-11 15:01:12 »

Yes, check out reflection vectors. Long story short there is a calculation that translates the ball's vector to the coordinate space of edge it is bouncing off of followed by a simple reflection at y=0. Dot products will translate to the appropriate planes and then you just flip vector from y=0 and translate back.

Of course paddles are rounded, so the type of reflection is circle/circle with velocity and circle/edge with velocity. I can't remember how you do moving circle/circle collisions but I did write it on the forum somewhere and made code on my computer for it.

CoffeeMonster

Senior Newbie

Coffee games rock!

 « Reply #4 - Posted 2007-08-12 00:18:08 »

Thanks everyone, I knew you'd have good advice. I'll have a read on reflection vectors.

Since I'm on the subject, where did you guys learn all this, is it pure trigonometry or did you learn it specifically from game writing  tutorials/books?

Cheers,
CoffeeMonster

--

CoffeeMonster
keldon85

Senior Devvie

Medals: 1

 « Reply #5 - Posted 2007-08-12 07:32:46 »

I (like most things) learned it by sketching everything on pages upon pages of paper. I studied 3d graphics so I know that [say] multiplying a point by  the axis vectors will translate coordinates to be relative to the axis. I read a few articles on the net, but I always end up having to figure out formulas by myself because I do that better.

Other people (I think) tend to learn it by reading it in books or at school/college/university.

CoffeeMonster

Senior Newbie

Coffee games rock!

 « Reply #6 - Posted 2007-08-16 08:56:14 »

Cool, thanks. What do you think of Java3D? Is it still maintained? Last time I asked most people here prefered the Java OpenGL wrapper (LWGL or something)?

Regards,
CoffeeMonster

--

CoffeeMonster
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 theagentd (11 views) 2015-03-27 23:08:20 wxwsk8er (52 views) 2015-03-20 15:39:46 Fairy Tailz (46 views) 2015-03-15 21:52:20 Olo (28 views) 2015-03-13 17:51:59 Olo (30 views) 2015-03-13 17:50:51 Olo (37 views) 2015-03-13 17:50:16 Olo (43 views) 2015-03-13 17:47:07 ClaasJG (56 views) 2015-03-10 11:36:42 ClaasJG (41 views) 2015-03-10 11:33:01 Pippogeek (47 views) 2015-03-05 14:36:23
 basil_ 22x BurntPizza 21x LiquidNitrogen 21x KevinWorkman 20x EgonOlsen 17x theagentd 16x Roquen 16x princec 11x Varkas 10x 65K 10x SHC 9x Riven 9x Ashedragon 8x phu004 7x wessles 7x lcass 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org