diff --git a/src/Game.cpp b/src/Game.cpp index 99a765c..a5d8a6c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -24,8 +24,7 @@ void Game::update(float dTime) { } void Game::tryCreateWall() { - int val = rand() % 1000; - if (val > 990){ + if (Game::Random(0, 1000) > 990){ walls.emplace_back(); } } @@ -47,3 +46,10 @@ Game::Game() { GameQueue * Game::eventQueue = new GameQueue; Game * Game::instance = nullptr; +double Game::Random(double low, double high) { + std::random_device device; + std::mt19937 gen(device()); + auto dist = std::uniform_real_distribution(low, high); + return dist(gen); +} + diff --git a/src/Game.h b/src/Game.h index 5256741..205adc8 100644 --- a/src/Game.h +++ b/src/Game.h @@ -18,6 +18,7 @@ class Game { void tryCreateWall(); void removeWalls(); public: + static double Random(double low, double high); Window * window = nullptr; // seconds float eTime = 0; diff --git a/src/Player.cpp b/src/Player.cpp index 5b454bd..d050620 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -50,6 +50,6 @@ void Player::update(float dTime, std::vector &walls) { } void Player::jump() { - vel += {0, -300}; + vel += {0, -jumpPower}; Audio::playSound(1, SOUND_JUMP); } diff --git a/src/Player.h b/src/Player.h index 8022301..1510da9 100644 --- a/src/Player.h +++ b/src/Player.h @@ -10,6 +10,8 @@ class Player : public InputListener { QVector2D vel {}; QVector2D acc {0, 9.81 * 30}; + static constexpr float jumpPower = 400; + void jump(); public: void draw(QPainter &painter) const; diff --git a/src/Wall.cpp b/src/Wall.cpp index 3cd32b9..270331d 100644 --- a/src/Wall.cpp +++ b/src/Wall.cpp @@ -18,7 +18,7 @@ void Wall::update(float dTime) { Wall::Wall() { pos = {WIDTH, GROUND_Y}; - size = {50, 50}; + size = QSize(int(Game::Random(30, 60)), int(Game::Random(30, 150))); } bool Wall::isLost() const {