<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #paddle - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23paddle</link>
      <pubDate>Sun, 08 Aug 2021 19:31:15 +0000</pubDate>
         <description>Tagged with #paddle - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23paddle/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How do I make two objects collide?</title>
      <link>https://forum.processing.org/two/discussion/25404/how-do-i-make-two-objects-collide</link>
      <pubDate>Wed, 06 Dec 2017 00:10:11 +0000</pubDate>
      <dc:creator>kkyl18</dc:creator>
      <guid isPermaLink="false">25404@/two/discussions</guid>
      <description><![CDATA[<p>I'm building a basic paddleball game, and I'm having trouble making the ball bounce when it comes in contact with the rectangle paddle at the bottom of the screen.</p>
]]></description>
   </item>
   <item>
      <title>Bounce Ball off of Paddle</title>
      <link>https://forum.processing.org/two/discussion/23866/bounce-ball-off-of-paddle</link>
      <pubDate>Sat, 19 Aug 2017 21:35:35 +0000</pubDate>
      <dc:creator>gleister</dc:creator>
      <guid isPermaLink="false">23866@/two/discussions</guid>
      <description><![CDATA[<p>Hey, back again with another question... I got my ball to move, my paddle to display and to move! Now, I just cant seem to get the paddle to reverse the Ball's direction by having it bounce off of it. Ive tried a handful of different methods, but none have been successful. Sometimes the ball just starts bouncing up and down at the top of the screen.</p>

<p>Here is my Code:</p>

<pre><code>    //Gwendolyn Leister - Pong Game
    //Hit the ball with the paddle by moving the mouse left and right 
    //Each time you hit the paddle, your score goes up

    //Many thanks to the two forums that helped me: 
    //<a href="https://forum.processing.org/two/discussion/23862/subclass-won-t-display-or-move-help#latest" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/23862/subclass-won-t-display-or-move-help#latest</a>
    //<a href="https://forum.processing.org/two/discussion/23842/myclass-move-does-not-exist-but-it-does#latest" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/23842/myclass-move-does-not-exist-but-it-does#latest</a>


    //Global Variables
    boolean gameStart = false;

    //Declare Fonts
    PFont myFont;
    PFont myFont2;

    final GamePiece Ball = new Ball();
    final GamePiece Paddle = new Paddle();

    void setup () {
      size(800, 800);
      smooth();
      background(0);
      myFont = loadFont("AnonymousPro-30.vlw"); //smaller text font
      myFont2 = loadFont("AnonymousPro-80.vlw"); //larger title font
    } 

    void draw() {

      background (#0A141F);

      //Layout
      rectMode(CORNER);
      fill(#CBFEFF);
      noStroke();
      rect(0, 640, 800, 260);
      stroke(255);
      fill(#CBFEFF);
      strokeWeight(10);
      line(0, 640, 800, 640);
      fill(#0A141F);
      rect(200, 700, 400, 160);

      //score text 
      textFont(myFont);
      textAlign(RIGHT);
      textSize(20);
      text("Score:", 70, 25);

      //display classes
      Ball.display();
      Paddle.display();

      if (gameStart) { //if the user hits enter to start game and allow subclasses to move/bounce
        Ball.move();
        Ball.bounce();
        Paddle.move();
      } else {  //when enter is not pressed or if it is pressed twice, it will pause the game

        textAlign(CENTER);
        textFont(myFont2);
        textSize(80);
        text("P O N G", 400, 100);
        textSize(20);
        text("press enter to start", 400, 600);
        text("move mouse horizontally to control the", 400, 140);
        text("paddle and to bounce the ball off of", 400, 162);
      }
    }



    // Resource used: <a href="https://processing.org/tutorials/interactivity/" target="_blank" rel="nofollow">https://processing.org/tutorials/interactivity/</a>
    void keyPressed() { //if enter is pressed then the game starts {
      if (keyCode == ENTER) {
        gameStart = !gameStart;
      } else {
      }
    }

    abstract class GamePiece {
      //ball variables
      int rad = 15;
      float xPos=width/2;
      float yPos=height/2;
      float Speed = 6; 
      float xDirection = -2;
      float yDirection = -1;

      int score = 0;//call booleans
      boolean mouseMoved;
      boolean overPaddle = false;
      boolean locked = false;
      float dx=0;

      //paddle variables
      int px=mouseX;
      int py=550;
      int pw=100;
      int ph=30;
      int pSpeed = 5;

      int pDistance = 250; // paddle dis


      //calls
      abstract void move(); 
      abstract void display();
      abstract void bounce();
    }


    class Ball extends GamePiece {
      //Resource used: <a href="https://processing.org/examples/bounce.html" target="_blank" rel="nofollow">https://processing.org/examples/bounce.html</a>


      int rad = 15;
      float xPos=width/2;
      float yPos=height/2;
      float Speed = 5;
      float xDirection = -2;
      float yDirection = -1;

      Ball() {
        super();
      }

      void display() {
        stroke(255);
        strokeWeight(3);
        fill(#FCE1BD);
        frameRate(30);
        ellipseMode(RADIUS);
        ellipse(xPos, yPos, rad, rad);
      }
      void move() { // ball position change
        xPos=xPos+Speed*xDirection;
        yPos=yPos+Speed*yDirection;
      }
      void bounce() { //<a href="https://processing.org/examples/bounce.html" target="_blank" rel="nofollow">https://processing.org/examples/bounce.html</a>

        if (yPos - rad &lt; py + ph/2) { // bounce ball off of paddle
          yDirection = -yDirection;  // when i apply this, then the ball acts crazy

          if (xPos&gt;(width-rad)) { //bounce right side
            xPos = width-rad;
            xDirection=-xDirection;
          }
          if (xPos&lt; rad) { //bounce left side
            xPos = rad;
            xDirection=-xDirection;
          }
          if (yPos&lt;rad) { //bounce top side
            yPos=rad;
            yDirection=-yDirection;
          }

          if (yPos&gt;800) { //falls below screen and relocates ball to inside the frame
            yDirection = -1;
            xPos=width/2;
            yPos=height/2;
          }
        }
      }
    }

    class Paddle extends GamePiece {

      Paddle () {
        super();
      }

      void display() {
        rectMode(CENTER);
        fill(#CBFEFF);
        stroke(255);
        strokeWeight(5);
        rect(mouseX, py, pw, ph);  //moves paddle with mouse
      }

      void move() {
      }

      void bounce () { 
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>myClass.move does not exist (but it does)</title>
      <link>https://forum.processing.org/two/discussion/23842/myclass-move-does-not-exist-but-it-does</link>
      <pubDate>Thu, 17 Aug 2017 18:30:56 +0000</pubDate>
      <dc:creator>gleister</dc:creator>
      <guid isPermaLink="false">23842@/two/discussions</guid>
      <description><![CDATA[<p>Hey all, 
I'm making a game for my online Processing class and I am a bit stuck. I'm very new to the program (and programming in general) so bare with me.  I have called move() in my Ball class but when I call ball.move(); in void draw(), I get an error that says.move() doesn't exist. If anyone could look at my code to see whats wrong with it, I would appreciate it a lot!</p>

<p>My code:</p>

<pre><code>float ballSpeed=5;
float PaddleSpeed=6;
gamePieces paddle;
gamePieces ball;
boolean mousePressed = false;


//paddle p1;

int playerscore = 0;
int cpuscore = 0;
int lastlevel = 3;
boolean keypress = false;
boolean endgame = false;

void setup () {
  size(800, 800);
  smooth();
  background(255);
  ball = new ball();
}

void draw() {
  //table
  background(0);


  //displays

  ball.display();
  if (endgame) {
    textSize(30);
    textAlign(CENTER);
    fill (255);
    text("Click to Start", 400, 100);
  } else {
    if (mousePressed == true) {
      ball.move();
      //paddle.moveX(moveX);

      //paddle.intersectTop(ball);
    }
  }
}
</code></pre>

<p>Ball clas (was in a separate tab)</p>

<pre><code>class ball extends gamePieces {

  // processing.org/examples/bounce.html
  int rad = 20;
  float xpos, ypos;

  float xspeed = 2.6;
  float yspeed = 2.5;

  int xdirection = 1;
  int ydirection = 1;


  ball() {
    super();
  }

  void display() {
    stroke(255);
    strokeWeight(3);
    fill(#FFFEE8);
    frameRate(30);
    ellipseMode(RADIUS);
    ellipse(xpos, ypos, rad, rad);
  }

  void move () {
    xpos = width/2;
    ypos = height/2;

    xpos = xpos + (xspeed * xdirection);
    ypos=+ ypos + (yspeed * ydirection);

    if (xpos &gt; width-rad || ypos &lt; rad) {
      xdirection *= -1;
    }
    if (ypos &gt; height-rad || ypos &lt; rad) {
      ydirection *= -1;
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Paddle For Pong</title>
      <link>https://forum.processing.org/two/discussion/23787/paddle-for-pong</link>
      <pubDate>Sat, 12 Aug 2017 21:29:27 +0000</pubDate>
      <dc:creator>ThatOnePandaGuy</dc:creator>
      <guid isPermaLink="false">23787@/two/discussions</guid>
      <description><![CDATA[<p>So im making a pong game and i have the code for the Right paddle to have the ball get bounced off. Then i copied that code and made some changes for it to "work" for the left paddle. Then i removed the collision for the left and right walls to see if the left paddle worked but i guess it was not. But im not sure what i did wrong. Any help would be great!</p>

<pre><code>float x = 300;
float y = 300;
float velocityX = 2;
float velocityY = 3;
////////////////////
float paddleY;
float paddleX = 20;
float paddleW = 20;
float paddleH = 100;
////////////////////
float ai;
float paddleY2 = 20;
float paddleX2 = 570;
float paddleW2 = 20;
float paddleH2 = 100;

void setup() {
  size(600,680);
}

void draw() {
  x += velocityX;
  y += velocityY;

  background(20);  
  noStroke();
  fill(255);
  rect(x,y,20,20);
  rect(paddleX,paddleY,paddleW,paddleH);
  rect(paddleX2,ai,paddleW2,paddleH2);
  fill(100);
  strokeWeight(2);
  stroke(255);
  rect(-1,0,601,80);
  rect(-1,600,601,80);
  //println(player);
  //println(ballY);
  ai = y-50;
  //paddleY = y-50;

  if (x &lt;= -20) {
    x = 100;
    y = 100;
  } else if (x &gt;= 600) {
    x = 100;
    y = 100;
  }

  /*if (x &gt; 580 || x &lt; 0) {
    velocityX *= -1;
  }*/
  if (y &gt; 580 || y &lt; 80) {
    velocityY *= -1;
  }

  if (x - 20/2 &lt; paddleX + paddleW/2 &amp;&amp; y - paddleH/2 &lt; paddleY + 100/2 &amp;&amp; y + 100/2 &gt; paddleY - paddleH/2) {
    velocityX /= -1;

  }

  if (x + 20/2 &gt; paddleX2 - paddleW2/2 &amp;&amp; y - paddleH2/2 &lt; paddleY + 100/2 &amp;&amp; y + 100/2 &gt; paddleY2 - paddleH2/2) {
    velocityX /= -1;

  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Array of objects &amp; functions</title>
      <link>https://forum.processing.org/two/discussion/22783/array-of-objects-functions</link>
      <pubDate>Sat, 27 May 2017 12:45:52 +0000</pubDate>
      <dc:creator>Alivanar</dc:creator>
      <guid isPermaLink="false">22783@/two/discussions</guid>
      <description><![CDATA[<p>Hi there, 
first of, english is not my native language so i apoligize if i' making some mistakes,
then, in a minigame that i am building w/ the p5.js library, i want to use this array :</p>

<pre lang="javascript">
 bonuses_array = [
   { name: "Paddle_size +", type: "Bonus", status: false, effect: addPSize(), duration: 30, graphic: Paddle_size_plus()},
   { name: "Paddle_speed +", type: "Bonus", status: false, effect: addPSpeed(), duration: 30, graphic: Paddle_speed_plus()},
   { name: "Ball_speed -", type: "Bonus", status: false, effect: reduceBSpeed(), duration: 30, graphic: Ball_speed_minus()},
   { name: "Paddle_size -", type: "Malus", status: false, effect: reducePSize(), duration: 30, graphic: Paddle_size_minus()},
   { name: "Paddle_speed -", type: "Malus", status: false, effect: reducePSpeed(), duration: 30,graphic: Paddle_speed_minus()},
   { name: "Ball_speed +", type: "Malus", status: false, effect: addBSpeed(), duration: 30, graphic: Ball_speed_plus()},
   { name: "Ball_size -", type: "Malus", status: false, effect: reduceBSize(), duration: 30, graphic: Ball_size_minus()},
  ]</pre>

<p>All the functions are defined somewhere else, and the thing i want to achieve is to be able to call bonuses_array[value].graphic(x, y). But it seems that the functions are not defined the right way... Can someone help me ? 
Thanks !!
Ali</p>
]]></description>
   </item>
   <item>
      <title>Questions about the PONG GAME</title>
      <link>https://forum.processing.org/two/discussion/11428/questions-about-the-pong-game</link>
      <pubDate>Wed, 24 Jun 2015 04:03:41 +0000</pubDate>
      <dc:creator>sapphiros</dc:creator>
      <guid isPermaLink="false">11428@/two/discussions</guid>
      <description><![CDATA[<p>Just want to ask some questions about this PONG GAME.
And here is the conditions:
1.the top paddle is controlled by the mouse, and the bottom is controlled by the keyboard.
2.If the ball passes the top or bottom paddle in the y direction, a point is scored (by console), and a new ball is generated.</p>

<p>Now I was stuck in the how to generate a new ball and how to consider if the ball hit the paddle or paddles missed it.</p>

<p>Here are the questions:
1.How can I make relationship between the coordinate of the center of the paddle to the center of the ball? 
   Should I add more conditions in the if block to change the speed of ball which it hits the paddles? 
2.How can I generate a new ball when the both paddles missed the ball? Should I add a boolean named collision and assign it to true? 
   And if it was false the program will generate a new ball? 
Was my method right or wrong? Could you guys give me some hints?</p>

<pre><code>float ballX = 250;
float ballY = 250;
float ballSize = 20;
float ballSpeedX = 3;
float ballSpeedY = 8;
float ballGenSpeed = 3;

float borderTop = 25;
float borderBottom = 450;
float borderLeft = 0;
float borderRight = 450;

float paddleH = 10;
float paddleW = 100;
float paddleSpeed = 15;
float paddleX;

void setup()
{
  size(500, 500);
  background(0);
}

void draw()
{
  background(0);
  ballX += ballSpeedX;
  ballY += ballSpeedY;

  if (ballX &lt; borderLeft || ballX &gt; borderRight)
  {
    ballSpeedX *= -1;
  }
  if (ballY &lt; borderTop+(paddleH*2) || ballY &gt; borderBottom-paddleH)
  {
    ballSpeedY *= -1;
  }

  ellipse(ballX, ballY, ballSize, ballSize);

  boolean collision = true;



  if (!collision) {
    for (int i = 0; i&lt;20; i++)
    {
      float theta = i/20 * 2 * PI;
      float ballDirectX = cos(theta)*ballGenSpeed;
      float ballDirectY = sin(theta)*ballGenSpeed;
      ellipse(ballDirectX, ballDirectY, ballSize, ballSize);
    }
  }

  rect(mouseX, borderTop, paddleW, paddleH);
  rect(paddleX, borderBottom, paddleW, paddleH);
  if (key == CODED) {
    if (keyCode == LEFT &amp;&amp; keyPressed) {
      paddleX -= paddleSpeed;
    } else if (keyCode == RIGHT &amp;&amp; keyPressed) {
      paddleX += paddleSpeed;
    }
  }
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>