better random

main
Benjamin Kraft 2 years ago
parent ef4e89e63c
commit 5caa486a75
  1. 10
      src/Game.cpp
  2. 1
      src/Game.h
  3. 2
      src/Player.cpp
  4. 2
      src/Player.h
  5. 2
      src/Wall.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<double>(low, high);
return dist(gen);
}

@ -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;

@ -50,6 +50,6 @@ void Player::update(float dTime, std::vector<Wall> &walls) {
}
void Player::jump() {
vel += {0, -300};
vel += {0, -jumpPower};
Audio::playSound(1, SOUND_JUMP);
}

@ -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;

@ -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 {

Loading…
Cancel
Save