add pacman eating pellets

This commit is contained in:
2025-11-10 17:10:05 -05:00
parent bdeb9cb5f7
commit d7fd4ec14a
+7
View File
@@ -1,4 +1,5 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Vector2.hpp>
#include <iostream>
#include <SFML/Audio.hpp>
@@ -113,6 +114,8 @@ void Game::run() {
}
}
sf::Vector2i currentPacmanTile = map.getTileCoords(pacman.getPosition());
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)) {
@@ -172,6 +175,10 @@ void Game::run() {
pacman.update();
if (map.hasPellet(currentPacmanTile.x, currentPacmanTile.y)) {
map.eatPellet(currentPacmanTile.x, currentPacmanTile.y);
}
window.clear();
window.draw(map);
window.draw(pacman);