Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-20-2004, 05:28 PM   PM User | #1
warhammerdude20
Regular Coder

 
Join Date: Dec 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
warhammerdude20 is an unknown quantity at this point
Question java Pong game

i have a problem with the pong game im making with java...

i have everything done in the game exept i cant make the ball bounce off the paddle. does anyone know how to do this?
also, i would like to know how to generate a random number in java

thanks
warhammerdude20 is offline   Reply With Quote
Old 02-20-2004, 09:32 PM   PM User | #2
warhammerdude20
Regular Coder

 
Join Date: Dec 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
warhammerdude20 is an unknown quantity at this point
ive figured out how to make a random number...

double rn=Math.floor(Math.random()*5);

same as javascript!!! i still need help with the collision thing but now i have yet another question... i have a function called shootBall:

public void shootBall(){
double rn1=Math.floor(Math.random()*2);
double rn2=Math.floor(Math.random()*2);
x_pos=150;
y_pos=150;
if(rn1==0.0)x_speed=1;
if(rn1==1.0)x_speed=-1;
if(rn2==0.0)y_speed=1;
if(rn2==1.0)y_speed=-1;
}

x_speed is the balls x speed and y_speed is the balls y speed.

it works for the most part but the ball will only will shoot right... how do i fix this?

again thanks...
warhammerdude20 is offline   Reply With Quote
Old 02-28-2004, 06:04 AM   PM User | #3
weronpc
Regular Coder

 
Join Date: Apr 2003
Location: Canada, Ontario, Mississauga
Posts: 312
Thanks: 0
Thanked 0 Times in 0 Posts
weronpc is an unknown quantity at this point
Hello warhammerdude20,

I am very interesting on how to create the game, can you send me your code?

you can email to me weronpc@yahoo.ca

Thank you.
weronpc is offline   Reply With Quote
Old 05-28-2008, 01:54 PM   PM User | #4
samamateurcoder
New to the CF scene

 
Join Date: May 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
samamateurcoder is an unknown quantity at this point
pong game error

hi guys...i am thru wth the code for pong game but i have a few prblems..
whenever my ball is hitting or missing the score doesnt changes on the panel instead of that it changes on the ms dos window..can anyone help me in this...also i am not able to change the color of the ball and bar and background does anyone knows about this???
samamateurcoder is offline   Reply With Quote
Old 05-29-2008, 04:21 AM   PM User | #5
twodayslate
Senior Coder

 
twodayslate's Avatar
 
Join Date: Mar 2007
Location: VA
Posts: 1,042
Thanks: 67
Thanked 39 Times in 39 Posts
twodayslate is on a distinguished road
Here is how I do random numbers.
http://java.sun.com/j2se/1.4.2/docs/...il/Random.html
Code:
import java.util.Random;
Random gen = new Random();
double random double = gen.nextDouble() * 50; //Random double of 1-50
__________________
twitter | Quality Hosting - $5.95/mo*
Feel free to PM me!
twodayslate is offline   Reply With Quote
Old 06-02-2008, 09:17 PM   PM User | #6
malfist
Regular Coder

 
Join Date: May 2008
Posts: 188
Thanks: 7
Thanked 7 Times in 7 Posts
malfist is an unknown quantity at this point
Quote:
Originally Posted by samamateurcoder View Post
hi guys...i am thru wth the code for pong game but i have a few prblems..
whenever my ball is hitting or missing the score doesnt changes on the panel instead of that it changes on the ms dos window..can anyone help me in this...also i am not able to change the color of the ball and bar and background does anyone knows about this???
Post up some code and we might be able to help.
malfist is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:27 PM.


Advertisement
Log in to turn off these ads.