Skip to content
Snippets Groups Projects
Select Git revision
  • 864ddd930ad72d84ba335cb0f317ad5d6d5fbd74
  • master default protected
2 results

Pipe.java

Blame
  • Pipe.java 1.41 KiB
    import bagel.DrawOptions;
    import bagel.Image;
    import bagel.Window;
    import bagel.util.Point;
    import bagel.util.Rectangle;
    
    public class Pipe {
        private final double velocity = -5;
        private double pos = Window.getWidth(); /* x-coord at spawn */
        private final int pixelGap = 168;
        public Point centrePipe1, centrePipe2;
    
        /* the higher this value the higher the pipe gap spawns, vice versa */
        private final int initialY = 50; /* y-value of pipe at spawn */
    
        private Image pipeImage1 = new Image("res/pipe.png");
        private Image pipeImage2 = new Image("res/pipe.png");
    
        private Rectangle rectPipe1, rectPipe2;
    
        public void Pipe() {
    
        }
    
        public void Render(Rectangle bird) {
            /* upside down pipe */
            this.pipeImage1.draw(this.pos, -this.initialY);
            centrePipe1 = new Point(this.pos, -this.initialY);
            rectPipe1 = this.pipeImage1.getBoundingBoxAt(centrePipe1);
    
            /* straight up pipe */
            DrawOptions options = new DrawOptions();
            this.pipeImage2.draw(this.pos, Window.getHeight() -this.initialY +this.pixelGap,
                    options.setRotation(Math.PI));
            centrePipe2 = new Point(this.pos, Window.getHeight() -this.initialY +this.pixelGap);
            rectPipe2 = this.pipeImage2.getBoundingBoxAt(centrePipe2);
    
            if(rectPipe2.intersects(bird)) {
                System.out.println("COLLISION!\n");
            }
    
            this.pos += this.velocity;
        }
    }