We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to make a copy of flappy bird, however, I am not sure how to auto-generate the walls for the game as well as the collision detection between the bird and the walls. Would appreciate tips that might help.
Code thus far:
box b = new box();
wall w = new wall();
int startTime;
int screen = 0;
void settings() {
fullScreen();
}
void setup() {
startTime = 3600;
}
void draw() {
if (screen == 0) {
background(#4D7EFF);
b.startBox();
fill(#74FA99);
textSize(70);
text("Welcome to Flappy Box", width/3.6, height/6);
fill(#9B0303);
rect(width/6.4, height/1.5, 400, 140);
rect(width/1.5, height/1.5, 400, 140);
textSize(60);
fill(#74FA99);
text("Start", width/4.7, height/1.34);
text("Instructions", width/1.45, height/1.34);
if (mousePressed && mouseButton == LEFT && mouseX >= width/6.4 && mouseX <= width/6.4 + 400 && mouseY >= height/1.5 && mouseY <= height/1.5 + 140) {
frameCount = 0;
screen = 1;
}
if (mousePressed && mouseButton == LEFT && mouseX >= width/1.5 && mouseX <= width/1.5 + 400 && mouseY >= height/1.5 && mouseY <= height/1.5 + 140) {
screen = 2;
}
}
if (screen == 2) {
background(#4D7EFF);
fill(#9B0303);
rect(width/2.74, height/2.1, 400, 140);
fill(#74FA99);
strokeWeight(3);
line(width/2.56, height/3.9, 880, height/3.9);
textSize(45);
text("Instructions", width/2.56, height/4);
textSize(20);
text("-Press the spacebar or left mouse button to bounce the ball up \n-Avoid all obsacles \n-Try to get as far as you can in 60 seconds", width/2.56, height/3.6);
textSize(60);
text("Start Game", width/2.6, height/1.7);
if (mousePressed && mouseButton == LEFT && mouseX >= 700 && mouseX <= 1100 && mouseY>= 515 && mouseY <= 655) {
frameCount = 0;
screen = 1;
}
}
if (screen == 1) {
background(#4D7EFF);
int timer = (startTime-frameCount)/60;
textSize(50);
fill(0);
text(timer, 1850, 40);
b.createBox();
b.fall();
b.jump();
b.lose();
w.spawnWall();
}
if (screen == 3) {
background(0);
fill(255);
textSize(60);
text("GAME OVER", width/2.7, height/2.8);
textSize(20);
}
textSize(20);
text("x: "+mouseX+" y: "+mouseY, 10, 15);
}
class box {
float boxx;
float boxy;
float ySpeed;
box() {
boxx = 500;
boxy = 500;
}
void startBox() {
fill(#12ff3a);
rect(width/2.4 - 50, height/2.9 - 50, 300, 300);
strokeWeight(0);
fill(#0038ff);
rect(width/2.4 - 50, height/2.9- 50, 150, 150);
fill(0);
rect(width/2.4 - 50, height/2.9 - 50, 80, 80);
}
void createBox() {
fill(#12ff3a);
rect(boxx, boxy, 35, 35);
strokeWeight(0);
fill(#0038ff);
rect(boxx, boxy, 20, 20);
fill(0);
rect(boxx, boxy, 10, 10);
}
void up() {
ySpeed = -10;
}
void fall() {
ySpeed += 0.4;
}
void jump() {
boxy += ySpeed;
}
void lose() {
if (boxy >= height) {
screen = 3;
}
}
}
class wall {
float wallx, wally;
wall() {
wallx = 1600;
wally = random(100, 850);
}
void spawnWall() {
rect(wallx, 0, 30, wally - 50);
rect(wallx, wally + 50, 30, height);
wallx = wallx - 7;
}
void newWall() {
}
}
void keyPressed() {
if (keyPressed && key == ' ') {
b.up();
}
}
void mousePressed() {
if (mousePressed && mouseButton == LEFT) {
b.up();
}
}
Answers
Not exactly Flappy Bird, but there are some moving stick "walls": :bz
http://Studio.ProcessingTogether.com/sp/pad/export/ro.9bTfM49wCIJza
https://Forum.Processing.org/two/discussion/8997/hoppy-beaver