• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Pong problems

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I wasn't sure whether to post in Micro Edition forum or not as this relates to my attempts to make a pong game for my phone. I'm trying to work my way through the simple games...if I can master Pong, Tetris will be next!

The problem I'm having is that I'm unsure as to how to get the ball to move at angles from a paddle once it strikes one.

Currently how I'm trying to do it is:



I've tried to get the ball to move by changing its x direction when it collides with a paddle (so dx = 1, then dx = -dx) but the ball does not move very realistically as it seems to always head back in the same direction after each collision.

I was thinking that I could check to see what section of the paddle the ball collided with and use that to pick which value to set dx as -1 / +1.

I'd be really grateful of any tips, I don't really want to go looking at other people's source code on the net.

Thanks

Tony
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I have one logic which i did in flash ..
When the ball comes calculate the angle at which it came , then reflect it back at that angle to the opposite side ... This is wat i ve done in flash.
 
Tony Craven
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

...When the ball comes calculate the angle at which it came , then reflect it back at that angle to the opposite side...



Thanks for the reply.

I was starting to come to this conclusion myself, it sounds like Snell's Law in Physics. I'll give it a go!

Tony
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if (ball & paddle collision) // reverse the ball's vertical direction dy = -dy; if (ball & wall collision) // reverse the ball's horizontal direction dx = -dx;

I think your code is ok except you need some change for the angle.
[ February 19, 2008: Message edited by: Austin Lee ]
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep track of the accelleration of the paddle and apply some extra dy or -dy. Kinda like adding spin to a serve in real ping pong.
 
Tony Craven
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the long delay in replying, thanks a million for your suggestions. I got it working in the end by splitting the paddle up into 5 sections and if the ball hit one of the sections, I'd set it's return vector from a predefined list.
 
reply
    Bookmark Topic Watch Topic
  • New Topic