diff --git a/src/Bird.java b/src/Bird.java index c4d196780cb7073a5089aa2f61bb63495015e2b2..15151dfd2317fe46916242a810148a63a179f3ae 100644 --- a/src/Bird.java +++ b/src/Bird.java @@ -2,14 +2,14 @@ import bagel.Image; public class Bird { /* positive means moving up, negative means moving down */ - public double velocity; - private static int frameCounterSinceStart = 0; + public double velocity = 0; + private static int frameCounterSinceStart = 1; public Image birdWingUp = new Image("res/birdWingUp.png"); public Image birdWingDown = new Image("res/birdWingDown.png"); public final double acceleration = 0.4; - public final double terminalVelocity = 10; + public final double terminalVelocity = -10; public final double x = 200; public double y = 350; diff --git a/src/Pipe.java b/src/Pipe.java index 3ebc9f053475ea9e161f76cae929103a24fed314..0abe366c921b44919086ffa27713932de393556a 100644 --- a/src/Pipe.java +++ b/src/Pipe.java @@ -1,27 +1,43 @@ -import bagel.*; +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 pipeImage = new Image("res/pipe.png"); + 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() { + public void Render(Rectangle bird) { /* upside down pipe */ - this.pipeImage.draw(this.pos, -this.initialY); + 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.pipeImage.draw(this.pos, Window.getHeight() -this.initialY +this.pixelGap, + 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; } diff --git a/src/ShadowFlap.java b/src/ShadowFlap.java index 3ce420b6eb031acfca40b3916ac10b2cffc4ff2b..4f03e4ca23995ba1aff2d5e31a294e4997ce1721 100644 --- a/src/ShadowFlap.java +++ b/src/ShadowFlap.java @@ -1,4 +1,5 @@ import bagel.*; +import bagel.util.Point; /** * Skeleton Code for SWEN20003 Project 1, Semester 2, 2021 @@ -51,7 +52,8 @@ public class ShadowFlap extends AbstractGame { }; bird.Render(); - pipe.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);