Skip to content
Snippets Groups Projects
Commit 7dc8f20b authored by roguecomp's avatar roguecomp
Browse files

Added Pipe and bird logic

parent 2fc6d91f
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment