SlideShare a Scribd company logo
1 of 10
Download to read offline
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 #4Ismar 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.pdffonecomp
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfcontact32
 
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 .pdfarmcomputers
 
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.pdfcalderoncasto9163
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노Chiwon Song
 
A simple snake game project
A simple snake game projectA simple snake game project
A simple snake game projectAmit 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 swiftChiwon Song
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascriptReece Carlson
 
Project hotel on hotel management fo
Project  hotel on hotel management foProject  hotel on hotel management fo
Project hotel on hotel management foSunny 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 .docxursabrooks36447
 
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.pdffeelinggifts
 
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)

Myraytracer
MyraytracerMyraytracer
Myraytracer
 
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
 

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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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 .pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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 .pdfmeerobertsonheyde608
 
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 .pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 

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

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.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) {