<?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 #collisions - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/p2/feed.rss?Tag=%23collisions</link>
      <pubDate>Sun, 08 Aug 2021 15:23:58 +0000</pubDate>
         <description>Tagged with #collisions - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23collisions/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>making a Gameover screen when a collision occurs</title>
      <link>https://forum.processing.org/two/discussion/25015/making-a-gameover-screen-when-a-collision-occurs</link>
      <pubDate>Wed, 15 Nov 2017 00:28:36 +0000</pubDate>
      <dc:creator>CSoulo</dc:creator>
      <guid isPermaLink="false">25015@/two/discussions</guid>
      <description><![CDATA[<p>Hey I was wondering how I would be able to go about making a gameover screen when a collision occurs. Right now i have a static wall which is called wal2 in the code below and i'm using the dist function to detect when my mouse is touching the ellipse and what I want is for it to change to screen GAMEOVER when the collision is true.</p>

<p><code>void draw() {
 if (screen == MAIN_MENU) {
 MAIN_MENU(); 
} else if 
(screen == INSTRUCTIONS) { 
INSTRUCTIONS(); 
} else if (screen == GAMEOVER) {
 GAMEOVER(); } 
else if (screen == STORY_1) { 
STORY_1(); 
} else if (screen == LEVEL_1) {
 LEVEL_1(); 
}
 }</code>
` // wall collisions//
  boolean collision = true;</p>

<p>if (collision) {
    screen = GAMEOVER;
  } else {
    screen = LEVEL_1;
  }</p>

<p>if (dist(wal1_x, wal1_y, mouseX, mouseY)&lt;=162) {
     collision = true;
  } else { 
    collision = false;
  }`</p>
]]></description>
   </item>
   <item>
      <title>issues passing an instance of one class into another class in P5.js</title>
      <link>https://forum.processing.org/two/discussion/24978/issues-passing-an-instance-of-one-class-into-another-class-in-p5-js</link>
      <pubDate>Sun, 12 Nov 2017 20:56:46 +0000</pubDate>
      <dc:creator>digitalcoleman</dc:creator>
      <guid isPermaLink="false">24978@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to convert some code and am nearly there but realize I do not understand how javascript and P5.js handles passing in an instance of one class to a method of another class. In this case, I am passing an instance of a paddle into the puck for a pong style game.</p>

<pre><code>   ` //in the main program we initialize
    var puck = new Puck(); 
    var left = new Paddle(true);
    var right = new Paddle(false);
    //and then call the method like this
    puck.checkPaddleLeft(left);
    puck.checkPaddleRight(right);
...`


  `  //in the puck class we have this
    function Puck(){
     this.x = 600/2; // Place the puck in the middle of the x axis.
     this.y = 400/2; // Place the puck in the middle of the y axis.
     this.xspeed = 0; // Sets the initial puck speed along the x axis.
     this.yspeed = 0; // Sets the initial puck speed along the y axis.
     this.r = 12; // Establishes the radius of the puck at 12 pixels.
     //reset();

    Puck.protoype.checkPaddleLeft = function(p) { // Function to determine collision between the puck and the left paddle.
      if (y &lt; p.y + p.h/2 &amp;&amp; y &gt; p.y - p.h/2 &amp;&amp; this.x - this.r &lt; p.x + p.w/2) {
        if (this.x &gt; p.x) {
          var diff = y - (p.y - p.h/2);
          var rad = radians(45);
          var angle = map(diff, 0, p.h, -rad, rad);
          this.xspeed = 5 * cos(angle);
          this.yspeed = 5 * sin(angle);
          this.x = p.x + p.w/2 + this.r;
        }
      }
    }
...}`
</code></pre>

<p>When you try to run this, it returns "Cannot set property 'checkPaddleLeft' of undefined"
Any assistance on how to structure such calls is appreciated.</p>
]]></description>
   </item>
   <item>
      <title>How to check if a shape is touching another shape?</title>
      <link>https://forum.processing.org/two/discussion/24789/how-to-check-if-a-shape-is-touching-another-shape</link>
      <pubDate>Sun, 29 Oct 2017 11:36:55 +0000</pubDate>
      <dc:creator>Nautilus</dc:creator>
      <guid isPermaLink="false">24789@/two/discussions</guid>
      <description><![CDATA[<p>How do I check if a shape is touching another shape in p5?
I tried something like this:</p>

<pre><code>if (shape1.x &amp;&amp; shape1.y === shape2.x &amp;&amp; shape2.y) {
    //other code
}
</code></pre>

<p>but it doesn't work.</p>
]]></description>
   </item>
   <item>
      <title>Pong Paddle collision not working</title>
      <link>https://forum.processing.org/two/discussion/24665/pong-paddle-collision-not-working</link>
      <pubDate>Sat, 21 Oct 2017 02:03:17 +0000</pubDate>
      <dc:creator>ControlledCopy</dc:creator>
      <guid isPermaLink="false">24665@/two/discussions</guid>
      <description><![CDATA[<p>So I just started processing...
I'm working on a pong game but the paddle on the left doesn't make the ball bounce o.0
Can someone help?</p>

<p>float ballX=300;
float ballY=100;
float speedX=6;
float speedY=6;
float padY=200;
float padX=970;
float padH=200;
float pad2X=10;
float pad2Y=200;
float pad2H=200;
float padSpeed=35;
void setup()
{
size(1000,600);
}
void keyPressed()
{
if (key==CODED)
{
if (keyCode==UP)
{
padY=padY-padSpeed;
}
if (keyCode==DOWN)
{
padY=padY+padSpeed;
}
}
if (key=='w')
{
pad2Y=pad2Y-padSpeed;
}
if (key=='s')
{
pad2Y=pad2Y+padSpeed;
}
}
void draw()
{
background(255);
fill(#00BC24);
rect(500,0,width/2,height);
if (ballX&lt;width/2)
fill(#00BC24);
else fill(255);
ellipse(ballX,ballY,40,40); //Ball
fill(255);
rect(padX,padY,20,padH);
fill(#00BC24);
rect(pad2X,pad2Y,20,pad2H);</p>

<p>if ((ballX&gt;padX-10) &amp;&amp; (ballY&gt;=padY) &amp;&amp; (ballY&lt;=padY+padH))
speedX=-speedX;
if ((ballX&lt;pad2X+10) &amp;&amp; (ballY&lt;=pad2Y) &amp;&amp; (ballY&lt;=pad2Y+pad2H))
speedX=-speedX;
if (ballY&gt;height)
speedY=-speedY;
if (ballY&lt;0)
speedY=-speedY;
ballX=ballX+speedX;
ballY=ballY+speedY;
}</p>
]]></description>
   </item>
   <item>
      <title>collision with box and player [box]</title>
      <link>https://forum.processing.org/two/discussion/24496/collision-with-box-and-player-box</link>
      <pubDate>Wed, 11 Oct 2017 17:24:20 +0000</pubDate>
      <dc:creator>GeorgeJava</dc:creator>
      <guid isPermaLink="false">24496@/two/discussions</guid>
      <description><![CDATA[<p>PLS help me how to make this collision :(
i create, but i want to disable or anable one side move....</p>
]]></description>
   </item>
   <item>
      <title>"boolean" question! why there is no comma in between two variables?</title>
      <link>https://forum.processing.org/two/discussion/24031/boolean-question-why-there-is-no-comma-in-between-two-variables</link>
      <pubDate>Tue, 05 Sep 2017 00:45:05 +0000</pubDate>
      <dc:creator>soonk</dc:creator>
      <guid isPermaLink="false">24031@/two/discussions</guid>
      <description><![CDATA[<pre><code>class Particle {
  float x, y;
  float r;

  Particle() {
    x = random(width);
    y = random(height);
    r= random (4,30);

  }

  Particle(float tempX, float tempY, float tempR) {

    x=tempX;
    y=tempY;
    r=tempR;
  }

  boolean overlaps(Particle other) {
    float d = dist(x,y,other.x,other.y);
    if (d&lt; r+ other.r){
      return true;
    } else {
      return false;
  }
  }
  void display() {
    stroke(255);
    strokeWeight(4);
    noFill();
    ellipse(x,y,r*2,r*2);
  }
</code></pre>

<p>In the code above, I don't get the logic behind</p>

<pre><code>boolean overlaps(Particle other) {
  float d= dist(x,y,other.x,other.y);
  if(d&lt;r+other.r){
    return true;
  }else{
    return false;
  }
}
</code></pre>

<p>For me it seems like, newly defined function 'overlaps' would take two inputs
one of which is Particle and the other is other.
And it will execute 
with the variable float d 
which represents distance between x&amp;y coordinates of Particle and x&amp;y coordinates of other.
if the distance value is smaller than the sum of radius of Particle and other, 
it will yield the 'true' value.</p>

<p>However,</p>

<p>specifically, for "overlaps(Particle other)",
I think there must be a comma between Particle and other
as 'Particle' also requires commas among each entity going into its round bracket.
like Particle (float tempX, float tempY,float tempZ).</p>

<p>I think I totally don't understand the part from boolean.
can you explain
what the part below is meaning?</p>

<pre><code>boolean overlaps(Particle other) {
  float d= dist(x,y,other.x,other.y);
</code></pre>

<p>I really don't get this part...</p>
]]></description>
   </item>
   <item>
      <title>I fixed my code following comments, but still have some error messages left about too much recursion</title>
      <link>https://forum.processing.org/two/discussion/24225/i-fixed-my-code-following-comments-but-still-have-some-error-messages-left-about-too-much-recursion</link>
      <pubDate>Sat, 23 Sep 2017 16:35:11 +0000</pubDate>
      <dc:creator>soonk</dc:creator>
      <guid isPermaLink="false">24225@/two/discussions</guid>
      <description><![CDATA[<p>Hello Forum,
Really appreciate for y'all comments on mine.
Based off of the comments left from forum, I revised some of my code.
But still facing the error messages about too much recursion.
And I really don't know why I got an error message saying rect (x,y,w,h) also pops me up the same error message.</p>

<p>Can I ask forum to let me know how to fix this problem?
My modified sketch code and class codes are as below.</p>

<p>=Sketch=</p>

<pre><code>Circle c;

Rectangle[] rects = new Rectangle[8];


void setup() {
  size(600,400);
  c = new Circle(0,0,30);
  for (int i=0; i&lt;rects.length; i++) {
    float x = int(random(50,width-50)/50) * 50;
    float y = int(random(50,height-50)/50) * 50;
    rects[i] = new Rectangle(x,y, 50,50);
  }
}


void draw() {
  background(255);


  for (Rectangle r : rects) {
    r.checkCollision(c);  
    r.display();               
  }


  c.update();
  c.display();
}
</code></pre>

<p>=Circle Class=</p>

<pre><code>class Circle {
  float x, y;    // position
  float r;       // radius

  Circle (float tempX, float tempY, float tempR) {
    x = tempX;
    y = tempY;
    r = tempR;
  }

  // move into mouse position
  void update() {
    x = mouseX;
    y = mouseY;
  }

  // draw
  void display() {
    fill(0, 150);
    noStroke();
    ellipse(x,y, r*2, r*2);
  }



}
</code></pre>

<p>=Rectangle Class=</p>

<pre><code>class Rectangle {
  float x, y;            // position
  float w, h;            // size
  boolean hit = false;   // is it hit?
  boolean circleRect(float cx, float cy, float radius, float rx, float ry, float rw, float rh) {


  float testX = cx;
  float testY = cy;


  if (cx &lt; rx)         testX = rx;      // compare left edge
  else if (cx &gt; rx+rw) testX = rx+rw;   // right edge
  if (cy &lt; ry)         testY = ry;      // top edge
  else if (cy &gt; ry+rh) testY = ry+rh;   // bottom edge


  float distX = cx-testX;
  float distY = cy-testY;
  float distance = sqrt( (distX*distX) + (distY*distY) );

  // if the distance is less than the radius, collision!
  if (distance &lt;= radius) {
    return true;
  }
  return false;
}

  Rectangle (float tempX, float tempY, float tempW, float tempH) {
    x = tempX;
    y = tempY;
    w = tempW;
    h = tempH;
  }

  // draw the rectangle
  // if hit, change the fill color
  void display() {
    if (hit) {
    fill(255,150,0);
    }
    else{ 
    fill(0,150,255);
    noStroke();
    rect(x,y, w,h);
  }
  for (Rectangle r : rects) {
  r.checkCollision(c);  // check for collision
  r.display();               // and draw
}
  }
   void checkCollision(Circle c) {
  hit = circleRect(c.x,c.y,c.r, x,y,w,h);
}
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Collision detection</title>
      <link>https://forum.processing.org/two/discussion/24153/collision-detection</link>
      <pubDate>Mon, 18 Sep 2017 00:46:57 +0000</pubDate>
      <dc:creator>mcendon</dc:creator>
      <guid isPermaLink="false">24153@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I am new to processing and I have to submit an assignment regarding motion so I decided to do a moving umbrella under the rain... Now, what I would like and have no idea how to do is to check for collisions between each drop of rain against the umbrella so that they can bounce every time they hit it.</p>

<p>Here is my code</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/902/UNMBJSMQKRD3.png" alt="Screen Shot 2017-09-17 at 4.20.56 PM" title="Screen Shot 2017-09-17 at 4.20.56 PM" />
<img src="https://forum.processing.org/two/uploads/imageupload/311/FRDO1WRNWIH6.png" alt="Screen Shot 2017-09-17 at 7.48.21 PM" title="Screen Shot 2017-09-17 at 7.48.21 PM" />
<img src="https://forum.processing.org/two/uploads/imageupload/396/CJ55LJIWV2G4.png" alt="Screen Shot 2017-09-17 at 7.48.47 PM" title="Screen Shot 2017-09-17 at 7.48.47 PM" />
<img src="https://forum.processing.org/two/uploads/imageupload/732/AJRZ3QCGPVCE.png" alt="Screen Shot 2017-09-17 at 7.49.14 PM" title="Screen Shot 2017-09-17 at 7.49.14 PM" />
<img src="https://forum.processing.org/two/uploads/imageupload/865/OH5IRY32VFR0.png" alt="Screen Shot 2017-09-17 at 7.49.29 PM" title="Screen Shot 2017-09-17 at 7.49.29 PM" /></p>
]]></description>
   </item>
   <item>
      <title>How to reference something else with the same class</title>
      <link>https://forum.processing.org/two/discussion/23967/how-to-reference-something-else-with-the-same-class</link>
      <pubDate>Tue, 29 Aug 2017 22:10:27 +0000</pubDate>
      <dc:creator>Deiplz</dc:creator>
      <guid isPermaLink="false">23967@/two/discussions</guid>
      <description><![CDATA[<p>I'm making a game where the enemies attack each other, how do I do that?</p>

<pre><code>ArrayList &lt;enemy&gt; enemies = new ArrayList &lt;enemy&gt; ();
ArrayList &lt;wall&gt; walls = new ArrayList &lt;wall&gt; ();
void setup() {
  size(1000, 700);
  frameRate(60);

}
void draw() {
  background(0);
      enemy e = new enemy();
  if (frameCount %100==0) {


    enemies.add(e);
  }
  for (int i = enemies.size() - 1; i &gt;= 0; i-=1) {
    enemy zz = enemies.get(i);
    if (zz.isalive==false) {
      enemies.remove(i);
    } else {
      zz.display();
      zz.move(e);
    }
  }
}
//================================================================
class enemy {
  boolean isalive = true, detected = false;
  float x  = -10000, y = -10000, size = 20,lock = -1,identity = random(99999);
  String names = "hi";
  enemy() {
    x  = random(width);
    y  = random(height);
  }
  void display() {
    fill(200, 0, 0);
    rect(x, y, size, size);
  }
  void move(enemy other) {
    if (dist(other.x, other.y, x, y)&lt;other.size + size + 100) {
      detected = true;
      lock = other.identity;
    }
    if (other.isalive ==false) {
      detected = false;
      lock = -1;
    }
    if (detected &amp;&amp; other.identity == lock) {
      if (x &gt; other.x) {
        x -= 5;
      }
      if (x &lt; other.x) {
        x += 5;
      }
      if (y &gt; other.y) {
        y -= 5;
      }
      if (y &lt; other.y) {
        y += 5;
      }
    }
    if (dist(x,y,other.x,other.y)&lt;20){
      other.isalive = true;
    }
  }
}
//==============================================================
class me {
}
//============================================================
class wall {
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to check if free-shaped image has been clicked?</title>
      <link>https://forum.processing.org/two/discussion/23888/how-to-check-if-free-shaped-image-has-been-clicked</link>
      <pubDate>Tue, 22 Aug 2017 10:47:33 +0000</pubDate>
      <dc:creator>MGlolenstine</dc:creator>
      <guid isPermaLink="false">23888@/two/discussions</guid>
      <description><![CDATA[<p>Ok, so I'm trying to make a board game, which is made of small parts like the one below <img src="https://forum.processing.org/two/uploads/imageupload/977/5GG6XBY464IZ.png" alt="A part of the map" title="A part of the map" />.
So, I need vertices, so I can check if the mouse is inside of the image when it's clicked.</p>

<p>Is there any other way I can check if transparent(not 100% transparent, but only parts of it) has been clicked. Without vertices.
I wanted vertices because I could check it with raytracing.</p>
]]></description>
   </item>
   <item>
      <title>collision detection with random objects</title>
      <link>https://forum.processing.org/two/discussion/23833/collision-detection-with-random-objects</link>
      <pubDate>Wed, 16 Aug 2017 14:54:40 +0000</pubDate>
      <dc:creator>netrate</dc:creator>
      <guid isPermaLink="false">23833@/two/discussions</guid>
      <description><![CDATA[<p>I am continuing my learning of how processing with python works.  I have created a small window with a character/rectangle that moves around it using the arrow keys.  I have also included a step counter and score at the bottom of the screen.  All of this works well and I understand it.</p>

<p>The next thing I want to try is adding a random object to the window that will have collision detection PLUS a moving object like a bullet, that fires from one side to the other repeatedly.</p>

<p>BLOCK 
1) I am going to create a random block (same size as the moving rectangle) and place it somewhere in the window
2) If the rectangle hits the block, I want collision detection and for it not to be able to move through it</p>

<p>BULLET
1) The bullet will be something small moving from left to right
2) If the bullet hits the moving rectangle, I want the rectangle to go back to the start.</p>

<p>Right now I have the random block placement, and I tried to make it so that it would be placed on the same coordinates as the rectangle (that is why I am using r1, r2 to round it to an even number).  I am sure there is an easier way of doing it, but this works.</p>

<p>I do not have any collision detection yet.  I thought I might have to add "OR" to the keyReleased conditionals:</p>

<p>if (keyCode == LEFT) and x1&gt;=1 OR</p>

<p>But I am not sure if that would work.  Here is the code so far.  Any help is greatly appreciated it.  And I do understand this isn't probably the most efficient way of doing things, but so far I do understand how I am doing it.</p>

<pre><code>add_library("minim")

x1=100
x2=20
y1=0
y2=20
steps=0

def setup():
    global sf, steps, r1, r2
    size(200, 200)
    background(255) # white
    minim=Minim(this)
    sf=minim.loadFile("light ping.mp3", 2048)
    r1= int(random(5,155))
    r2 = int(r1/10) * 10
    print("This is the random number", r1)
    print("This is the random number", r2)


def draw():
    background(255)
    global x1,y1,x2,y2, steps
    fill(39,79,188)
    rect(r2,r2,x2,y2)

    fill(155)
    stroke(1)
    rect(x1, y1, x2, y2)
    noStroke()
    rect(0,0,5, height-25)
    rect(0,height-25,width, 5)
    rect(width-5, 0, 5, height-25)
    rect(0,0,width, 5)
    # score header
    text("SCORE", 10, height-5) 
    # steps counter
    text(steps, 60, height-5)



def keyReleased():
    global x1, y1, x2, y2, steps
    steps=steps+1
    rect(x1, y1, x2, y2)
    if (key==CODED):
        if (keyCode == LEFT) and x1&gt;=1:
            x1=x1-10
            print(x1)
            rect(x1,y1,x2,y2)            

        elif (keyCode == RIGHT) and x1&lt;=169:
            x1=x1+10
            print(x1)
            rect(x1,y1,x2,y2)

        elif (keyCode == UP) and y1&gt;=1:
            y1=y1-10
            print(y1)
            rect(x1,y1,x2,y2)

        elif (keyCode == DOWN) and y1&lt;=140:
            y1=y1+10
            print(y1)
            rect(x1,y1,x2,y2)

        else:
            fill(255,255,0)
            rect(x1,y1,x2,y2)
            sf.play()
            sf.rewind()
</code></pre>
]]></description>
   </item>
   <item>
      <title>how do I make an impact detector?</title>
      <link>https://forum.processing.org/two/discussion/23726/how-do-i-make-an-impact-detector</link>
      <pubDate>Sun, 06 Aug 2017 14:15:55 +0000</pubDate>
      <dc:creator>Deiplz</dc:creator>
      <guid isPermaLink="false">23726@/two/discussions</guid>
      <description><![CDATA[<p>so far, i've searched up many ways to make an impact detector, but none of them work.
code is down here. how to make a code run when a bullet hits a zombie.</p>

<pre><code>      ArrayList &lt;Bullet&gt; bullets = new ArrayList &lt;Bullet&gt; ();
      PVector me, speed,zombiespeed,Bullet;
      float maxSpeed = 2.5;
      float zombiex;
      float zombiey;
      zombie zombie1;
      zombie zombie2;
      void setup() { 
      rectMode(CENTER);
      size(600, 600);
      me = new PVector();
      speed = new PVector();
      zombiespeed = new PVector();
      Bullet = new PVector();
      noCursor();
      noStroke();
      me.x = 300;
      me.y = 300;
    }
    void draw(){
      background(255);
      //walls
      if (me.x &lt; 0){me.x = 0;}
      if (me.x &gt; width){me.x = width;}
      if (me.y &lt; 0){me.y = 0;}
      if (me.y &gt; height){me.y = height;}
      //zombie movement
      if (zombiex&gt; me.x){zombiex-= random(1,2.5);}
      if (zombiey&lt; me.y){zombiey += random(1,2.5);}
      if (zombiex&lt; me.x){zombiex += random(1,2.5);}
      if (zombiey &gt; me.y){zombiey -= random(1,2.5);}
      //player
      me.add(speed);
      fill(255, 0, 0);
      ellipse(me.x, me.y, 20, 20);
      //zombie
      fill(0,150,50);
      zombie1 = new zombie();
      zombie2 = new zombie();

  //mouse
  PVector mouse = new PVector(mouseX, mouseY);
  fill(0);
  ellipse(mouse.x, mouse.y, 5, 5);
  //shoot
  if (frameCount%20==0 &amp;&amp; mousePressed) {PVector dir = PVector.sub(mouse,me);
  dir.normalize();
  dir.mult(9);
  Bullet b = new Bullet(me, dir);
  bullets.add(b); }
  //bullet movement
  for (Bullet b : bullets) {b.bullup();
  b.bulldis();}
  }
  //bullet class
  class Bullet extends PVector { PVector vel; 
  Bullet(PVector loc, PVector vel) { super(loc.x, loc.y);
  this.vel = vel; }
  void bullup() {add(vel);}
  void bulldis() {fill(0, 150, 55);
  ellipse(x, y, 5, 5);}
  }
  class zombie{PVector pos;
zombie(PVector pos,PVector zom){super (zom.x,zom.y);
  this.pos = pos;}
    void zomup(){add(pos);}
  void zomdis(){fill 0,150,50)
  rect(x,y,25,25);}
  }
}
  //move
  void keyPressed() {
  if (key == 'w'){ speed.y = -maxSpeed; }
  if (key == 's'){ speed.y =  maxSpeed; }
  if (key == 'a'){ speed.x = -maxSpeed; }
  if (key == 'd'){ speed.x =  maxSpeed; }
  }
  //stop
  void keyReleased() {
  if (key == 'w' || key == 's'){ speed.y = 0; }
  if (key == 'a' || key == 'd'){ speed.x = 0; }
  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>[Newbie to p5.js] Making a mini avoidance game, hazard doesn't seem to be showing up?</title>
      <link>https://forum.processing.org/two/discussion/23745/newbie-to-p5-js-making-a-mini-avoidance-game-hazard-doesn-t-seem-to-be-showing-up</link>
      <pubDate>Tue, 08 Aug 2017 13:15:21 +0000</pubDate>
      <dc:creator>FullArt</dc:creator>
      <guid isPermaLink="false">23745@/two/discussions</guid>
      <description><![CDATA[<p>Hi there! I've recently taken up learning p5.js after a friend showed me its potential, and I wanted to try some simple but complete stuff, but I've not worked with anything like this for very long. I've ham-fisted together some of the examples from the p5.js site and youtube, and I got the movement of the player working, but I can't seem to display the hazards. I'm thinking the issue is purely somewhere between line 28 and 53, where the bulk of the hazard's code is but can't quite visualize all the variables physically. Any thoughts?</p>

<pre><code>var canvasWidth = 700;
var canvasHeight = 400;
var yoff = 0.0;   

function setup() { 
  createCanvas(canvasWidth, canvasHeight);
} 


function draw() {
  drawBackground();
    drawCar();
}


//Car (player)
var car = {
  x : 50,
  y : 230,
  draw : function() {
    fill(0);
    rect(this.x, this.y, 50, 50);
    }
}



//Rock (enemies to avoid)
var rocks = [];

function rock(I) {
  I.active = true;
  I.yvelocity = 2;
  I.width = 20;
  I.height = 20;
  I.y = Math.random() * (canvasHeight-I.height);
  I.x = 400;
  I.inBounds = function() {
    return I.x &gt;= 700 &amp;&amp; I.x &lt; canvasWidth + I.width;
  };
  I.draw = function() {
    //fill(0); this comes up as an error every now and then, not sure how to add 
    //this attribute to the var in the array, unlike I did with the car. 
    //The rect attribute also comes up with an error sometimes
    rect(I.x, I.y, I.width, I.height);
  };
  I.update = function() {
    I.active = I.active &amp;&amp; I.inBounds();
    I.x -= I.xvelocity;
  };
  return I;

}


//Background and setting
function drawBackground() { 
  background(175, 213, 255);
  //noStroke();
  fill(225, 212, 160);
  beginShape(); 
    var xoff = 0;     
    // Iterate over horizontal pixels
    for (var x = 0; x &lt;= width; x += 10) {
        // Calculate a y value according to noise, map to 
        var y = map(noise(xoff, yoff), 0, 1, 100,200);
        vertex(x, y); 
        // Increment x dimension for noise
        xoff += 0.05;
    }
    // increment y dimension for noise
    yoff += 0.01;
    vertex(width, height);
    vertex(0, height);
  endShape(CLOSE);
}


//Car controls / drawing
function drawCar() {

  car.draw();
  if (keyIsDown(DOWN_ARROW)) {
    if (car.y + 5 &gt;= 350)
      car.y = 350;
    else
      car.y += 5;
    }
    if (keyIsDown(UP_ARROW)) {
    if (car.y &lt;= 150)
        car.y = 150;
    else
      car.y -= 5;
    }
}

if(Math.random() &lt; 0.05){
    rocks.push(rock({}));
}

rocks = rocks.filter(function(rock){
  return rock.active;
});
rocks.forEach(function(rock){
    rock.update();
  rock.draw();
});
</code></pre>
]]></description>
   </item>
   <item>
      <title>Pong</title>
      <link>https://forum.processing.org/two/discussion/23725/pong</link>
      <pubDate>Sun, 06 Aug 2017 13:39:55 +0000</pubDate>
      <dc:creator>ThatOnePandaGuy</dc:creator>
      <guid isPermaLink="false">23725@/two/discussions</guid>
      <description><![CDATA[<p>Hello, im trying to make a pong game. I have my ball bouncing around but i need to get the ball to bounce off of the paddles. Im not sure how to do this iv looked at the Circle Collision example but its to much for me to understand. If you could make it easier to understand that would be great!</p>
]]></description>
   </item>
   <item>
      <title>Detecting when the mouse is over an object</title>
      <link>https://forum.processing.org/two/discussion/23511/detecting-when-the-mouse-is-over-an-object</link>
      <pubDate>Tue, 18 Jul 2017 20:57:15 +0000</pubDate>
      <dc:creator>howaboutno</dc:creator>
      <guid isPermaLink="false">23511@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>I hope this isn't a duplicate but I haven't found a thread that told me what I wanted to know.</p>

<p>To keep it short, I'm trying to make a little "Pairs" style game and now I'm looking for a way to detect when the mouse is hovering over one of the cards. I have written some code, shown below, that initializes an array, then populates it with the specified number of Objects from the "Card" class and displays them.</p>

<p>If possible, I'd like to be able to trigger a function (change color or something like that) when hovering over the card; if that doesn't work, only triggering something when actually clicking the card would be fine as well.</p>

<p>The only idea I had was to iterate over the array on every MousePressed(), calculate the size of each rect (x and y are stored in the object, width and height are global variables) and compare if MouseX and MouseY are between the rects or not, but that seems really overengineered and it would probably be really slow.</p>

<p>Is there a better way?</p>

<p>Thank you very much!</p>

<pre><code>Card[] cards = new Card [36];

int rows = 6;
int columns = 6;
int cardsize = 75;
int space = 25;
int border = 12;
int cardstotal = (rows * columns);



void setup() {
  size(600, 600);
  background(255, 204, 0);
  int cardsinrow = 0;
  int cardsincolumn = 0;

  // Puts cards where they belong
  for (int i = 0; i &lt; cards.length; i++) {
    cards[i] = new Card((border + (cardsinrow * (cardsize + space))), (border + (cardsincolumn * (cardsize + space))), 1, false);
    cardsinrow++;
    if (cardsinrow &gt;= columns) { // "Line break" for the cards
      cardsinrow = 0;
      cardsincolumn++;
    }
    println(cardsincolumn); // Debug
  }
}

void draw() {

  for (int i=0; i &lt; cards.length; i++) {
    cards[i].display();
  }
}

public class Card {

  int cardposx;
  int cardposy;
  int cardcontent;
  boolean cardstatus;


  Card(int cardposx_, int cardposy_, int cardcontent_, boolean cardstatus_) {
    cardposx = cardposx_;
    cardposy = cardposy_;
    cardcontent = cardcontent_;
    cardstatus = cardstatus_;
  }

  void display() {
    rect(cardposx, cardposy, cardsize, cardsize);
  }
}

// class =======================================================
</code></pre>
]]></description>
   </item>
   <item>
      <title>Making a pacman and having a hard time with collisions</title>
      <link>https://forum.processing.org/two/discussion/23670/making-a-pacman-and-having-a-hard-time-with-collisions</link>
      <pubDate>Tue, 01 Aug 2017 21:01:08 +0000</pubDate>
      <dc:creator>NaZeta</dc:creator>
      <guid isPermaLink="false">23670@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I started a few months ago using processing and I'm also new to OOP. Now I'm doing a pacman, still have to code the ghosts and the pacman's food but I'm having problems with the walls. I've tried looking at other pacman codes so I know there are many ways to check collisions but I can't make it work on my code. I've also checked the jeffreythompson.org web but I still have problems.
To make it short I would like to know, how do I check the collisions? where is a the "right" place to check the collisions, map or pac? And since I'm new to code, if my logic or format is not good and wanna point that out, I'll be happy to learn. Thanks!</p>

<p>The map1 class</p>

<pre><code>class map1 {
  int SIDE = 30; //How big is the rectangle (30x30)
  PImage tile;
  char[][] map = {
  //Where X is a rectangle will be drawn. 
  //1,2,3 and 4 are for portals (which I didn't code yet). 
  //The A is an empty spot, seems like I can't leave the array empty so I filled it with A

    {'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', 'X', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', 'X', 'X', 'X', 'X', 'X', ' ', 'X', 'X', 'X', ' ', 'X', 'X', 'X', ' ', 'X', 'X', 'X', ' ', 'X', 'X', 'X', 'X', 'X', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', 'X', 'X', 'X', ' ', 'X', ' ', 'X', 'X', ' ', 'X', ' ', ' ', ' ', 'X', ' ', 'X', 'X', ' ', 'X', ' ', 'X', 'X', 'X', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', ' ', ' ', ' ', ' ', 'X', ' ', 'X', 'X', ' ', 'X', 'X', 'X', 'X', 'X', ' ', 'X', 'X', ' ', 'X', ' ', ' ', ' ', ' ', ' ', 'X', ' ', 'X', 'X', 'X', 'X', 'X', 'X', 'X'}, 
    {'X', ' ', ' ', ' ', 'X', 'X', ' ', 'X', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', 'X', ' ', 'X', 'X', ' ', ' ', ' ', 'P', 'x', 'x', 'x', 'x', 'x', 'p'}, 
    {'X', ' ', 'X', ' ', 'X', 'X', ' ', 'X', 'X', ' ', 'X', ' ', 'X', 'X', 'X', ' ', 'X', 'X', 'X', ' ', 'X', ' ', 'X', 'X', ' ', 'X', 'X', ' ', 'X', ' ', 'X', 'X', 'X', 'X', 'X', 'X', 'X'}, 
    {'X', ' ', 'X', ' ', 'X', 'X', ' ', 'X', 'X', ' ', 'X', ' ', 'X', 'X', 'X', ' ', 'X', 'X', 'X', ' ', 'X', ' ', 'X', 'X', ' ', 'X', 'X', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', 'X', 'X', ' ', 'X', 'X', 'X', ' ', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', ' ', 'X', 'X', 'X', ' ', 'X', 'X', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', ' ', ' ', 'X', 'X', ' ', ' ', ' ', ' ', ' ', 'X', 'X', 'x', 'x', 'x', 'x', 'x', 'X', 'X', ' ', ' ', ' ', ' ', ' ', 'X', 'X', ' ', ' ', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', 'X', 'X', ' ', 'X', 'X', 'X', ' ', ' ', 'X', 'X', 'X', 'x', 'X', 'X', 'X', ' ', ' ', 'X', 'X', 'X', ' ', 'X', 'X', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', ' ', ' ', ' ', ' ', ' ', 'X', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', 'X', ' ', ' ', ' ', ' ', ' ', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', 'X', ' ', 'X', 'X', ' ', 'X', 'X', ' ', 'X', 'X', 'X', 'X', 'X', 'X', 'X', ' ', 'X', 'X', ' ', 'X', 'X', ' ', 'X', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', ' ', ' ', 'X', 'X', ' ', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', ' ', 'X', 'X', ' ', ' ', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', ' ', ' ', 'X', ' ', ' ', 'X', ' ', ' ', ' ', 'X', ' ', 'X', 'X', ' ', 'X', 'X', ' ', 'X', ' ', ' ', ' ', 'X', ' ', ' ', 'X', ' ', ' ', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', 'X', 'X', ' ', ' ', ' ', 'X', 'X', 'X', ' ', 'X', ' ', ' ', ' ', 'X', ' ', 'X', 'X', 'X', ' ', ' ', ' ', 'X', 'X', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', 'X', 'X', 'X', 'X', ' ', ' ', ' ', ' ', ' ', 'X', ' ', 'X', ' ', 'X', ' ', ' ', ' ', ' ', ' ', 'X', 'X', 'X', 'X', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', ' ', ' ', ' ', ' ', ' ', 'X', 'X', 'X', ' ', ' ', ' ', 'X', ' ', ' ', ' ', 'X', 'X', 'X', ' ', ' ', ' ', ' ', ' ', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', ' ', 'X', ' ', 'X', 'X', 'X', 'X', ' ', 'X', 'X', 'X', 'X', ' ', 'X', 'X', 'X', ' ', 'X', 'X', 'X', 'X', ' ', 'X', 'X', 'X', 'X', ' ', 'X', ' ', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', '3', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', 'X', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '4', 'X', 'A', 'A', 'A', 'A', 'A', 'A'}, 
    {'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'A', 'A', 'A', 'A', 'A', 'A'} };

  map1() {

    tile = loadImage("tile.jpg");
  }

  void display() {

    for (int i = 0; i&lt;23; i++) {

      for (int j = 0; j&lt;37; j++) { 

        if (map[i][j]=='X') { 

          image(tile, j*SIDE, i*SIDE); 
        }
      }
    }
  }
}
</code></pre>

<p>Pac class</p>

<pre><code>class pac {

  int x, y, R, speed = 2;
  String TOUP, TODOWN, TOLEFT, TORIGHT, direction = "TORIGHT";

  pac() {
    x = 465;
    y = 405;
    R = 15; 
  }

  void display() {

    ellipse(x,y,R*2,R*2);
  }

  void move() {

    switch (direction) {

      case "TORIGHT":
          x+=speed;
      break;
      case "TOLEFT":
          x-=speed;
      break;
      case "TOUP":
          y-=speed;
      break;
      case "TODOWN":
          y+=speed;
      break;
      case "NOMOVE":
          //Stop moving if hits a wall
      break;      
    }

    if (keyCode == LEFT) {
      direction = "TOLEFT";
    }
    if (keyCode == RIGHT) {
      direction = "TORIGHT";
    }
    if (keyCode == DOWN) {
      direction = "TODOWN";
    }
    if (keyCode == UP) {
      direction = "TOUP";
    }

  }

  void collision() {


  }

}
</code></pre>

<p>How the game looks so far if helps, don't pay attention to the numbers, I was just trying to make collisions work.
<img src="https://puu.sh/wZ2tr/7151b4a2f1.png" alt="" /></p>
]]></description>
   </item>
   <item>
      <title>How to make 2 moving objects collide?</title>
      <link>https://forum.processing.org/two/discussion/23555/how-to-make-2-moving-objects-collide</link>
      <pubDate>Sat, 22 Jul 2017 15:06:57 +0000</pubDate>
      <dc:creator>rmar15</dc:creator>
      <guid isPermaLink="false">23555@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm currently making this little game where you're a ball and you must dodge other balls, and I want to make that when some ball hits you the game ends, I've read that dist() may help, but I've only seen it work with static objects and the mouse, not both being moving.</p>

<p>This my code:</p>

<pre><code>int a=390;
int b=390;
int c=390;
int d=390;
int e=390;
int f=390;
int g=390;
int h=390;
int i=390;
int j=390;

void setup () {
size (420,420);
}

void draw () {
  background(mouseY +250,mouseY ,0);
  ellipse (mouseX,mouseY, 30,30);
    a=a-5;
    b=b-4;
    c=c-7;
    d=d-5;
    e=e-6;
    f=f-3;
    g=g-5;
    h=h-6;
    i=i-7;
    j=j-3;
    ellipse (30,a+1, 25,25);
    ellipse (75,b+2, 25,25);
    ellipse (120,c+1,25,25);
    ellipse (165,d+2,25,25);
    ellipse (210,e+1,25,25);
    ellipse (255,f+2,25,25);
    ellipse (300,g+1,25,25);
    ellipse (345,h+2,25,25);
    ellipse (390,i+1,25,25);

    if (a&lt;=0)
    a=390;
    if (b&lt;=0)
    b=390;
    if (c&lt;=0)
    c=390;
    if (d&lt;=0)
    d=390;
    if (e&lt;=0)
    e=390;
    if (f&lt;=0)
    f=390;
    if (g&lt;=0)
    g=390;
    if (h&lt;=0)
    h=390;
    if (i&lt;=0)
    i=390;

}
</code></pre>

<p>Any help will be appreciated!</p>
]]></description>
   </item>
   <item>
      <title>Method to count particles?</title>
      <link>https://forum.processing.org/two/discussion/23223/method-to-count-particles</link>
      <pubDate>Tue, 27 Jun 2017 06:13:56 +0000</pubDate>
      <dc:creator>carlosponce</dc:creator>
      <guid isPermaLink="false">23223@/two/discussions</guid>
      <description><![CDATA[<p>Hello Processing community,</p>

<p>I am new with p5.js and I am learning to do some fun simulations with it. But I would like to ask for some help.</p>

<p>I am trying to do a simulation about diffusion. Particles moving randomly from left to right. So far this is what I have done:</p>

<p><a href="https://www.openprocessing.org/sketch/435895" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/435895</a></p>

<p>I would like to know how to count the number of particles crossing the middle wall in the simulation. Or how can I count particles from one region to another?</p>

<p>Please, if you have any advice or a link where I can learn about this, I would appreciate it.</p>

<p>Thanks in advance...</p>
]]></description>
   </item>
   <item>
      <title>Hit Detection of two objects.</title>
      <link>https://forum.processing.org/two/discussion/23286/hit-detection-of-two-objects</link>
      <pubDate>Sun, 02 Jul 2017 17:07:22 +0000</pubDate>
      <dc:creator>LSB_</dc:creator>
      <guid isPermaLink="false">23286@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to find a method, for finding wether two objects have collided, i.e they have the same location. However my For loop won't work as it doesn't even enter it. One object, Snake, has an x and y location, the food or 'apples' also have an x and y location. When they = eachother, it should log ''Collision''. I'll post the code below.</p>

<pre lang="javascript">var snake;
var apples = [];
function setup() {
  createCanvas(600,600);
  frameRate(10);
  snake = new snake();
  for (var i = 0; i &lt; 20; i++) {
    apples.push(new apple(Math.round(random(600) / 10) * 10,Math.round(random(600) / 10) * 10));
  } //generates apples 
}

function draw() {
  background(51);
  snake.update();
  snake.show();
  
  for (var i = 0; i &lt; 20; i++) {
    apples[i].show();
  }
}

function keyPressed() {
  if (keyCode === 87) {
    snake.dir(0,-10);
  } 
  else if (keyCode === 83){
    snake.dir(0,10);
  } 
  else if (keyCode === 65){
    snake.dir(-10,0);}
    
    else if (keyCode === 68) {
    snake.dir(10,0);
    }
  }

function snake() {
  this.x = 300;
  this.y = 300;
  this.xspeed = 0;
  this.yspeed = 0;
  
  this.update = function(){
    this.x = this.x + this.xspeed;
    this.y = this.y + this.yspeed;
    Math.ceil(this.x / 10) * 10;
    Math.ceil(this.y / 10) * 10;
    
    for (var i = 0; i == apples.length - 1; i++){
      if (this.x == apples[i].x &amp;&amp; this.y == apples[i].y){
        console.log ("collision");
      }
    }
  }

  this.show = function() {
    fill(255);
    rect(this.x,this.y,10,10);
  }
  
  this.dir = function(x,y){
    this.xspeed = x;
    this.yspeed = y;
    
  }
}

function apple(x,y) {
  this.x = x;
  this.y = y;
  
  this.show = function() {
    fill(255);
    rect(this.x,this.y,10,10);
  }
}</pre>
]]></description>
   </item>
   <item>
      <title>Controlling 1 object from an ArrayList while maintaining inherited collision properties</title>
      <link>https://forum.processing.org/two/discussion/23259/controlling-1-object-from-an-arraylist-while-maintaining-inherited-collision-properties</link>
      <pubDate>Thu, 29 Jun 2017 21:39:31 +0000</pubDate>
      <dc:creator>somuee</dc:creator>
      <guid isPermaLink="false">23259@/two/discussions</guid>
      <description><![CDATA[<p>Hi There,
I can either get all objects to collide properly but not control my "hero" or I can control my "hero" but not collide (case with code below). How can I control an object from an ArrayList AND have it collide with everything else from the list?
Thanks! EDIT: just fixed a mistake so the hero displays now.</p>

<pre><code>Hero heros;
ArrayList&lt;Actor&gt; actors=new ArrayList&lt;Actor&gt;();

void setup() {
  size(1600, 800);
  addActors();
}

void draw() {
  background(120, 120, 255);
  for (int i=0; i&lt;actors.size(); i++) {
    Actor currActor=actors.get(i);

    for (int j = i + 1; j &lt; actors.size(); j++) {
      Actor otherActor = actors.get(j);
      if (currActor.hitActor(otherActor)) {
        currActor.resolveHitActor(otherActor);
      }
    }
    currActor.update();
  }
  heros.update();
  heros.handleCollision();
  heros.force();
}

void keyPressed () {
  heros.keyPressed();
}
void keyReleased () {
  heros.keyReleased();
}

void addActors () {
  for (int i=0; i&lt;10; i++) {
    actors.add(new Baddy(new PVector(random(50, width-50), random(50, width-50)), new PVector(random(2, 4), random(2, 4)), random(20, 50)));
    actors.add(new BossBaddy(new PVector(random(50, width-50), random(50, width-50)), new PVector(random(2, 4), random(2, 4)), random(20, 50)));
  }
  heros=new Hero(new PVector(random(50, width-50), random(50, width-50)), new PVector(random(2, 4), random(2, 4)), 100);
}

//ACTOR CLASS
class Actor {
  PVector pos;
  PVector vel;
  PVector grav;
  float diameter;

  Actor(PVector pos, PVector vel, float diameter) {
    this.pos = pos;
    this.vel = vel;
    //   size = s;
    this.diameter = diameter;
    grav = new PVector(0, 0.2);
  }

  // Check for collisiond between actors
  boolean hitActor (Actor other) {
    if (dist(pos.x, pos.y, other.pos.x, other.pos.y) &lt; diameter/2 + other.diameter/2) {
      return true;
    }
    return false;
  }
  //resolve collision
  void resolveHitActor(Actor other) {
    float angle = atan2(pos.y - other.pos.y, pos.x - other.pos.x);
    float avgSpeed = (vel.mag() + other.vel.mag())*0.49;
    vel.x = avgSpeed * cos(angle);
    vel.y = avgSpeed * sin(angle);
    other.vel.x = avgSpeed * cos(angle - PI);
    other.vel.y = avgSpeed * sin(angle - PI);
  }

  void update() {
    move();
    wallCollision();
    drawMe();
  }

  void move() {
    pos.add(vel);
    vel.add(grav);
  }

  void wallCollision() {
    if ((pos.x &gt; width - diameter/2) || (pos.x &lt; 0 + diameter/2)) {
      vel.x = vel.x * -1;
    }
    if (pos.y &gt; height - 100) {
      vel.y = vel.y *-0.95;
      pos.y = height- 100;
    }
  }

  void drawMe() {
    pushMatrix ();
    fill(0);
    translate(pos.x, pos.y);
    ellipse(0, 0, diameter, diameter);
    popMatrix ();
  }
}
//BADDY CLASS
class Baddy extends Actor {

  Baddy(PVector pos, PVector vel, float diameter) {
        super (pos, vel, diameter);
        this.diameter = diameter;

  }

  void drawMe() {
    pushMatrix();
    strokeWeight(5);
    stroke(255, 255, 0);
    fill(0, 255, 0);
    translate(pos.x, pos.y);
    ellipse(0, 0, diameter, diameter);
    popMatrix();
  }
}
//BOSSBADDY CLASS
class BossBaddy extends Baddy {

  BossBaddy(PVector pos, PVector vel, float diameter) {
        super (pos, vel, diameter);
    this.diameter = diameter;
  }

  void drawMe (){
    pushMatrix ();
    translate (pos.x, pos.y);
    noStroke();
    fill(255, 0, 0);
    ellipse(0, 0, diameter, diameter);
    popMatrix ();
  }
}

//HERO CLASS

class Hero extends Actor {
  float damp = 0.9;
  float angle;
  boolean up = false;
  boolean down = false;
  boolean left = false;
  boolean right = false;

  Hero(PVector pos, PVector vel, float diameter) {
        super (pos, vel, diameter);
    this.diameter = diameter;
  }

  void force(){
  PVector upForce = new PVector (0, -2);
  PVector downForce = new PVector (0, 2);
  PVector leftForce = new PVector (-2, 0);
  PVector rightForce = new PVector (2, 0);

  if (up) accelerate(upForce);
  if (down) accelerate(downForce);
  if (left) accelerate(leftForce);
  if (right) accelerate(rightForce);
  }

  void keyPressed () {

    if (key == 'w') up = true;
    if (key == 's') down = true;
    if (key == 'a') left = true;
    if (key == 'd') right = true;
  }

  void keyReleased () {
    if (key == 'w') up = false;
    if (key == 's') down = false;
    if (key == 'a') left = false;
    if (key == 'd') right = false;
  }
  void update() {
    move();
    drawMe();
  }
  void move() {
    pos.add(vel);
    vel.mult(damp);
  }
  void accelerate(PVector force) {
    vel.add(force);
  }
  void handleCollision() {
    if ((pos.x &gt; width - diameter) || (pos.x &lt; 0 + diameter)) {
      vel.x = vel.x * -1.8;
    }
    if (pos.y &lt; 0 + diameter/2 + 20) {
      vel.y = vel.y * -1;
      pos.y = 0 + diameter/2 + 20;
    }
    if (pos.y &gt; height - 100) {
      vel.y = vel.y *-0.05;
      pos.y = height- 100;
    }
  }
  void drawMe() {
 translate (pos.x, pos.y);
 fill(255 );
 ellipse(0,0, diameter, diameter);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>if anyone can put collision detection between the object and sponge bob character? appreciate it</title>
      <link>https://forum.processing.org/two/discussion/22165/if-anyone-can-put-collision-detection-between-the-object-and-sponge-bob-character-appreciate-it</link>
      <pubDate>Mon, 24 Apr 2017 13:51:52 +0000</pubDate>
      <dc:creator>guppy9988</dc:creator>
      <guid isPermaLink="false">22165@/two/discussions</guid>
      <description><![CDATA[<pre><code>//Falling Game
//Kyle Foster

PImage bkg, catcher, object;

int direction = 1;
int i = 1;

//catcher
int cX = 300;
int cY = 390;

//object
int oX = int(random(1,600));
int oY = 0;
int speed = int(random(1,10));
int oX2 = int(random(1,600));
int oY2 = 0;
int speed3 = int(random(2,4));
int oX3 = int(random(1,600));
int speed2 = int(random(1,2));
int oY3 = 0;

int random=0;

void setup() {
  size (700, 525);
  catcher = loadImage("2015-07-14-1436902565-6235018-SpongeBob_5.png");
  object = loadImage("76259-spongebob-square-pants-burger.png");
  bkg = loadImage("Krusty_Krab_kitchen.png");
}

void draw() {

  background(bkg);
//Objects
oY = oY + speed;
oY = oY +5;

image(object,oX,oY);
  image(catcher, cX, cY);
  if(oY&lt;=900){
  }
  else{
    oY = int(random(-1,-600));
    oX = int(random(1,729));
  }
  image(object,oX2,oY2);
  oY2 = oY2 +5;
  oY2 = oY2 +speed3;
  if(oY2&lt;=900){
  }
  else{
    oY2 = int(random(-1,-300));
    oX2 = int(random(1,729));
  }
  image(object,oX3,oY3);
  oY3 = oY3 +5;
  oY3 = oY3 + speed2;

 //code that stops spongebob at sides of screen
  cX = constrain(cX, 0, width-110);

 //keypressed
  if (keyPressed &amp;&amp; (key == CODED)) {
    if (keyCode == LEFT) {
      cX = cX - 10;
    } else if (keyCode == RIGHT) {
      cX =cX+10;
    }
  } 

  if (keyPressed) {
    if (key == 'a') {
      cX = cX - 10;
    } else if (key == 'd') {
      cX =cX+10;
    }
  } 
 //mousex and mouse y
  println(mouseX, mouseY);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Collision Detection</title>
      <link>https://forum.processing.org/two/discussion/23052/collision-detection</link>
      <pubDate>Tue, 13 Jun 2017 12:31:33 +0000</pubDate>
      <dc:creator>koogs</dc:creator>
      <guid isPermaLink="false">23052@/two/discussions</guid>
      <description><![CDATA[<p>Read this - it contains many examples written using Processing</p>

<p><a href="http://www.jeffreythompson.org/collision-detection/" target="_blank" rel="nofollow">http://www.jeffreythompson.org/collision-detection/</a></p>

<p>Table of Contents:</p>

<p><a href="http://www.jeffreythompson.org/collision-detection/table_of_contents.php" target="_blank" rel="nofollow">http://www.jeffreythompson.org/collision-detection/table_of_contents.php</a></p>

<p>(you might want to use dist() rather than calculating the distance yourself though...)</p>

<p>more here: <a href="http://happycoding.io/tutorials/processing/collision-detection" target="_blank" rel="nofollow">http://happycoding.io/tutorials/processing/collision-detection</a></p>
]]></description>
   </item>
   <item>
      <title>How to make 2 moving images collide?</title>
      <link>https://forum.processing.org/two/discussion/22966/how-to-make-2-moving-images-collide</link>
      <pubDate>Tue, 06 Jun 2017 23:47:15 +0000</pubDate>
      <dc:creator>brianna0811</dc:creator>
      <guid isPermaLink="false">22966@/two/discussions</guid>
      <description><![CDATA[<p>I want to have the panda (which the user moves with left and right arrow keys) collide with a candy image which is falling from the top left of the screen. When the 2 images collide, it would say "YOU TOUCHED THE CANDY" on the screen and the console. But when the panda and candy touch, nothing happens.</p>

<p>Here is the link to the code (I couldn't figure out how to indent the code on here):
<a href="https://paste.ofcode.org/sBSTST866aqUv5xkzWJ84g" target="_blank" rel="nofollow">https://paste.ofcode.org/sBSTST866aqUv5xkzWJ84g</a></p>

<p>I tried doing if (pandaX==xPosCandy &amp;&amp; pandaY==yPosCandy ) 
But it didn't work.
I also tried doing if (pandaX&gt;xPosCandy &amp;&amp; pandaY&lt;yPosCandy ) but it says YOU TOUCHED THE CANDY too soon.</p>

<p>Any help would be appreciated, and let me know if you need more code. Thanks!</p>
]]></description>
   </item>
   <item>
      <title>I have a current code but I need to make the outer squares move, please help</title>
      <link>https://forum.processing.org/two/discussion/22759/i-have-a-current-code-but-i-need-to-make-the-outer-squares-move-please-help</link>
      <pubDate>Thu, 25 May 2017 15:10:53 +0000</pubDate>
      <dc:creator>KingSpagooter</dc:creator>
      <guid isPermaLink="false">22759@/two/discussions</guid>
      <description><![CDATA[<pre><code>// =================================================================
//Variables
StopWatchTimer sw;
float x = 0;
float y = 100;
float speed = 1;
// =================================================================
// Main
void setup() {
  size(700, 560);
  println (millis());
  sw = new StopWatchTimer();
  sw.start();
  rectMode(CENTER);
}
// Draw
void draw () {
  time();
  println(mouseX);
  println(mouseY);
  stroke (153);
  fill (204, 102, 0);
  rect (555, 275, 50, 50);
  rect (345, 475, 50, 50);
  rect (115, 275, 50, 50);
  rect (345, 75, 50, 50);
  frame.setTitle(int(frameRate) + " fps");
  fill (235, 235, 0);
  noStroke();
  rect (mouseX, mouseY, 30, 30);
}
// =================================================================
// Other
void time() {
  background(#C9C9C9);
  fill(#000000);
  textAlign(CENTER);
  text(nf(sw.minute(), 2)+":"+nf(sw.second(), 2), 656, 14);
}
// =================================================
// classes
class StopWatchTimer {
  int startTime = 0, stopTime = 0;
  boolean running = false; 
  void start() {
    startTime = millis();
    running = true;
  }
  void stop() {
    stopTime = millis();
    running = false;
  }
  int getElapsedTime() {
    int elapsed;
    if (running) {
      elapsed = (millis() - startTime);
    } else {
      elapsed = (stopTime - startTime);
    }
    return elapsed;
  }
  int second() {
    return (getElapsedTime() / 1000) % 60;
  }
  int minute() {
    return (getElapsedTime() / (1000*60)) % 60;
  }
}
// ====================================================
//High Rez
void saveHiRes(int scaleFactor) {
  PGraphics hires = createGraphics(width*scaleFactor, height*scaleFactor, JAVA2D);
  beginRecord(hires);
  hires.scale(scaleFactor);
  draw();
  endRecord();
  hires.save("hires.png");
}
//=======================================================
//collision 
boolean mouseOverRect(int x, int y, int w, int h) {
  return (mouseX &gt;= x &amp;&amp; mouseX &lt;= x+w &amp;&amp; mouseY &gt;= y &amp;&amp; mouseY &lt;= y+h);
}
// =====================================================
void move() {
  x = x + speed;
  if (x &gt; width) {
    x = 0;
  }
}
void display() {
  rect(x,y,30,10);
}``
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to check if you clicked an image</title>
      <link>https://forum.processing.org/two/discussion/22861/how-to-check-if-you-clicked-an-image</link>
      <pubDate>Thu, 01 Jun 2017 16:04:21 +0000</pubDate>
      <dc:creator>Epicness35</dc:creator>
      <guid isPermaLink="false">22861@/two/discussions</guid>
      <description><![CDATA[<p>Hello . I have an image and want to check if the user clicked it, and print a value. How would I do this? Thanks for any help!</p>
]]></description>
   </item>
   <item>
      <title>How to resume movement once my sprite has hit a wall?</title>
      <link>https://forum.processing.org/two/discussion/22842/how-to-resume-movement-once-my-sprite-has-hit-a-wall</link>
      <pubDate>Wed, 31 May 2017 13:46:39 +0000</pubDate>
      <dc:creator>dgreen154</dc:creator>
      <guid isPermaLink="false">22842@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I've finally got my sprite to stop at a wall. Now, I'm having trouble figuring out a way to resume it's movement once it hits black. My goal is to make a maze game and I'm doing it by pixel colour. So if colour == black then stop movement... Also, when I hold a direction, the sprite keeps moving whether I am pressing a key or not. Any thoughts? Help? Ideas?</p>

<pre><code>PImage sprite;
int x = 580;
int y = 200;
int black = -16777216;
int speed = 3;
void setup(){
  size(800, 600);
  smooth();
  frameRate(60);
  sprite = loadImage("scaled_sprite.png");
}

void draw(){
  fill(0);
  rect(0,0, 400,2000);
  fill(255);
  rect(400,0, 400,2000);
  image(sprite,x,y);

  color c = get(x,y);
  if(c != black ){
  if ((keyPressed == true) &amp;&amp; (key == 'w')) {
    y-=speed;
  }
  if ((keyPressed == true) &amp;&amp; (key == 'a')) {
    x-=speed;
  }
   if ((keyPressed == true) &amp;&amp; (key == 's')) {
    y+=speed;
  }
    if ((keyPressed == true) &amp;&amp; (key == 'd')) {
    x+=speed;
  }
  }



println(c);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Hit detection</title>
      <link>https://forum.processing.org/two/discussion/22778/hit-detection</link>
      <pubDate>Sat, 27 May 2017 00:39:35 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">22778@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to do hit detection using invisible (not yet) rects over top of the image. For some reason these two rects keep moving up and down on the y-axis? Does anyone know how to easily stop it? If you move your mouse you will see the hits. 
They rects are stationary but when I log off the site and then log back on, the rects often have moved up or down the y-axis. Then I change the y variable to get them right and it just happens again. 
Thank you</p>

<p><a href="https://openprocessing.org/sketch/429876" target="_blank" rel="nofollow">https://openprocessing.org/sketch/429876</a></p>
]]></description>
   </item>
   <item>
      <title>How do I Make it so When the Green Square Touches the Blue Rectangle it Teleports to the Start</title>
      <link>https://forum.processing.org/two/discussion/22716/how-do-i-make-it-so-when-the-green-square-touches-the-blue-rectangle-it-teleports-to-the-start</link>
      <pubDate>Mon, 22 May 2017 17:03:15 +0000</pubDate>
      <dc:creator>zero000</dc:creator>
      <guid isPermaLink="false">22716@/two/discussions</guid>
      <description><![CDATA[<p>How do I make it so when the green square touches the blue rectangle it teleports to the start with an array.
This is for a frogger game.
Here is my code:</p>

<pre><code>int x = 250;
int y = 475;
int xPos=225;
int xDir=3;
int xPos2=200;
int xDir2=2;
int xPos3=25;
int xDir3=1;
int xPos4=25;
int xDir4=2;
void setup()
{
  size(500,500);

}
void car()
{
  if(dist(x, y, xPos,150) &lt; 15) {

// hit

x=250;

y=475;

}
    fill(255,0,0);
    rect(xPos, 150, 25, 25);
  xPos=xPos+xDir;
  if (xPos&gt;width || xPos&lt;20)
  {
    xDir=-xDir;
  }
  if(dist(x, y, xPos2, 275) &lt; 15) {



x=250;

y=475;

}
  rect(xPos2,275,25,25);
  xPos2=xPos2+xDir2;
  if (xPos2&gt;width || xPos2&lt;20)
  {
    xDir2=-xDir2;
  }
  }
  void log() {


   fill(128,64,0);
   rect(xPos3, 80, 125, 35);

  xPos3=xPos3+xDir3;
  if (xPos3&gt;width || xPos3&lt;20)
  {
    xDir3=-xDir3;
  }
  fill(128,64,0);
   rect(xPos4, 42, 125, 37);

  xPos4=xPos4+xDir4;
  if (xPos4&gt;width || xPos4&lt;20)
  {
    xDir4=-xDir4;
  }
  }
void draw()
{
    fill(0);
  rect(0,115,500,325);

  fill(0,128,0);
  rect(0,350,500,375);
  fill(0,0,255);
  rect(0,0,500,125);
  fill(1,50,32);
  rect(0,0,500,41);
  for(int a=25; a &lt; width; a=a+100)
{
  fill(255,255,0);
  rect(a,215,45,10);}

  log();

  fill(0,255,0);
  rect(x,y,25,24);
  car();

}

void keyPressed() {
  if (key == CODED) {
    if (keyCode == UP) {
      y -= 35;
    } else if (keyCode == DOWN) {
      y += 35;
    } else if (keyCode == LEFT) {
      x -= 35;
    } else if (keyCode == RIGHT) {
      x += 35;
    }  
  } 
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Need help on circle collision! Thanks</title>
      <link>https://forum.processing.org/two/discussion/22751/need-help-on-circle-collision-thanks</link>
      <pubDate>Thu, 25 May 2017 01:56:06 +0000</pubDate>
      <dc:creator>JaeY</dc:creator>
      <guid isPermaLink="false">22751@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I really need help on this project I have to finish within 5 hours. I have random circles coming down the screen, with a red circle in the middle. My goal is to make it so that if the Red circle comes in contact with any grey circle, they both disappear. Thank you so much for the help!</p>
]]></description>
   </item>
   <item>
      <title>Problem regarding ArrayList</title>
      <link>https://forum.processing.org/two/discussion/22678/problem-regarding-arraylist</link>
      <pubDate>Sat, 20 May 2017 10:18:34 +0000</pubDate>
      <dc:creator>jcov</dc:creator>
      <guid isPermaLink="false">22678@/two/discussions</guid>
      <description><![CDATA[<p>Hey,</p>

<p>Just wondering if anyone can help me out with this bit of code.</p>

<p>I'm trying to remove an ellipse that's drawn to the screen after I've clicked it. Not sure how to approach the problem?</p>

<pre><code>ArrayList &lt;ball&gt; balls = new ArrayList &lt;ball&gt;();
int numOfBalls = 5;
float dist;

class ball {

  float x, y;

  ball() {

    x = random(20, width-20);
    y = random(20, height-20);
  }

  void draw_ball () {
    ellipse(x, y, 20, 20);
  }

  void remove_ball () {
    for (int i = numOfBalls-1; i &gt;=0; i--) {

      dist = sqrt((x-mouseX) * (x-mouseX) + (y-mouseY) * (y-mouseY));
      if (dist &lt;= 20) {

        balls.remove(i);
      }
    }
  }
}

void setup () {
  size(500, 500);
  for ( int i = 0; i &lt; numOfBalls; i++)
    balls.add(new ball());
}

void draw () {
  for ( int i = 0; i &lt; numOfBalls; i++)
    balls.get(i).draw_ball();
}

void mousePressed() {

  remove_ball();
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>