Hi der Titel sagt alles mein Problem ist es das meine Kollision unten aber nicht oben funktioniert.
Hier meine Kollisions Klasse:
und hier der Code, wo ich die box erstelle, update und abfrage:
das ganze soll ein Flappy Bird werden ich weiß nicht warum die Kollisions box verbuggt ist da sie unten funktioniert
so habe ich es unten gemacht:
ich lasse mit die boxen rendern und sie werden angezeigt also denke ich das es an der Kollisions abfrage liegt.
Ich hoffe das mir jemand von euch helfen kann dies zu fixen.
Hier meine Kollisions Klasse:
Java:
public class CollisionBox {
private double x, y, width, height;
public CollisionBox(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public boolean hasCollided(double x, double y) {
//Check if the given coordinates are in the area of the collision box
return x > this.x && y > this.y && x < this.width && y < this.height;
}
public void updateCollisionBox(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public boolean checkCollisionWithAnotherCollisionBox(CollisionBox collisionBox){
return collisionBox.getX() > this.getX() && collisionBox.getY() > this.getY() && collisionBox.getWidth() < this.width && collisionBox.getHeight() < this.height;
}
public void renderCollisionBox() {
RenderUtil.drawRect(x, y, width, height, Color.RED.getRGB());
}
/*Setter & Getter*/
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
}
und hier der Code, wo ich die box erstelle, update und abfrage:
Java:
private CollisionBox upper;
this.upper = new CollisionBox(this.x, this.level.getHeight(), this.x + this.width, this.y + this.height + Main.mainInstance.getSpace());
this.upper.updateCollisionBox(this.x, this.level.getHeight(), this.x + this.width, this.y + this.height + Main.mainInstance.getSpace());
this.pipe.getUpper().checkCollisionWithAnotherCollisionBox(this.bird.getCollisionBox())//ist ein boolean in einer if abfrage
das ganze soll ein Flappy Bird werden ich weiß nicht warum die Kollisions box verbuggt ist da sie unten funktioniert
so habe ich es unten gemacht:
Java:
private CollisionBox under;
this.under = new CollisionBox(this.x, this.y, this.x + this.width, this.y + this.height);
this.under.updateCollisionBox(this.x, this.y, this.x + this.width, this.y + this.height);
this.pipe.getUnder().checkCollisionWithAnotherCollisionBox(this.bird.getCollisionBox())//ist ein boolean in einer if abfrage
ich lasse mit die boxen rendern und sie werden angezeigt also denke ich das es an der Kollisions abfrage liegt.
Ich hoffe das mir jemand von euch helfen kann dies zu fixen.