Please recreate a simple game of flappy birds using two classes and incorporate images and ez
java
The project must use EZ and incorporate at least 2 of the following concepts:
Array Lists
Finite State Machines
File reading / parsing
File writing
2D arrays
Inheritance
Private, public member variables and member functions
Solution
Java code for flappy bird are below:
/* * Added frameRate(30) in because the program apparently started going 60fps when it was
configured to run at 30
* */
frameRate(30);
// variables for the width and space in the middle of pipes
var pipeW = 40;
var space = 100;
var endW = pipeW + 10;
var endH = 20;
// space between pipes
var pipeSpace = width / (4 - 1);
// max and min height of pipes
var pipeMaxY = 250;
var pipeMinY = 100;
// speed the pipe\'s move left
var pipeSpeed = 4;
// variables for bird\'s location and movement
var birdX = 100; // x is constant
var birdY = 200;
var birdR = 10;
var birdDY = 0;
// var birdDX = 0;
// PHYSICS
var grav = 1.5;
var jump = 0.15;
var groundY = 350;
var pipeStartLocation = 500;
var pipes = [[pipeStartLocation, random(pipeMinY, pipeMaxY)],
[pipeStartLocation + pipeSpace, random(pipeMinY, pipeMaxY)],
[pipeStartLocation + pipeSpace*2, random(pipeMinY, pipeMaxY)],
[pipeStartLocation + pipeSpace*3, random(pipeMinY, pipeMaxY)]];
noStroke();
var inGame = false;
var inStart = true;
var inGameOver = false;
var score = 0;
var gotFirstPoint = false;
var drawBird = function() {
pushMatrix();
translate(birdX, birdY);
// angle the bird
rotate(-40);
rotate(max(-0, min(120, 20*birdDY)));
// body
stroke(0, 0, 0);
strokeWeight(1);
fill(255, 221, 0);
ellipse(0, 0, birdR*2 - 2, birdR*1.6 - 2);
// belly
fill(255, 170, 0);
arc(0, 0, birdR*2 - 2, birdR*1.6 - 2, 30, 150);
// wing
fill(254, 255, 178);
pushMatrix();
rotate(sin(frameCount * 80) * 15); // flap rotation
ellipse(-birdR*4/5, 0, birdR * 0.9, birdR * 0.6);
popMatrix();
// eye
fill(255, 255, 255);
pushMatrix();
rotate(22);
ellipse(birdR/2, -birdR/3, birdR, birdR * 0.8);
popMatrix();
fill(0, 0, 0);
ellipse(birdR*0.9, -birdR/20, birdR/5, birdR / 3);
// lips
fill(255, 0, 72);
ellipse(birdR/2, birdR*3/5, birdR*0.8, birdR / 4);
ellipse(birdR*0.6, birdR*2/5, birdR, birdR / 4);
noStroke();
popMatrix();
};
var drawGround = function() {
// dirt
fill(214, 189, 145);
rect(0, groundY, 400, 400 - groundY);
// dark green grass
fill(68, 143, 62);
rect(0, groundY, 400, 5);
stroke(82, 179, 85);
// diagonal grass
strokeWeight(3.0);
for(var x = 0; x < 440; x += 10) {
pushMatrix();
translate(x, groundY + 5);
if(!inGameOver) {
translate(-(pipeSpeed*frameCount % 10), 0);
}
rotate(225);
line(0, 2, 0, 5);
popMatrix();
}
noStroke();
};
var drawPipe = function(x, y) {
strokeWeight(4.0);
// pipe body
fill(65, 186, 79);
stroke(0, 0, 0, 180);
rect(x - pipeW / 2, 0, pipeW, y - space / 2); // top
rect(x - pipeW / 2, y + space / 2, pipeW, 400 - y - space / 2 + 10); // bottom
noStroke();
// pipe stripes
colorMode(HSB);
var bodyColW = 5;
for(var c = x - pipeW / 2; c < x + pipeW / 2; .
Please recreate a simple game of flappy birds using two classes and .pdf
1. Please recreate a simple game of flappy birds using two classes and incorporate images and ez
java
The project must use EZ and incorporate at least 2 of the following concepts:
Array Lists
Finite State Machines
File reading / parsing
File writing
2D arrays
Inheritance
Private, public member variables and member functions
Solution
Java code for flappy bird are below:
/* * Added frameRate(30) in because the program apparently started going 60fps when it was
configured to run at 30
* */
frameRate(30);
// variables for the width and space in the middle of pipes
var pipeW = 40;
var space = 100;
var endW = pipeW + 10;
var endH = 20;
// space between pipes
var pipeSpace = width / (4 - 1);
// max and min height of pipes
var pipeMaxY = 250;
var pipeMinY = 100;
// speed the pipe's move left
var pipeSpeed = 4;
// variables for bird's location and movement
var birdX = 100; // x is constant
var birdY = 200;
var birdR = 10;
2. var birdDY = 0;
// var birdDX = 0;
// PHYSICS
var grav = 1.5;
var jump = 0.15;
var groundY = 350;
var pipeStartLocation = 500;
var pipes = [[pipeStartLocation, random(pipeMinY, pipeMaxY)],
[pipeStartLocation + pipeSpace, random(pipeMinY, pipeMaxY)],
[pipeStartLocation + pipeSpace*2, random(pipeMinY, pipeMaxY)],
[pipeStartLocation + pipeSpace*3, random(pipeMinY, pipeMaxY)]];
noStroke();
var inGame = false;
var inStart = true;
var inGameOver = false;
var score = 0;
var gotFirstPoint = false;
var drawBird = function() {
pushMatrix();
translate(birdX, birdY);
// angle the bird
rotate(-40);
rotate(max(-0, min(120, 20*birdDY)));
// body
stroke(0, 0, 0);
strokeWeight(1);
fill(255, 221, 0);
ellipse(0, 0, birdR*2 - 2, birdR*1.6 - 2);
// belly
fill(255, 170, 0);
arc(0, 0, birdR*2 - 2, birdR*1.6 - 2, 30, 150);