How can I make a circular version of pong in Java?

In summary, the author is trying to make a game similar to the classic pong game, but does not seem to understand how the paddle moves around.
  • #1
techy
1
0
hi,

I have been trying to make a game similar to pong in java. But I do not understand the concept of bouncing of the paddle. the paddle moves around in a circle. Here is the code that I have for the vector class that takes in the position of the paddle as a vector.
Java:
public class Vector {
     double dx, dy;
 
    public Vector(int x, int y) {
        dx = 1.*x;
        dy = 1.*y;
    }
   
    public double dot(Vector V){
        return this.dx * V.dx + this.dy * V.dy;
    }
   
    public static final Vector UX = new Vector(1, 0);
    public static final Vector UY = new Vector(0, 1);
    public static final Vector ZERO = new Vector(0, 0);
   
   
    public Vector(double dr, double theta) {
        setRTheta(dr, theta);
    }
   
    private void setRTheta(double dr, double theta) {
        dx = dr*Math.cos(theta);
        dy = dr*Math.sin(theta);
    }
   
    public void setX(int x){
        dx = x;
    }
   
    public void setY(int y){
        dy = y;
    }
   
    public int getX(){
        return (int)dx;
    }
   
    public int getY(){
        return (int)dy; 
    }

    public double getR() {
        return Math.hypot(dx, dy);
    }

    public double getTheta() {
        return Math.atan2(dy, dx);
    }

    public Vector multiply(double d) {
        return new Vector(this.dx * d, this.dy * d);
    }
    public void add(Vector v) {
        dx += v.dx;
        dy += v.dy;
    }

    public Vector subtract(Vector v)
    {
        return new Vector(this.dx - v.dx, this.dy - v.dy);
    }
   
    public void reflect(double angle) {
        setRTheta(-getR(), 2*angle-getTheta());
    }
   
    public void reflectP(Vector v){
        Vector unitVector = new Vector(v.dx/Math.sqrt(v.dx * v.dx + v.dy * v.dy), v.dy/Math.sqrt(v.dx * v.dx + v.dy * v.dy));
        double dotProduct = this.dot(unitVector);
        Vector result = unitVector.multiply(2 * dotProduct).subtract(this);
        dx = result.dx;
        dy = result.dy;
//        dx = dx - 2*(v.dx/Math.sqrt(v.dx * v.dx + v.dy * v.dy) + this.dx) * //v.dx/Math.sqrt(v.dx * v.dx + v.dy * v.dy);
//        dy = dy - 2*(v.dy/Math.sqrt(v.dx * v.dx + v.dy * v.dy) + this.dy) * //v.dy/Math.sqrt(v.dx * v.dx + v.dy * v.dy);
    }
   
    public String toString(){
        return  " "  + dx + " "  + dy;  
    }
}

Can somebody please help me with this?
 
Last edited by a moderator:
Technology news on Phys.org

1. What is the objective of circular pong?

The objective of circular pong is to bounce a ball back and forth between two players using circular paddles, without letting the ball touch the center of the circle. The first player to reach a predetermined number of points wins.

2. How is circular pong different from traditional pong?

Circular pong differs from traditional pong in its use of circular paddles and a circular playing field. This creates a more dynamic and challenging gameplay experience, as players must adjust their angle and timing to hit the ball.

3. Are there any variations of circular pong?

Yes, there are several variations of circular pong, such as speed pong where the ball moves at a faster pace, and multi-player circular pong where more than two players can participate. These variations add new challenges and excitement to the game.

4. What skills does circular pong help develop?

Circular pong helps develop hand-eye coordination, reflexes, and strategy as players must quickly anticipate the movement of the ball and adjust their paddle accordingly. It also promotes teamwork and communication in multi-player versions.

5. Is circular pong considered a physically demanding game?

Circular pong can be physically demanding, especially in longer games or when played at a faster pace. The constant movement and quick reflexes required can also provide a good workout for the arms and core muscles.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
749
  • Programming and Computer Science
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
991
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
Back
Top