From b57bd9381e991e31408c1d205fd5c35dfdea3d65 Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 19 Jan 2024 19:10:03 +0100 Subject: [PATCH] speed increase for every bump --- Vec2d/Vec2d.h | 12 +++++++++--- VisibleObjects/Ball.h | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Vec2d/Vec2d.h b/Vec2d/Vec2d.h index e337beb..8d2dc17 100644 --- a/Vec2d/Vec2d.h +++ b/Vec2d/Vec2d.h @@ -18,16 +18,16 @@ inline double_t toRadians(double_t degrees) { class Vec2d { private: std::default_random_engine random; - const float_t hypotenuse; + float_t hypotenuse; double_t x, y; + const float_t bumpSpeedIncrease = 1.05; public: Vec2d(float_t hypotenuse) : hypotenuse(hypotenuse) { std::random_device rd; random = std::default_random_engine(rd()); int sign = random() % 2 == 0 ? -1 : 1; - //double_t angle = toRadians(random() % 6000 / 100 - 30); - double_t angle = 15; + double_t angle = toRadians(random() % 6000 / 100 - 30); x = cos(angle) * sign * hypotenuse; y = sin(angle) * sign * hypotenuse; } @@ -38,6 +38,11 @@ public: } void bump(BumpType bumpType, PaddleDirection paddleDirection) { + // Make everything a bit faster so it's not boring + hypotenuse *= bumpSpeedIncrease; + x *= bumpSpeedIncrease; + y *= bumpSpeedIncrease; + switch (bumpType) { case BumpType::BOTH: x = -x; @@ -58,6 +63,7 @@ public: y = sin(angle) * hypotenuse; } } + } }; \ No newline at end of file diff --git a/VisibleObjects/Ball.h b/VisibleObjects/Ball.h index ffac56e..bcc52a2 100644 --- a/VisibleObjects/Ball.h +++ b/VisibleObjects/Ball.h @@ -29,7 +29,7 @@ public: this->rightPaddle = rightPaddle; this->x = screen->x / 2; this->y = screen->y / 2; - vec2d = new Vec2d(4); + vec2d = new Vec2d(6); } void resetPosition() { @@ -37,7 +37,7 @@ public: this->y = screen->y / 2; delete vec2d; - vec2d = new Vec2d(4); + vec2d = new Vec2d(6); } void draw(SDL_Renderer *renderer) const {