SlideShare a Scribd company logo
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; c += bodyColW) {
fill(68, 230, 170 + (x - c) / bodyColW * 20);
rect(c, 0, bodyColW, y - space / 2);
rect(c, y + space / 2, bodyColW, 400 - y - space / 2 + 10); // bottom
}
// pipe end
fill(65, 186, 79);
stroke(0, 0, 0, 180);
rect(x - endW / 2, y - space / 2 - endH, endW, endH, 3); // top
rect(x - endW / 2, y + space / 2, endW, endH, 3); // bottom
noStroke();
// end stripes
colorMode(HSB);
var endColW = 5;
for(var c = x - endW / 2; c < x + endW / 2; c += endColW) {
fill(68, 230, 170 + (x - c) / endColW * 20);
rect(c, y - space / 2 - endH, endColW, endH);
rect(c, y + space / 2, endColW, endH); // bottom
}
colorMode(RGB);
};
var drawBackground = function() {
// clouds
fill(244, 245, 235);
for(var x = 0; x <= 400; x += 40) {
var noiseScale = 0.02;
var noiseVal = noise(-x*noiseScale);
ellipse(x, groundY, noise(noiseVal) * 120, noiseVal * 220);
}
// hills/trees
fill(98, 209, 102, 240);
stroke(66, 128, 42);
for(var x = 0; x <= 400; x += 20) {
var noiseScale = 0.02;
var noiseVal = noise(x*noiseScale);
ellipse(x, groundY, noise(noiseVal)*50, noiseVal * 100);
}
noStroke();
};
var draw = function() {
if(inGame) {
background(139, 205, 214);
drawBackground();
for(var i = 0; i < pipes.length; i++) {
drawPipe(pipes[i][0], pipes[i][1]);
}
drawGround();
drawBird();
fill(76, 73, 153, 200);
stroke(0, 0, 0, 130);
rect(18, 358, 200, 40, 10);
fill(255, 255, 255);
text("Score: " + score, 20, 390);
noStroke();
// making the bird fall
birdDY += grav;
birdY += birdDY;
if(birdY < birdR) {
birdY = birdR;
}
if(birdDY < 0 && birdDY > -space / 10) {
birdDY += 1;
}
// move pipes
for(var i = 0; i < pipes.length; i++) {
pipes[i][0] -= pipeSpeed;
}
// make new pipe when farthest right one is pipeSpace away from right
if(pipes[pipes.length - 1][0] <= width - pipeSpace) {
pipes.push([400 + endW, random(pipeMinY, pipeMaxY)]);
}
// delete offscreen left pipes
if(pipes[0][0] < -endW) {
pipes.shift();
score++;
}
// check for collision
var collision = false;
var birdTop = birdY - birdR;
var birdBottom = birdY + birdR;
var birdLeft = birdX - birdR;
var birdRight = birdX + birdR;
if(!gotFirstPoint && birdX > pipes[0][0]) {
gotFirstPoint = true;
score++;
}
if(birdBottom >= groundY) {
collision = true;
} else {
for(var i = 0; i < pipes.length; i++) {
// if not too for left or right
var tooLeft = birdRight < pipes[i][0]-endW/2;
var tooRight = birdLeft > pipes[i][0]+endW/2;
if(!tooLeft && !tooRight) {
var tooHigh = birdBottom < pipes[i][1] + space/2;
var tooLow = birdTop > pipes[i][1] - space/2;
if(!tooHigh || !tooLow) {
// using end pipe left/rights this means collision
collision = true;
break;
}
} else {
//inColX = false;
}
}
}
if(collision) {
inGame = false;
inGameOver = true;
}
} else if(inStart) {
background(139, 205, 214);
drawBackground();
drawGround();
fill(255, 255, 255, 127);
stroke(0, 0, 0, 127);
rect(65, 62, 187, 50, 10);
noStroke();
textFont(loadFont("Tahoma", 36), 36);
fill(68, 143, 62);
text("Flappy Bird", 70, 100);
stroke(0, 0, 0);
if(mouseX >= 70 && mouseX <= 70 + 100 && mouseY >= 250 && mouseY <= 250 + 50)
{
fill(73, 173, 64);
if(mouseIsPressed) {
inGame = true;
inStart = false;
}
}
rect(70, 250, 100, 50, 5);
fill(0, 0, 0);
text("Start", 80, 290);
noStroke();
drawBird();
} else if(inGameOver) {
background(139, 205, 214);
drawBackground();
for(var i = 0; i < pipes.length; i++) {
drawPipe(pipes[i][0], pipes[i][1]);
}
drawGround();
drawBird();
fill(255, 255, 255, 127);
stroke(0, 0, 0, 127);
rect(80, 110, 280, 150, 15);
noStroke();
fill(0, 0, 0);
textFont(loadFont("Tahoma", 36), 36);
text("Game Over Try again!", 100, 150);
text("Final Score: " + score, 85, 250);
if(birdY + birdR < groundY) {
birdDY++;
birdY += birdDY;
} else if(birdY + birdR > groundY) {
birdY = groundY - birdR*0.8;
}
}
};
var lastMousePress = millis();
var mousePressed = function() {
lastMousePress = millis();
if(inGame) {
birdDY = -space*jump;
}
};

More Related Content

Similar to Please recreate a simple game of flappy birds using two classes and .pdf

Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
Ismar Silveira
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
fonecomp
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
contact32
 
Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala
Sri Ambati
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
armcomputers
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
calderoncasto9163
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노
Chiwon Song
 
A simple snake game project
A simple snake game projectA simple snake game project
A simple snake game project
Amit Kumar
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
pramode_ce
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swift
Chiwon Song
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascript
Reece Carlson
 
Project hotel on hotel management fo
Project  hotel on hotel management foProject  hotel on hotel management fo
Project hotel on hotel management fo
Sunny Singhania
 
i need an input of this program.  anything good or bad.  what could .docx
i need an input of this program.  anything good or bad.  what could .docxi need an input of this program.  anything good or bad.  what could .docx
i need an input of this program.  anything good or bad.  what could .docx
ursabrooks36447
 
Need help with questions 2-4. Write assembly code to find absolute v.pdf
Need help with questions 2-4. Write assembly code to find absolute v.pdfNeed help with questions 2-4. Write assembly code to find absolute v.pdf
Need help with questions 2-4. Write assembly code to find absolute v.pdf
feelinggifts
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
명신 김
 

Similar to Please recreate a simple game of flappy birds using two classes and .pdf (20)

Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Ssaw08 0624
Ssaw08 0624Ssaw08 0624
Ssaw08 0624
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Virtual inheritance
Virtual inheritanceVirtual inheritance
Virtual inheritance
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
 
Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노
 
A simple snake game project
A simple snake game projectA simple snake game project
A simple snake game project
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swift
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascript
 
Project hotel on hotel management fo
Project  hotel on hotel management foProject  hotel on hotel management fo
Project hotel on hotel management fo
 
i need an input of this program.  anything good or bad.  what could .docx
i need an input of this program.  anything good or bad.  what could .docxi need an input of this program.  anything good or bad.  what could .docx
i need an input of this program.  anything good or bad.  what could .docx
 
Need help with questions 2-4. Write assembly code to find absolute v.pdf
Need help with questions 2-4. Write assembly code to find absolute v.pdfNeed help with questions 2-4. Write assembly code to find absolute v.pdf
Need help with questions 2-4. Write assembly code to find absolute v.pdf
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Include
IncludeInclude
Include
 
Rkf
RkfRkf
Rkf
 

More from meerobertsonheyde608

Discuss the seven factors that analysts consider where selecting a f.pdf
Discuss the seven factors that analysts consider where selecting a f.pdfDiscuss the seven factors that analysts consider where selecting a f.pdf
Discuss the seven factors that analysts consider where selecting a f.pdf
meerobertsonheyde608
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
meerobertsonheyde608
 
Conduct some basic research on the recessive disorder Albinism.Des.pdf
Conduct some basic research on the recessive disorder Albinism.Des.pdfConduct some basic research on the recessive disorder Albinism.Des.pdf
Conduct some basic research on the recessive disorder Albinism.Des.pdf
meerobertsonheyde608
 
calculate the next annual dividend payment for stock currently selli.pdf
calculate the next annual dividend payment for stock currently selli.pdfcalculate the next annual dividend payment for stock currently selli.pdf
calculate the next annual dividend payment for stock currently selli.pdf
meerobertsonheyde608
 
Bookmark On the Isle of Man off the coast of Ireland, a curious cat .pdf
Bookmark On the Isle of Man off the coast of Ireland, a curious cat .pdfBookmark On the Isle of Man off the coast of Ireland, a curious cat .pdf
Bookmark On the Isle of Man off the coast of Ireland, a curious cat .pdf
meerobertsonheyde608
 
Answer the questions below based on the database model found on the n.pdf
Answer the questions below based on the database model found on the n.pdfAnswer the questions below based on the database model found on the n.pdf
Answer the questions below based on the database model found on the n.pdf
meerobertsonheyde608
 
You are reviewing basic network protocols with a new tech in your co.pdf
You are reviewing basic network protocols with a new tech in your co.pdfYou are reviewing basic network protocols with a new tech in your co.pdf
You are reviewing basic network protocols with a new tech in your co.pdf
meerobertsonheyde608
 
Why might a gene have more than 2 different allelesa.     DNA seq.pdf
Why might a gene have more than 2 different allelesa.     DNA seq.pdfWhy might a gene have more than 2 different allelesa.     DNA seq.pdf
Why might a gene have more than 2 different allelesa.     DNA seq.pdf
meerobertsonheyde608
 
Which of the following are true statementsI. sin2+cos2=1II. sec.pdf
Which of the following are true statementsI. sin2+cos2=1II. sec.pdfWhich of the following are true statementsI. sin2+cos2=1II. sec.pdf
Which of the following are true statementsI. sin2+cos2=1II. sec.pdf
meerobertsonheyde608
 
What scientific mechanism for evolution did Charles Darwin and Alfred.pdf
What scientific mechanism for evolution did Charles Darwin and Alfred.pdfWhat scientific mechanism for evolution did Charles Darwin and Alfred.pdf
What scientific mechanism for evolution did Charles Darwin and Alfred.pdf
meerobertsonheyde608
 
What is the main difference between doing business process analysis .pdf
What is the main difference between doing business process analysis .pdfWhat is the main difference between doing business process analysis .pdf
What is the main difference between doing business process analysis .pdf
meerobertsonheyde608
 
What are the genetic differences between a processed pseudogene and .pdf
What are the genetic differences between a processed pseudogene and .pdfWhat are the genetic differences between a processed pseudogene and .pdf
What are the genetic differences between a processed pseudogene and .pdf
meerobertsonheyde608
 
True or False_____ Cells Composed of chemicals and structures, ma.pdf
True or False_____ Cells Composed of chemicals and structures, ma.pdfTrue or False_____ Cells Composed of chemicals and structures, ma.pdf
True or False_____ Cells Composed of chemicals and structures, ma.pdf
meerobertsonheyde608
 
The picture above shows the life cycle of a moss. Mark all true stat.pdf
The picture above shows the life cycle of a moss. Mark all true stat.pdfThe picture above shows the life cycle of a moss. Mark all true stat.pdf
The picture above shows the life cycle of a moss. Mark all true stat.pdf
meerobertsonheyde608
 
The conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdf
The conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdfThe conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdf
The conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdf
meerobertsonheyde608
 
Suppose S is a set of n + 1 integers. Prove that there exist distinct.pdf
Suppose S is a set of n + 1 integers. Prove that there exist distinct.pdfSuppose S is a set of n + 1 integers. Prove that there exist distinct.pdf
Suppose S is a set of n + 1 integers. Prove that there exist distinct.pdf
meerobertsonheyde608
 
Structural features of fungi Complete the following paragraph to desc.pdf
Structural features of fungi Complete the following paragraph to desc.pdfStructural features of fungi Complete the following paragraph to desc.pdf
Structural features of fungi Complete the following paragraph to desc.pdf
meerobertsonheyde608
 
State some successful predictions from Einsteins theory of special.pdf
State some successful predictions from Einsteins theory of special.pdfState some successful predictions from Einsteins theory of special.pdf
State some successful predictions from Einsteins theory of special.pdf
meerobertsonheyde608
 
QUESTION 7 Forward and futures markets provide insurance or hedging a.pdf
QUESTION 7 Forward and futures markets provide insurance or hedging a.pdfQUESTION 7 Forward and futures markets provide insurance or hedging a.pdf
QUESTION 7 Forward and futures markets provide insurance or hedging a.pdf
meerobertsonheyde608
 
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdfProblem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
meerobertsonheyde608
 

More from meerobertsonheyde608 (20)

Discuss the seven factors that analysts consider where selecting a f.pdf
Discuss the seven factors that analysts consider where selecting a f.pdfDiscuss the seven factors that analysts consider where selecting a f.pdf
Discuss the seven factors that analysts consider where selecting a f.pdf
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
 
Conduct some basic research on the recessive disorder Albinism.Des.pdf
Conduct some basic research on the recessive disorder Albinism.Des.pdfConduct some basic research on the recessive disorder Albinism.Des.pdf
Conduct some basic research on the recessive disorder Albinism.Des.pdf
 
calculate the next annual dividend payment for stock currently selli.pdf
calculate the next annual dividend payment for stock currently selli.pdfcalculate the next annual dividend payment for stock currently selli.pdf
calculate the next annual dividend payment for stock currently selli.pdf
 
Bookmark On the Isle of Man off the coast of Ireland, a curious cat .pdf
Bookmark On the Isle of Man off the coast of Ireland, a curious cat .pdfBookmark On the Isle of Man off the coast of Ireland, a curious cat .pdf
Bookmark On the Isle of Man off the coast of Ireland, a curious cat .pdf
 
Answer the questions below based on the database model found on the n.pdf
Answer the questions below based on the database model found on the n.pdfAnswer the questions below based on the database model found on the n.pdf
Answer the questions below based on the database model found on the n.pdf
 
You are reviewing basic network protocols with a new tech in your co.pdf
You are reviewing basic network protocols with a new tech in your co.pdfYou are reviewing basic network protocols with a new tech in your co.pdf
You are reviewing basic network protocols with a new tech in your co.pdf
 
Why might a gene have more than 2 different allelesa.     DNA seq.pdf
Why might a gene have more than 2 different allelesa.     DNA seq.pdfWhy might a gene have more than 2 different allelesa.     DNA seq.pdf
Why might a gene have more than 2 different allelesa.     DNA seq.pdf
 
Which of the following are true statementsI. sin2+cos2=1II. sec.pdf
Which of the following are true statementsI. sin2+cos2=1II. sec.pdfWhich of the following are true statementsI. sin2+cos2=1II. sec.pdf
Which of the following are true statementsI. sin2+cos2=1II. sec.pdf
 
What scientific mechanism for evolution did Charles Darwin and Alfred.pdf
What scientific mechanism for evolution did Charles Darwin and Alfred.pdfWhat scientific mechanism for evolution did Charles Darwin and Alfred.pdf
What scientific mechanism for evolution did Charles Darwin and Alfred.pdf
 
What is the main difference between doing business process analysis .pdf
What is the main difference between doing business process analysis .pdfWhat is the main difference between doing business process analysis .pdf
What is the main difference between doing business process analysis .pdf
 
What are the genetic differences between a processed pseudogene and .pdf
What are the genetic differences between a processed pseudogene and .pdfWhat are the genetic differences between a processed pseudogene and .pdf
What are the genetic differences between a processed pseudogene and .pdf
 
True or False_____ Cells Composed of chemicals and structures, ma.pdf
True or False_____ Cells Composed of chemicals and structures, ma.pdfTrue or False_____ Cells Composed of chemicals and structures, ma.pdf
True or False_____ Cells Composed of chemicals and structures, ma.pdf
 
The picture above shows the life cycle of a moss. Mark all true stat.pdf
The picture above shows the life cycle of a moss. Mark all true stat.pdfThe picture above shows the life cycle of a moss. Mark all true stat.pdf
The picture above shows the life cycle of a moss. Mark all true stat.pdf
 
The conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdf
The conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdfThe conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdf
The conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdf
 
Suppose S is a set of n + 1 integers. Prove that there exist distinct.pdf
Suppose S is a set of n + 1 integers. Prove that there exist distinct.pdfSuppose S is a set of n + 1 integers. Prove that there exist distinct.pdf
Suppose S is a set of n + 1 integers. Prove that there exist distinct.pdf
 
Structural features of fungi Complete the following paragraph to desc.pdf
Structural features of fungi Complete the following paragraph to desc.pdfStructural features of fungi Complete the following paragraph to desc.pdf
Structural features of fungi Complete the following paragraph to desc.pdf
 
State some successful predictions from Einsteins theory of special.pdf
State some successful predictions from Einsteins theory of special.pdfState some successful predictions from Einsteins theory of special.pdf
State some successful predictions from Einsteins theory of special.pdf
 
QUESTION 7 Forward and futures markets provide insurance or hedging a.pdf
QUESTION 7 Forward and futures markets provide insurance or hedging a.pdfQUESTION 7 Forward and futures markets provide insurance or hedging a.pdf
QUESTION 7 Forward and futures markets provide insurance or hedging a.pdf
 
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdfProblem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
 

Recently uploaded

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

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);
  • 3. // 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);
  • 4. 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; c += bodyColW) { fill(68, 230, 170 + (x - c) / bodyColW * 20); rect(c, 0, bodyColW, y - space / 2); rect(c, y + space / 2, bodyColW, 400 - y - space / 2 + 10); // bottom } // pipe end fill(65, 186, 79); stroke(0, 0, 0, 180); rect(x - endW / 2, y - space / 2 - endH, endW, endH, 3); // top rect(x - endW / 2, y + space / 2, endW, endH, 3); // bottom
  • 5. noStroke(); // end stripes colorMode(HSB); var endColW = 5; for(var c = x - endW / 2; c < x + endW / 2; c += endColW) { fill(68, 230, 170 + (x - c) / endColW * 20); rect(c, y - space / 2 - endH, endColW, endH); rect(c, y + space / 2, endColW, endH); // bottom } colorMode(RGB); }; var drawBackground = function() { // clouds fill(244, 245, 235); for(var x = 0; x <= 400; x += 40) { var noiseScale = 0.02; var noiseVal = noise(-x*noiseScale); ellipse(x, groundY, noise(noiseVal) * 120, noiseVal * 220); } // hills/trees fill(98, 209, 102, 240); stroke(66, 128, 42); for(var x = 0; x <= 400; x += 20) { var noiseScale = 0.02; var noiseVal = noise(x*noiseScale); ellipse(x, groundY, noise(noiseVal)*50, noiseVal * 100); } noStroke(); }; var draw = function() {
  • 6. if(inGame) { background(139, 205, 214); drawBackground(); for(var i = 0; i < pipes.length; i++) { drawPipe(pipes[i][0], pipes[i][1]); } drawGround(); drawBird(); fill(76, 73, 153, 200); stroke(0, 0, 0, 130); rect(18, 358, 200, 40, 10); fill(255, 255, 255); text("Score: " + score, 20, 390); noStroke(); // making the bird fall birdDY += grav; birdY += birdDY; if(birdY < birdR) { birdY = birdR; } if(birdDY < 0 && birdDY > -space / 10) { birdDY += 1; } // move pipes for(var i = 0; i < pipes.length; i++) { pipes[i][0] -= pipeSpeed; } // make new pipe when farthest right one is pipeSpace away from right if(pipes[pipes.length - 1][0] <= width - pipeSpace) { pipes.push([400 + endW, random(pipeMinY, pipeMaxY)]); }
  • 7. // delete offscreen left pipes if(pipes[0][0] < -endW) { pipes.shift(); score++; } // check for collision var collision = false; var birdTop = birdY - birdR; var birdBottom = birdY + birdR; var birdLeft = birdX - birdR; var birdRight = birdX + birdR; if(!gotFirstPoint && birdX > pipes[0][0]) { gotFirstPoint = true; score++; } if(birdBottom >= groundY) { collision = true; } else { for(var i = 0; i < pipes.length; i++) { // if not too for left or right var tooLeft = birdRight < pipes[i][0]-endW/2; var tooRight = birdLeft > pipes[i][0]+endW/2; if(!tooLeft && !tooRight) { var tooHigh = birdBottom < pipes[i][1] + space/2; var tooLow = birdTop > pipes[i][1] - space/2; if(!tooHigh || !tooLow) { // using end pipe left/rights this means collision collision = true; break; }
  • 8. } else { //inColX = false; } } } if(collision) { inGame = false; inGameOver = true; } } else if(inStart) { background(139, 205, 214); drawBackground(); drawGround(); fill(255, 255, 255, 127); stroke(0, 0, 0, 127); rect(65, 62, 187, 50, 10); noStroke(); textFont(loadFont("Tahoma", 36), 36); fill(68, 143, 62); text("Flappy Bird", 70, 100); stroke(0, 0, 0); if(mouseX >= 70 && mouseX <= 70 + 100 && mouseY >= 250 && mouseY <= 250 + 50) { fill(73, 173, 64); if(mouseIsPressed) { inGame = true; inStart = false; } } rect(70, 250, 100, 50, 5); fill(0, 0, 0); text("Start", 80, 290);
  • 9. noStroke(); drawBird(); } else if(inGameOver) { background(139, 205, 214); drawBackground(); for(var i = 0; i < pipes.length; i++) { drawPipe(pipes[i][0], pipes[i][1]); } drawGround(); drawBird(); fill(255, 255, 255, 127); stroke(0, 0, 0, 127); rect(80, 110, 280, 150, 15); noStroke(); fill(0, 0, 0); textFont(loadFont("Tahoma", 36), 36); text("Game Over Try again!", 100, 150); text("Final Score: " + score, 85, 250); if(birdY + birdR < groundY) { birdDY++; birdY += birdDY; } else if(birdY + birdR > groundY) { birdY = groundY - birdR*0.8; } } }; var lastMousePress = millis(); var mousePressed = function() { lastMousePress = millis(); if(inGame) {