Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2007, 12:44 AM
Member
 
Join Date: Jul 2007
Posts: 40
fernando is on a distinguished road
Help with rebound function
Hi, I am trying to make a pong game in java and this is the rebound function for the left paddle. now just to set a few variables:
Code:
x_pos is the balls x position y_pos is the balls y position x_speed is the x speed of the ball radius is only for the ball and is the balls radius. paddle1_x you can guess paddle1_y you can also guess...
Now i did not have a radius for my paddles so the paddle stretches 40 y down and 10 x in width... so without any further ado, heres the code:

Code:
public void bounceToLeft(){ if(x_pos-radius<=paddle1_x+10&&x_pos-radius>=paddle1_x){ if(y_pos<=paddle1_y-40&&y_pos>=paddle1_y){ x_speed=-1; } } }
I call this function in the run method of the applet. Does anyone know why it doesn't work?

Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 09:12 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
public void bounceToLeft(){ if(y_pos + 2*radius > rightPaddle_y && // ball will hit top of paddle y_pos < rightPaddle_y + rightPaddle_height && // ball will hit paddle bottom x_pos + 2*radius > rightPaddle_x) // ball hits paddle side x_speed *= -1; // toggle speed direction } public void bounceToRight() { if(y_pos + 2*radius > leftPaddle_y && // hit top of paddle y_pos < leftPaddle_y + leftPaddle_height && // hit paddle bottom x_pos + x_speed < leftPaddle_x + leftPaddle_width) // hit paddle side x_speed *= -1; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
use of onclick function m4tt New To Java 1 02-16-2008 05:03 AM
Need a little help with a function! Nuluvius New To Java 3 02-08-2008 01:33 AM
I want to add function romina New To Java 1 08-07-2007 07:25 AM
function name osval Advanced Java 1 08-06-2007 10:56 PM
Help with the Dummy Function Felissa JavaServer Pages (JSP) and JSTL 1 07-06-2007 07:03 PM


All times are GMT +3. The time now is 11:32 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org