mirror of
https://github.com/dylanbenzi/pacmen-sfml.git
synced 2026-11-27 08:26:59 +00:00
add energizer pellet logic
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
#include <filesystem>
|
||||
#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; }
|
||||
|
||||
Reference in New Issue
Block a user