Authors

Flappy Fairy game

Advisors & Mentors

No advisors yet

Abstract

In the game “Flappy Fairy” the player control a fairy, attempting to fly between columns of brown pipes without hitting them.

PImage bg; //bg=background, here we declare. PImage fairy; //declare til fairy PImage topPipe; PImage bottomPipe; int pipeX[]; //declare two arrays int pipeY[]; int bgx; //variable int bgy; float fairyX; float fairyY; float g; //gravity float vFairyY; int gameState = -1; //to check the game, reason why we choose int insted of boolean is that we might have more than 2 state. int score; int highestScore; //RUN ONE TIME void setup() { size(700,550); bg = loadImage("bg.png"); fairy = loadImage("fairy.png"); g = 0.5; //gravity variable = speed of downward acceleration bottomPipe = loadImage("bottom.png"); topPipe = loadImage("Top.png"); pipeX = new int[4]; //[0,0,0,0] = lenght 4 but 0,1,2,3 which will be the lenght //making a new array, and tell how long it has to be pipeY = new int[pipeX.length]; //here insted of write 4 we just type pipeX.length. //POPULATE THE ARRAY WITH VALUES for(int i = 0; i highestScore/45) { highestScore = score; } score = 0; fill(0); text ("High Score: " + highestScore/45, width - 220, 80); // pipeX = new int[4]; pipeY = new int[pipeX.length]; //here insted of write 4 we just type pipeX.length. //POPULATE THE ARRAY WITH VALUES for(int i = 0; i < pipeX.length; i++) // { pipeX[i] = width + 200*i; //width help us get the pipes off the screen. pipeY[i] = (int)random(-270, 0); //random spittes out af flow, which is a decimal number. //-250 distance space } text("Press space to retry...", 40, 200); if(keyPressed) { fairyY = height/2; gameState = 0; //Thats what start the game } } } void score() { fill(255, 0, 0); textSize(25); text ("Score: " + score/45, width - 170, 40); //score divideret med 45, så vi kun får et point per gap. } void startScreen() { image(bg, 0, 0); textSize(40); text("Welcome to Flappy Fairy", 40, 100); text("Press space to begin ...", 40, 200); if(keyPressed) { fairyY = height/2; gameState = 0; //Thats what start the game } }
void keyPressed() //this function you choose space to flappy the fairy so it fly up { vFairyY = -10; //The rate of fairy which fly up. } void fairy() { image(fairy, 250, fairyY, 70, 70); //250 = x som er fast, yFairy er en variable som ikke er fast. fairyY = fairyY + vFairyY; vFairyY = vFairyY + g; if(fairyY > height || fairyY < 0) //fairy skal ikke off the screen { //text("OH NO! Fairy dead", 350, 150); } } void setBg() { image(bg, bgx, bgy); image(bg, bgx + bg.width, bgy); //using the width of bg, //so when it gets to the end of the image, //there will be another image behind it. bgx = bgx -2; //moving the background = animation. Change -2 to move faster bg. if (bgx < -bg.width) //bgx is less than negative bg.width, //so when it gets to the part when its negative-width //then we will reset. bgx = 0; //Here is the reset = 0. } void setPipe() { for (int i = 0; i < pipeX.length; i++) { image(topPipe, pipeX[i], pipeY[i]); //putting the pipes in the game image(bottomPipe, pipeX[i], pipeY[i] + 500); //pipeY = distance between pipes //distance mellem pipes pipeX[i]-= 2; // making the pipes move to the left. if (pipeX[i] pipeX[i] && 250 pipeY[i] + 250 && fairyY pipeX[i] && 250 < pipeX[i] + 92 && fairyY pipeX[i] && 250 pipeY[i] + 500 - 70) { gameState = 1; } } }

Related