add energizer pellet logic

This commit is contained in:
2025-11-11 19:55:38 -05:00
parent ec323f14c6
commit bb788bba59
4 changed files with 34 additions and 2 deletions
+1 -1
View File
@@ -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 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 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 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 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
+15 -1
View File
@@ -148,6 +148,8 @@ void Game::run() {
sf::Sound pellet0(*resources.getSound("eat_dot_0")); sf::Sound pellet0(*resources.getSound("eat_dot_0"));
sf::Sound pellet1(*resources.getSound("eat_dot_1")); sf::Sound pellet1(*resources.getSound("eat_dot_1"));
sf::Sound fright(*resources.getSound("fright"));
int pelletSoundCount = 0; int pelletSoundCount = 0;
sf::Clock clock; sf::Clock clock;
@@ -262,7 +264,19 @@ void Game::run() {
if (map.hasPellet(currentPacmanTile.x, currentPacmanTile.y)) { if (map.hasPellet(currentPacmanTile.x, currentPacmanTile.y)) {
map.eatPellet(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)); scoreText.setString(std::to_string(score));
if (pelletSoundCount % 2) { if (pelletSoundCount % 2) {
+10
View File
@@ -81,6 +81,16 @@ bool MazeMap::hasPellet(int x, int y) const {
return !pelletEaten[tileIndex] && pelletMap[tileIndex] > 0; 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 { bool MazeMap::isWall(int x, int y) const {
if (!isLegalTile(x, y)) return true; if (!isLegalTile(x, y)) return true;
+8
View File
@@ -8,6 +8,12 @@
#include <filesystem> #include <filesystem>
#include "Entity.h" #include "Entity.h"
enum class PelletType {
NONE,
DOT,
ENERGIZER
};
class MazeMap : public sf::Drawable, public sf::Transformable { class MazeMap : public sf::Drawable, public sf::Transformable {
public: public:
MazeMap() : width(28), height(31), tileSize(8), texture(nullptr), baseMazeSprite(std::nullopt) {} MazeMap() : width(28), height(31), tileSize(8), texture(nullptr), baseMazeSprite(std::nullopt) {}
@@ -23,6 +29,8 @@ public:
bool hasPellet(int x, int y) const; bool hasPellet(int x, int y) const;
PelletType getPelletType(sf::Vector2i tilePos) const;
bool isWall(int x, int y) const; bool isWall(int x, int y) const;
int convert2DCoords(int x, int y) const { return x + y * width; } int convert2DCoords(int x, int y) const { return x + y * width; }