Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (593)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Pong  (Read 1554 times)
0 Members and 1 Guest are viewing this topic.
Offline CoffeeMonster

Senior Newbie

Coffee games rock!

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


I want to get back into Java Midlets games using MIDP which I enjoyed at Uni because it was relatively simple, but not Flash  Grin
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?



Offline askoruli

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.

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

Google 'reflection vector'

People make games and games make people
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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.

Offline 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?



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

Offline 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)?



Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Riven (19 views)
2015-07-03 11:22:16

deepthought (45 views)
2015-06-30 15:39:44

deepthought (49 views)
2015-06-30 15:39:09

deepthought (62 views)
2015-06-30 15:36:52

Za\'Anzabar (29 views)
2015-06-29 05:44:54

TritonDreyja (44 views)
2015-06-24 17:10:40

CopyableCougar4 (43 views)
2015-06-23 00:34:45

BurntPizza (46 views)
2015-06-21 20:36:46

cookiecompiler (88 views)
2015-06-11 15:42:53

cookiecompiler (51 views)
2015-06-11 15:41:14
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!