diff --git a/include/Game.h b/include/Game.h index ec5230d..95ac7ad 100644 --- a/include/Game.h +++ b/include/Game.h @@ -27,6 +27,7 @@ struct Cpu sf::Vector2f pos{}; sf::Vector2f prevPos{}; float velocity{}; + float speed{5}; unsigned int score{}; }; @@ -103,7 +104,7 @@ private: double accumulator{}; - double playTime{}; - + TimeDuration playTime{}; + std::chrono::seconds totalSeconds{}; }; \ No newline at end of file diff --git a/src/Game.cpp b/src/Game.cpp index dfcb3ae..e222eb6 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -95,7 +95,8 @@ void Game::run() TimeDuration duration = currentFrameStartPoint - lastFrameStartPoint; const double frameTime = duration.count(); - playTime += frameTime; + playTime += duration; + totalSeconds = std::chrono::duration_cast(playTime).count(); lastFrameStartPoint = currentFrameStartPoint; @@ -228,14 +229,19 @@ void Game::render() void Game::updateCpu() { + if (totalSeconds > 0 and totalSeconds % 10 == 0) + { + cpu.speed += .5f; + } + if (ball.pos.y > cpu.pos.y) { - cpu.velocity = 5; + cpu.velocity = cpu.speed; } if (ball.pos.y < cpu.pos.y) { - cpu.velocity = -5; + cpu.velocity = cpu.speed * -1.f; } if (ball.pos.y == cpu.pos.y) @@ -262,9 +268,8 @@ void Game::collision() {} void Game::updateTexts() { - const int totalSeconds = static_cast(playTime); - const int minutes = totalSeconds / 60; - const int seconds = totalSeconds % 60; + const auto minutes = totalSeconds / 60; + const auto seconds = totalSeconds % 60; const std::string secondsStr = (seconds < 10) ? "0" + std::to_string(seconds) : std::to_string(seconds); const std::string minutesStr = (minutes < 10) ? "0" + std::to_string(minutes) : std::to_string(minutes);