# Flappy bird colision help

**URL:** https://discourse.processing.org/t/flappy-bird-colision-help/9736
**Category:** Coding Questions
**Created:** [March 28, 2019, 10:15pm UTC](https://discourse.processing.org/t/flappy-bird-colision-help/9736 "2019-03-28T22:15:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bobbobbobbob](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@bobbobbobbob](https://discourse.processing.org/u/bobbobbobbob)
#### Post date: [March 28, 2019, 10:15pm UTC](https://discourse.processing.org/t/flappy-bird-colision-help/9736/1 "2019-03-28T22:15:27Z")

</div>

```auto
int rectX2;
float r2;
int rectX;
float r;
float v = -1;
float y = 300;
void setup() {
  size(600, 600);
  background(0);
  r = random(50, 450);
  rectX = 550;
  r2 = random(50, 450);
  rectX2 = 1100;
}

void draw() {
  background(0);
  y+=v;
  v+=.25;
  ellipse(300, y, 50, 50); 
  ellipseMode(CENTER ); 
  rect(rectX, r - 500, 100, 500 );
  rect(rectX, r + 150, 100, 500 );
  rect(rectX2, r2 - 500, 100, 500 );
  rect(rectX2, r2 + 150, 100, 500 );
  rectX-=3; 
  if (rectX<=-50){
   rectX=rectX2 + 550;
  }
  rectX2-=3; 
  if (rectX2<=-50){
   rectX2=rectX + 550;
  }
  println(rectX,rectX2);
 }

void keyPressed() {
  if (key==' ')v-=9;
}

```

i need help adding collision between the circle and rectangle for flappy bird

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [March 29, 2019, 1:27am UTC](https://discourse.processing.org/t/flappy-bird-colision-help/9736/2 "2019-03-29T01:27:30Z")

</div>

> **[Collision Detection](http://jeffreythompson.org/collision-detection/circle-rect.php)**
>
> An online book about collision detection using Processing.

---

<div class="post-metadata">

### Author: ![bobbobbobbob](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@bobbobbobbob](https://discourse.processing.org/u/bobbobbobbob)
#### Post date: [March 29, 2019, 2:35am UTC](https://discourse.processing.org/t/flappy-bird-colision-help/9736/3 "2019-03-29T02:35:09Z")

</div>

im still new to processing and dont know how to directly implement the into my code

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [March 29, 2019, 4:07am UTC](https://discourse.processing.org/t/flappy-bird-colision-help/9736/4 "2019-03-29T04:07:06Z")

</div>

> [@bobbobbobbob](#):
>
> still new

understand, but actually that is the point,  
that you asked ? after one day play ?  
for something not so basic,

> and please not angry

while your game ( show ) looks like a good start!  
the code not.  
and i hope you allow me to show you a other way  
( program structure, variable … )  
what later / regarding your question / will pay off.

a rewrite of your code as a example  
( sorry, no collision code )

> **click here**
>
> ```auto
> 
> // CANVAS
> int cw = 600;
> int ch = 600;
> color cb = color(200, 200, 0);
> boolean showFPS = true;
> 
> void settings() {
> size(cw, ch);
> }
> 
> void setup() {
> pipe1_init();
> pipe2_init();
> }
> 
> // BIRD
> float bx = 100, by = 0;
> float br = 25;
> float bv = 2, bdv = 0.25, bjv = -5;
> color bfill = color(0, 200, 0);
> color bstroke = color(200, 100, 200);
> int bstrokew = 2;
> 
> void bird() {
> fill(bfill);
> strokeWeight(bstrokew);
> stroke(bstroke);
> ellipse(bx, by, 2*br, 2*br);
> by += bv; // for next draw loop
> //bv += bdv; //??
> if ( by > height - br ) by = height - br; // stop fall down 
> if ( keyPressed && key == ' ' ) by += bjv;
> }
> 
> // PIPES
> float pgap = 150, pstart = 50, pw = 100, ph = ch, pspeed = 2;
> float p1x = cw, p1y = 0;
> float p2x = 1.5*cw, p2y = 0; // generate a uneaven space between the pipes
> color pfill = color(100, 100, 0);
> color pstroke = color(50, 50, 0);
> int pstrokew = 8;
> 
> void pipe1_init() {
> p1y = random(pstart, ch - pstart-pgap);
> println("p1x "+nf(p1x, 1, 1)+" p1y "+nf(p1y, 1, 1));
> }
> void pipe2_init() {
> p2y = random(pstart, ch - pstart-pgap);
> println("p2x "+nf(p2x, 1, 1)+" p2y "+nf(p2y, 1, 1));
> }
> 
> void pipe() {
> fill(pfill);
> strokeWeight(pstrokew);
> stroke(pstroke);
> // pipe 1
> rect(p1x, p1y, pw, -ph);  
> rect(p1x, p1y+pgap, pw, ph);
> p1x -= pspeed; // pipe 1 xpos
> if ( p1x <= -pw ) { 
> p1x = cw;
> pipe1_init(); // new random hight
> }
> // pipe 2
> rect(p2x, p2y, pw, -ph);  
> rect(p2x, p2y+pgap, pw, ph);
> p2x -= pspeed; // pipe 2 xpos
> if ( p2x <= -pw ) { 
> p2x = cw;
> pipe2_init(); // new random hight
> }
> }
> 
> void draw() {
> background(cb);
> if ( showFPS ) surface.setTitle("Flappy Bird "+nf(frameRate, 1, 1));
> else surface.setTitle("Flappy Bird 1.0.1");
> bird();
> pipe();
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [March 30, 2019, 5:21pm UTC](https://discourse.processing.org/t/flappy-bird-colision-help/9736/5 "2019-03-30T17:21:00Z")

</div>

> [@bobbobbobbob](#):
>
> adding collision between the circle and rectangle

> [@bobbobbobbob](#):
>
> dont know how to directly implement the into my code

GoToLoop gave you a link to a working example sketch. You read the tutorial, and you can run that circle-rect collision tutorial sketch in PDE (without changing anything) and see it working, yes?

When you say “directly implement that into my code” – what are you now trying to do, specifically, that you are having trouble with?
