From 7dc8f20b80c87fe39ac887d8a2d34ef6cbdbfbbf Mon Sep 17 00:00:00 2001 From: roguecomp <roguecomp001@gmail.com> Date: Fri, 10 Sep 2021 11:15:01 +1000 Subject: [PATCH] Added Pipe and bird logic --- src/ShadowFlap.java | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/ShadowFlap.java b/src/ShadowFlap.java index a0b660e..3ce420b 100644 --- a/src/ShadowFlap.java +++ b/src/ShadowFlap.java @@ -8,8 +8,19 @@ import bagel.*; * @student_id: 1180554 */ public class ShadowFlap extends AbstractGame { + private Image Background; + private Bird bird; + private Pipe pipe; + private static String gameState = "mainMenu"; + private final String startString = "PRESS SPACE TO START"; + private final String outOfBounds = "Out Of Bounds"; + private final Font font = new Font("res/slkscr.ttf", 48); public ShadowFlap() { + super(1024, 768, "Flappy Bird"); + this.Background = new Image("res/background.png"); + bird = new Bird(); + pipe = new Pipe(); } /** @@ -26,7 +37,42 @@ public class ShadowFlap extends AbstractGame { */ @Override public void update(Input input) { + Background.draw(Window.getWidth() / 2.0, Window.getHeight() / 2.0); + if(this.gameState == "started") { + /* game has started */ + bird.velocity -= bird.acceleration; + bird.velocity = Math.max(bird.velocity, bird.terminalVelocity); /* set fall velocity limit */ + bird.y -= bird.velocity; + + if(input.wasPressed(Keys.SPACE)) { bird.velocity = 6; } + if(bird.y > Window.getHeight() || bird.y < 0) { + gameState = "outOfBounds"; + }; + + bird.Render(); + pipe.Render(); + } + 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); + } + else { + /* loading screen */ + if (input.wasPressed(Keys.SPACE)) { + gameState = "started"; + } + + /* draw font exactly in the middle of the screen */ + font.drawString(startString, (Window.getWidth() / 2.0) - (font.getWidth(startString) / 2.0), + Window.getHeight() / 2.0); + } + + if (input.wasPressed(Keys.ESCAPE)) { + Window.close(); + } } } -- GitLab