...

View Full Version : java Pong game



warhammerdude20
02-20-2004, 06:28 PM
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
02-20-2004, 10:32 PM
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...

weronpc
02-28-2004, 07:04 AM
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.

samamateurcoder
05-28-2008, 02:54 PM
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???

twodayslate
05-29-2008, 05:21 AM
Here is how I do random numbers.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html

import java.util.Random;
Random gen = new Random();
double random double = gen.nextDouble() * 50; //Random double of 1-50

malfist
06-02-2008, 10:17 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum