Skip to content
Snippets Groups Projects
Select Git revision
  • 07b6335c60fad186498c72cd9ff341ba46388210
  • master default protected
2 results

Fuzzer.java

Blame
  • Forked from Toby Murray / swen90006-a2-2020
    Source project has a limited visibility.
    ShadowFlap.java 2.50 KiB
    import bagel.*;
    import bagel.util.Point;
    
    /**
     * Skeleton Code for SWEN20003 Project 1, Semester 2, 2021
     *
     * Please filling your name below
     * @author: Vishnudutt Kappagantula
     * @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();
        }
    
        /**
         * The entry point for the program.
         */
        public static void main(String[] args) {
            ShadowFlap game = new ShadowFlap();
            game.run();
        }
    
        /**
         * Performs a state update.
         * allows the game to exit when the escape key is pressed.
         */
        @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();
                Point birdPos = new Point(bird.x, bird.y);
                pipe.Render(bird.birdWingDown.getBoundingBoxAt(birdPos));
            }
            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();
            }
        }
    
    }