diff --git a/src/ShadowFlap.java b/src/ShadowFlap.java index 4f03e4ca23995ba1aff2d5e31a294e4997ce1721..a53841fbfb49ab1cd8a6fc2605b5d0ab3d8fce12 100644 --- a/src/ShadowFlap.java +++ b/src/ShadowFlap.java @@ -12,9 +12,12 @@ public class ShadowFlap extends AbstractGame { private Image Background; private Bird bird; private Pipe pipe; - private static String gameState = "mainMenu"; + private int score = 0; + private String gameState = "mainMenu", temp = ""; private final String startString = "PRESS SPACE TO START"; - private final String outOfBounds = "Out Of Bounds"; + private final String outOfBounds = "GAME OVER!"; + private final String finalScore = "Final Score: "; + private final String winFont = "CONGRATULATIONS!"; private final Font font = new Font("res/slkscr.ttf", 48); public ShadowFlap() { @@ -53,13 +56,39 @@ public class ShadowFlap extends AbstractGame { bird.Render(); Point birdPos = new Point(bird.x, bird.y); - pipe.Render(bird.birdWingDown.getBoundingBoxAt(birdPos)); + temp = pipe.Render(bird.birdWingDown.getBoundingBoxAt(birdPos)); + if(temp == null) { + temp = ""; + } + else { + gameState = temp; + } + + if(bird.x > pipe.pos) { + this.score = 1; + } + + if(pipe.pos <= 0) { + this.gameState = "win"; + } } else if (gameState == "outOfBounds") { Background.draw(Window.getWidth() / 2.0, Window.getHeight() / 2.0); font.drawString(outOfBounds, (Window.getWidth() / 2.0) - (font.getWidth(outOfBounds) / 2.0), Window.getHeight() / 2.0); + font.drawString(finalScore + String.valueOf(this.score), + (Window.getWidth() / 2.0) - (font.getWidth(finalScore + String.valueOf(this.score)) / 2.0), + (Window.getHeight() / 2.0) + 75); + } + else if (gameState == "win") { + Background.draw(Window.getWidth() / 2.0, Window.getHeight() / 2.0); + font.drawString(winFont, + (Window.getWidth() / 2.0) - (font.getWidth(winFont) / 2.0), + Window.getHeight() / 2.0); + font.drawString(finalScore + String.valueOf(this.score), + (Window.getWidth() / 2.0) - (font.getWidth(finalScore + String.valueOf(this.score)) / 2.0), + (Window.getHeight() / 2.0) + 75); } else { /* loading screen */