Web Analytics Made Easy -
StatCounter java Pong game - CodingForum

Announcement

Collapse
No announcement yet.

java Pong game

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    UNDER CONSTRUCTION

  • #2
    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...
    UNDER CONSTRUCTION

    Comment


    • #3
      Hello warhammerdude20,

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

      you can email to me [email protected]

      Thank you.

      Comment


      • #4
        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???

        Comment


        • #5
          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!

          Comment


          • #6
            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.

            Comment

            Working...
            X