Fappy Bird
Fappy Bird
Fappy Bird
class World {
public ArrayList<float[]> clouds = new ArrayList<float[]>();
public void drawClouds() { for (float[] c : this.clouds) { fill(255);
ellipse(c[0], c[1], c[2], c[3]); noFill(); } }
public void createCloud(float w, float h) { this.clouds.add(new float[]
{random(this.clouds.get(this.clouds.size()-1)[0] + w, width), random(height/5), w,
h}); }
public void createClouds(int times, float w, float h) { for (int ii = 0; ii <
times; ii += 1) { this.clouds.add(new float[] {random(width), random(height/5), w,
h}); } }
}
class Bird {
private int x, y, dy;
private int r, g, b;
private float rad, dia, eyeSize, pupilSize;
private boolean wait = true;
Bird(int x, int y, float rad, float eye, float pupil, int r, int g, int b)
{ this.x = x; this.y = y; this.r = r; this.g = g; this.b = b; this.rad = rad;
this.dia = this.rad*2; this.eyeSize = eye; this.pupilSize = pupil; }
// Calculate distance from center of circle to the upper right corner of the
circle
float[] point_on_circle = pointOnCircle(this.x, this.y, this.rad,
radians(315));
float point_x = point_on_circle[0];
float point_y = point_on_circle[1];
//float dist = sqrt(pow(this.rad, 2) / 2);
fill(255);
circle(point_x, point_y, this.eyeSize);
fill(0);
circle(point_x, point_y, this.pupilSize);
noFill();
}
class Pipe {
private int x, w;
private int r, g, b;
private float y, h;
Pipe(int x, int w, int[] c) { this.x = x; this.w = w; this.r = c[0]; this.g =
c[1]; this.b = c[2]; }
World world;
Bird bird;
ArrayList<Pipe> pipes = new ArrayList<Pipe>();
boolean check_score = true;
float score = 0;
boolean game_over = false;
void setup() {
fullScreen();
frameRate(120);
focused = true;
int x = width/10; int y = height/2; int rad = height/10;
int eye = 100; int pupil = 15;
void draw() {
if (game_over) { noLoop(); }
// Only update the game if the game currently has the focus
if (focused == true) {
background(0, 150, 255);
world.drawClouds();
bird.show();
float br = bird.rad;
for (Pipe p : pipes) {
int px = p.x; float py = p.y; float ph = p.h; int pw = p.w;
p.show();
for (int ii = 0; ii <= 360; ii += 1) {
if (circlePipeCollision(bird, px, 0, pw, py-ph) ||
circlePipeCollision(bird, px, py, pw, height-py)) {
println("YOU COLLIDED WITH A PIPE!");
println("YOUR SCORE: " + round(score));
game_over = true;
break;
}
}
void keyPressed() {
if (game_over == true && key == 89) { loop(); game_over = false; }
if (key == CODED && keyCode == UP) { bird.flap(100); focused = true; bird.wait =
true; }
else { bird.wait = true; }
}