From 048427a6dc7af2bb62fca6ff81de59cdaffa5816 Mon Sep 17 00:00:00 2001 From: roguecomp <roguecomp001@gmail.com> Date: Fri, 10 Sep 2021 18:24:23 +1000 Subject: [PATCH] Implementing win and lose screens --- src/ShadowFlap.java | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/ShadowFlap.java b/src/ShadowFlap.java index 4f03e4c..a53841f 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 */ -- GitLab