Gravity + jumping

This commit is contained in:
2020-07-27 20:05:59 +02:00
parent 18f1213985
commit 9195be85d0
2 changed files with 104 additions and 15 deletions
+13 -1
View File
@@ -170,6 +170,8 @@ public:
virtual int collisionPushY() = 0;
virtual int collisionWidth() = 0;
virtual int collisionHeight() = 0;
virtual std::pair<std::pair<double,double>,std::pair<double,double>> getDoubleRect() = 0;
virtual void setPos(double x, double y) = 0;
bool colidesWith(const RenderObject &other) const {
if(!hasCollisions() || !other.hasCollisions()) {
return false;
@@ -333,6 +335,16 @@ public:
x->updateCollision(collisionPushX(), collisionPushY(), collisionWidth(), collisionHeight());
}
}
virtual std::pair<std::pair<double,double>,std::pair<double,double>> getDoubleRect() {
return {{x_,y_}, {w_,h_}};
}
virtual void setPos(double x, double y) {
auto dimensions = renderer->getDimensions();
x_ = x;
y_ = y;
rect.x = x_ * dimensions.first;
rect.y = y_ * dimensions.second;
}
virtual int leftmost() {
return rect.x;
}
@@ -359,7 +371,7 @@ public:
rect.w = w_ * smaller_dimension;
rect.h = h_ * smaller_dimension;
}
private:
protected:
double x_;
double y_;
double w_;