Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 1428 times)
0 Members and 1 Guest are viewing this topic.
Offline 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  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?

Cheers,
CoffeeMonster


--

CoffeeMonster
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 Member


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?

Cheers,
CoffeeMonster

--

CoffeeMonster
Offline keldon85

Senior Member


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

Regards,
CoffeeMonster

--

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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (39 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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
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!