From bb788bba590f5ffe17533afb1057e5efebfda772 Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Tue, 11 Nov 2025 19:55:38 -0500 Subject: [PATCH] add energizer pellet logic --- assets/game/pellets.txt | 2 +- src/Game.cpp | 16 +++++++++++++++- src/MazeMap.cpp | 10 ++++++++++ src/MazeMap.h | 8 ++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/assets/game/pellets.txt b/assets/game/pellets.txt index 2f18415..4fe5ec6 100644 --- a/assets/game/pellets.txt +++ b/assets/game/pellets.txt @@ -21,7 +21,7 @@ 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 -0 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 +0 2 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 2 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 0 diff --git a/src/Game.cpp b/src/Game.cpp index b6be55c..08b1bb2 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -148,6 +148,8 @@ void Game::run() { sf::Sound pellet0(*resources.getSound("eat_dot_0")); sf::Sound pellet1(*resources.getSound("eat_dot_1")); + sf::Sound fright(*resources.getSound("fright")); + int pelletSoundCount = 0; sf::Clock clock; @@ -262,7 +264,19 @@ void Game::run() { if (map.hasPellet(currentPacmanTile.x, currentPacmanTile.y)) { map.eatPellet(currentPacmanTile.x, currentPacmanTile.y); - score += 10; + + switch (map.getPelletType(currentPacmanTile)) { + case PelletType::NONE: + break; + case PelletType::DOT: + score += 10; + break; + case PelletType::ENERGIZER: + score += 50; + fright.play(); + break; + }; + scoreText.setString(std::to_string(score)); if (pelletSoundCount % 2) { diff --git a/src/MazeMap.cpp b/src/MazeMap.cpp index cf60285..7411a87 100644 --- a/src/MazeMap.cpp +++ b/src/MazeMap.cpp @@ -81,6 +81,16 @@ bool MazeMap::hasPellet(int x, int y) const { return !pelletEaten[tileIndex] && pelletMap[tileIndex] > 0; } +PelletType MazeMap::getPelletType(sf::Vector2i tilePos) const { + int tileIndex = tilePos.x + tilePos.y * width; + int pellet = pelletMap[tileIndex]; + + if (pellet == 1) return PelletType::DOT; + if (pellet == 2) return PelletType::ENERGIZER; + + return PelletType::NONE; +} + bool MazeMap::isWall(int x, int y) const { if (!isLegalTile(x, y)) return true; diff --git a/src/MazeMap.h b/src/MazeMap.h index 1559cdf..f1bde54 100644 --- a/src/MazeMap.h +++ b/src/MazeMap.h @@ -8,6 +8,12 @@ #include #include "Entity.h" +enum class PelletType { + NONE, + DOT, + ENERGIZER +}; + class MazeMap : public sf::Drawable, public sf::Transformable { public: MazeMap() : width(28), height(31), tileSize(8), texture(nullptr), baseMazeSprite(std::nullopt) {} @@ -23,6 +29,8 @@ public: bool hasPellet(int x, int y) const; + PelletType getPelletType(sf::Vector2i tilePos) const; + bool isWall(int x, int y) const; int convert2DCoords(int x, int y) const { return x + y * width; }