int bar1X = 500; int bar2X = 200; float gap1Y = random(0,400); float gap2Y = random(0,400); float birdY = 250; float birdSpeed = 3; PImage img; void setup() { size(500,500); img = loadImage("flappy.png"); } void draw() { image(img,0,0); drawBars(); moveBars(); checkForDeath(); drawBird(); moveBird(); } void reset() { bar1X = 500; bar2X = 200; gap1Y = random(0,400); gap2Y = random(0,400); birdY = 250; birdSpeed = 3; } void checkForDeath() { color whereBirdIs = get(250,(int)birdY); if( whereBirdIs==#00ff00 || birdY<0 || birdY>500) { reset(); } } void drawBird() { fill(#FFFF00); ellipse(250,birdY,30,30); } void moveBird() { if( mousePressed ) { birdSpeed = -5; } else { birdSpeed = birdSpeed+.2; } birdY = birdY+birdSpeed; } void drawBars() { fill(#00ff00); noStroke(); rect(bar1X,0,100,gap1Y); //draws top pipe rect(bar2X,0,100,gap2Y); //draws top pipe rect(bar1X,gap1Y+100,100,500); //draws bottom pipe rect(bar2X,gap2Y+100,100,500); //draws bottom pipe //rect(bar1X,0,100,500); //draws green bar //rect(bar2X,0,100,500); //draws green bar //fill(255); //rect(bar1X,gap1Y,100,100); //draws white gap //rect(bar2X,gap2Y,100,100); //draws white gap } void moveBars() { bar1X = bar1X-5; if( bar1X <= -100 ) { bar1X = 500; gap1Y = random(0,400); } bar2X = bar2X-5; if( bar2X <= -100 ) { bar2X = 500; gap2Y = random(0,400); } }