mirror of
https://github.com/dylanbenzi/pacmen-sfml.git
synced 2026-11-27 08:26:59 +00:00
add initial game delay during start
This commit is contained in:
+13
-2
@@ -1,4 +1,5 @@
|
|||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
|
#include <SFML/System/Time.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
@@ -109,6 +110,10 @@ void Game::run() {
|
|||||||
|
|
||||||
int pelletSoundCount = 0;
|
int pelletSoundCount = 0;
|
||||||
|
|
||||||
|
sf::Clock clock;
|
||||||
|
|
||||||
|
sf::Time initialGameplayPause;
|
||||||
|
|
||||||
while (window.isOpen())
|
while (window.isOpen())
|
||||||
{
|
{
|
||||||
while (const std::optional event = window.pollEvent())
|
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());
|
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)) {
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W) || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up)) {
|
||||||
pacman.queueDirection(MovementDir::UP);
|
pacman.queueDirection(MovementDir::UP);
|
||||||
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A) || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left)) {
|
} 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);
|
map.eatPellet(currentPacmanTile.x, currentPacmanTile.y);
|
||||||
|
|
||||||
if (pelletSoundCount % 2) {
|
if (pelletSoundCount % 2) {
|
||||||
pellet0.play();
|
|
||||||
} else {
|
|
||||||
pellet1.play();
|
pellet1.play();
|
||||||
|
} else {
|
||||||
|
pellet0.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
pelletSoundCount++;
|
pelletSoundCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
window.clear();
|
window.clear();
|
||||||
window.draw(map);
|
window.draw(map);
|
||||||
window.draw(pacman);
|
window.draw(pacman);
|
||||||
|
|||||||
Reference in New Issue
Block a user