add initial game delay during start

This commit is contained in:
2025-11-10 17:27:45 -05:00
parent 294781b449
commit cb3edad6da
+13 -2
View File
@@ -1,4 +1,5 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/System/Vector2.hpp>
#include <iostream>
#include <SFML/Audio.hpp>
@@ -109,6 +110,10 @@ void Game::run() {
int pelletSoundCount = 0;
sf::Clock clock;
sf::Time initialGameplayPause;
while (window.isOpen())
{
while (const std::optional event = window.pollEvent())
@@ -119,8 +124,12 @@ void Game::run() {
}
}
sf::Time elapsedTime = clock.restart();
initialGameplayPause += elapsedTime;
sf::Vector2i currentPacmanTile = map.getTileCoords(pacman.getPosition());
if (initialGameplayPause > sf::seconds(4.5f)) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W) || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up)) {
pacman.queueDirection(MovementDir::UP);
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A) || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left)) {
@@ -184,14 +193,16 @@ void Game::run() {
map.eatPellet(currentPacmanTile.x, currentPacmanTile.y);
if (pelletSoundCount % 2) {
pellet0.play();
} else {
pellet1.play();
} else {
pellet0.play();
}
pelletSoundCount++;
}
}
window.clear();
window.draw(map);
window.draw(pacman);