From 2d80604362b9c84e56eb05abeb26d8542cec38f0 Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Tue, 11 Nov 2025 23:45:05 -0500 Subject: [PATCH 1/6] modify methods to only use vectors --- src/Game.cpp | 6 ++--- src/MazeMap.cpp | 60 ++++++++++++++++++++++++++++++++++++++----------- src/MazeMap.h | 18 ++++++++++----- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index ee4ed88..b9135e7 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -252,7 +252,7 @@ void Game::run() { break; } - if (!map.isWall(targetTile.x, targetTile.y)) { + if (!map.isWall(targetTile)) { map.snapEntityToGrid(pacman); switch (queued) { @@ -328,8 +328,8 @@ void Game::run() { map.handleTunnelWrapping(pacman); - if (map.hasPellet(currentPacmanTile.x, currentPacmanTile.y)) { - map.eatPellet(currentPacmanTile.x, currentPacmanTile.y); + if (map.hasPellet(currentPacmanTile)) { + map.eatPellet(currentPacmanTile); switch (map.getPelletType(currentPacmanTile)) { case PelletType::NONE: diff --git a/src/MazeMap.cpp b/src/MazeMap.cpp index 7411a87..39f7158 100644 --- a/src/MazeMap.cpp +++ b/src/MazeMap.cpp @@ -60,10 +60,10 @@ bool MazeMap::loadMaze(const std::vector& collisionData, return true; } -void MazeMap::eatPellet(int x, int y) { - if (!isLegalTile(x, y)) return; +void MazeMap::eatPellet(sf::Vector2i tilePos) { + if (!isLegalTile(tilePos)) return; - int tileIndex = x + y * width; + int tileIndex = convert2DCoords(tilePos); pelletEaten[tileIndex] = true; @@ -73,14 +73,35 @@ void MazeMap::eatPellet(int x, int y) { } } -bool MazeMap::hasPellet(int x, int y) const { - if (!isLegalTile(x, y)) return false; +//void MazeMap::eatPellet(int x, int y) { +// if (!isLegalTile(x, y)) return; +// +// int tileIndex = x + y * width; +// +// pelletEaten[tileIndex] = true; +// +// sf::Vertex* triangles = &pelletVertices[tileIndex * 6]; +// for (int i = 0; i < 6; ++i) { +// triangles[i].color = sf::Color::Transparent; +// } +//} - int tileIndex = x + y * width; +bool MazeMap::hasPellet(sf::Vector2i tilePos) const { + if (!isLegalTile(tilePos)) return false; + + int tileIndex = convert2DCoords(tilePos); return !pelletEaten[tileIndex] && pelletMap[tileIndex] > 0; } +//bool MazeMap::hasPellet(int x, int y) const { +// if (!isLegalTile(x, y)) return false; +// +// int tileIndex = x + y * width; +// +// return !pelletEaten[tileIndex] && pelletMap[tileIndex] > 0; +//} + PelletType MazeMap::getPelletType(sf::Vector2i tilePos) const { int tileIndex = tilePos.x + tilePos.y * width; int pellet = pelletMap[tileIndex]; @@ -91,18 +112,31 @@ PelletType MazeMap::getPelletType(sf::Vector2i tilePos) const { return PelletType::NONE; } -bool MazeMap::isWall(int x, int y) const { - if (!isLegalTile(x, y)) return true; +bool MazeMap::isWall(sf::Vector2i tilePos) const { + if (!isLegalTile(tilePos)) return true; + + int tileIndex = convert2DCoords(tilePos); - int tileIndex = x + y * width; return collisionMap[tileIndex] == 1; } -bool MazeMap::isLegalTile(int x, int y) const { - return x >= 0 && x < static_cast(width) && - y >= 0 && y < static_cast(height); +//bool MazeMap::isWall(int x, int y) const { +// if (!isLegalTile(x, y)) return true; +// +// int tileIndex = x + y * width; +// return collisionMap[tileIndex] == 1; +//} + +bool MazeMap::isLegalTile(sf::Vector2i tilePos) const { + return tilePos.x >= 0 && tilePos.x < static_cast(width) && + tilePos.y >= 0 && tilePos.y < static_cast(height); } +//bool MazeMap::isLegalTile(int x, int y) const { +// return x >= 0 && x < static_cast(width) && +// y >= 0 && y < static_cast(height); +//} + void MazeMap::draw(sf::RenderTarget& target, sf::RenderStates states) const { if (!texture || !baseMazeSprite.has_value()) return; @@ -196,7 +230,7 @@ bool MazeMap::entityCanMove(Entity& entity, MovementDir dir) { return true; }; - return !isWall(targetTile.x, targetTile.y); + return !isWall(targetTile); }; void MazeMap::handleTunnelWrapping(Entity& entity) { diff --git a/src/MazeMap.h b/src/MazeMap.h index f1bde54..90ad9cb 100644 --- a/src/MazeMap.h +++ b/src/MazeMap.h @@ -25,16 +25,22 @@ public: sf::Vector2u baseMazeTexturePos, sf::Vector2u pelletMazeTexturePos); - void eatPellet(int x, int y); + //void eatPellet(int x, int y); + void eatPellet(sf::Vector2i tilePos); - bool hasPellet(int x, int y) const; + //bool hasPellet(int x, int y) const; + bool hasPellet(sf::Vector2i tilePos) const; PelletType getPelletType(sf::Vector2i tilePos) const; - bool isWall(int x, int y) const; + //bool isWall(int x, int y) const; + bool isWall(sf::Vector2i tilePos) const; - int convert2DCoords(int x, int y) const { return x + y * width; } - bool isLegalTile(int x, int y) const; + //int convert2DCoords(int x, int y) const { return x + y * width; } + int convert2DCoords(sf::Vector2i tilePos) const { return tilePos.x + tilePos.y * width; } + + //bool isLegalTile(int x, int y) const; + bool isLegalTile(sf::Vector2i tilePos) const; bool entityCanMove(Entity& entity, MovementDir dir); @@ -48,6 +54,8 @@ public: void handleTunnelWrapping(Entity& entity); + bool isIntersectionTile(sf::Vector2i tileCoords) const; + unsigned int getWidth() const { return width; } unsigned int getHeight() const { return height; } unsigned int getTileSize() const { return tileSize; } From d02dfbe7b405d29b85081781d6ffbb3fbe81a5ab Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Thu, 13 Nov 2025 14:09:00 -0500 Subject: [PATCH 2/6] add intersection tile logic to map --- src/MazeMap.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/MazeMap.cpp b/src/MazeMap.cpp index 39f7158..544bfe7 100644 --- a/src/MazeMap.cpp +++ b/src/MazeMap.cpp @@ -137,6 +137,23 @@ bool MazeMap::isLegalTile(sf::Vector2i tilePos) const { // y >= 0 && y < static_cast(height); //} +bool MazeMap::isIntersectionTile(sf::Vector2i tilePos) const { + // true if more than two surrounding tiles are not walls + + int surroundingMovementTiles = 0; + + // +x (right) + if (!isWall({tilePos.x + 1, tilePos.y})) surroundingMovementTiles++; + // -x (left) + if (!isWall({tilePos.x - 1, tilePos.y})) surroundingMovementTiles++; + // +y (down) + if (!isWall({tilePos.x, tilePos.y + 1})) surroundingMovementTiles++; + // -y (up) + if (!isWall({tilePos.x, tilePos.y - 1})) surroundingMovementTiles++; + + return surroundingMovementTiles > 2; +}; + void MazeMap::draw(sf::RenderTarget& target, sf::RenderStates states) const { if (!texture || !baseMazeSprite.has_value()) return; From 0bbe00fe019465abfd7196f1da66c0c0de58b67b Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Thu, 13 Nov 2025 14:35:12 -0500 Subject: [PATCH 3/6] add ghost specific classes and temporarily remove sound --- CMakeLists.txt | 4 ++-- src/Blinky.cpp | 5 +++++ src/Blinky.h | 11 +++++++++++ src/Clyde.cpp | 5 +++++ src/Clyde.h | 11 +++++++++++ src/Game.cpp | 20 ++++++++++++-------- src/Ghost.h | 6 +++++- src/Inky.cpp | 5 +++++ src/Inky.h | 11 +++++++++++ src/Pinky.cpp | 5 +++++ src/Pinky.h | 11 +++++++++++ 11 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 src/Blinky.cpp create mode 100644 src/Blinky.h create mode 100644 src/Clyde.cpp create mode 100644 src/Clyde.h create mode 100644 src/Inky.cpp create mode 100644 src/Inky.h create mode 100644 src/Pinky.cpp create mode 100644 src/Pinky.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fa88ca..e744090 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ FetchContent_Declare(json FetchContent_MakeAvailable(SFML json) -add_executable(main src/main.cpp src/Entity.cpp src/Game.cpp src/MazeMap.cpp src/ResourceManager.cpp) +add_executable(main src/main.cpp src/Entity.cpp src/Game.cpp src/MazeMap.cpp src/ResourceManager.cpp src/Blinky.cpp src/Pinky.cpp src/Inky.cpp src/Clyde.cpp) target_compile_features(main PRIVATE cxx_std_17) target_link_libraries(main PRIVATE SFML::Graphics SFML::Audio nlohmann_json::nlohmann_json) @@ -28,4 +28,4 @@ add_custom_command(TARGET main POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/assets ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets - COMMENT "Copying assets to build directory") \ No newline at end of file + COMMENT "Copying assets to build directory") diff --git a/src/Blinky.cpp b/src/Blinky.cpp new file mode 100644 index 0000000..d434580 --- /dev/null +++ b/src/Blinky.cpp @@ -0,0 +1,5 @@ +#include "Blinky.h" + +void Blinky::setTargetTile() { + +}; diff --git a/src/Blinky.h b/src/Blinky.h new file mode 100644 index 0000000..a736086 --- /dev/null +++ b/src/Blinky.h @@ -0,0 +1,11 @@ +#ifndef BLINKY_H +#define BLINKY_H + +#include "Ghost.h" + +class Blinky : public Ghost { +public: + void setTargetTile() override; +}; + +#endif diff --git a/src/Clyde.cpp b/src/Clyde.cpp new file mode 100644 index 0000000..1c5c2b0 --- /dev/null +++ b/src/Clyde.cpp @@ -0,0 +1,5 @@ +#include "Clyde.h" + +void Clyde::setTargetTile() { + +}; diff --git a/src/Clyde.h b/src/Clyde.h new file mode 100644 index 0000000..ce54e59 --- /dev/null +++ b/src/Clyde.h @@ -0,0 +1,11 @@ +#ifndef CLYDE_H +#define CLYDE_H + +#include "Ghost.h" + +class Clyde : public Ghost { +public: + void setTargetTile() override; +}; + +#endif diff --git a/src/Game.cpp b/src/Game.cpp index b9135e7..87e9748 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -8,7 +8,11 @@ #include #include "Game.h" +#include "Blinky.h" +#include "Clyde.h" +#include "Inky.h" #include "MazeMap.h" +#include "Pinky.h" #include "ResourceManager.h" #include "Pacman.h" #include "Ghost.h" @@ -91,10 +95,10 @@ void Game::run() { Pacman pacman; - Ghost blinky; - Ghost pinky; - Ghost inky; - Ghost clyde; + Blinky blinky; + Pinky pinky; + Inky inky; + Clyde clyde; pacman.setAnimationTiles(resources.getTexture("all_textures"), {1824, 0}, "right_walking", {60, 60}, 2, 0); pacman.setAnimationTiles(resources.getTexture("all_textures"), {1824, 64}, "left_walking", {60, 60}, 2, 0); @@ -143,7 +147,7 @@ void Game::run() { auto window = sf::RenderWindow(sf::VideoMode(windowRes), windowName); sf::Sound sound(*resources.getSound("start")); - sound.play(); + //sound.play(); sf::Sound pellet0(*resources.getSound("eat_dot_0")); sf::Sound pellet1(*resources.getSound("eat_dot_1")); @@ -339,16 +343,16 @@ void Game::run() { break; case PelletType::ENERGIZER: score += 50; - fright.play(); + //fright.play(); break; }; scoreText.setString(std::to_string(score)); if (pelletSoundCount % 2) { - pellet1.play(); + //pellet1.play(); } else { - pellet0.play(); + //pellet0.play(); } pelletSoundCount++; diff --git a/src/Ghost.h b/src/Ghost.h index ac40815..562eff9 100644 --- a/src/Ghost.h +++ b/src/Ghost.h @@ -2,9 +2,13 @@ #define GHOST_H #include "Entity.h" +#include class Ghost : public Entity { - +public: + virtual void setTargetTile() = 0; +protected: + sf::Vector2i targetTile; }; #endif diff --git a/src/Inky.cpp b/src/Inky.cpp new file mode 100644 index 0000000..37c6055 --- /dev/null +++ b/src/Inky.cpp @@ -0,0 +1,5 @@ +#include "Inky.h" + +void Inky::setTargetTile() { + +}; diff --git a/src/Inky.h b/src/Inky.h new file mode 100644 index 0000000..04e77d3 --- /dev/null +++ b/src/Inky.h @@ -0,0 +1,11 @@ +#ifndef INKY_H +#define INKY_H + +#include "Ghost.h" + +class Inky : public Ghost { +public: + void setTargetTile() override; +}; + +#endif diff --git a/src/Pinky.cpp b/src/Pinky.cpp new file mode 100644 index 0000000..472cea7 --- /dev/null +++ b/src/Pinky.cpp @@ -0,0 +1,5 @@ +#include "Pinky.h" + +void Pinky::setTargetTile() { + +}; diff --git a/src/Pinky.h b/src/Pinky.h new file mode 100644 index 0000000..a4adf20 --- /dev/null +++ b/src/Pinky.h @@ -0,0 +1,11 @@ +#ifndef PINKY_H +#define PINKY_H + +#include "Ghost.h" + +class Pinky : public Ghost { +public: + void setTargetTile() override; +}; + +#endif From 20eb36945b1555b3672a348a47ff87addf5be178 Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Thu, 13 Nov 2025 14:48:35 -0500 Subject: [PATCH 4/6] add ghost specific targeting functions --- src/Blinky.cpp | 2 +- src/Blinky.h | 2 +- src/Clyde.h | 2 +- src/Ghost.h | 1 - src/Inky.h | 2 +- src/Pinky.h | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Blinky.cpp b/src/Blinky.cpp index d434580..92e7ab6 100644 --- a/src/Blinky.cpp +++ b/src/Blinky.cpp @@ -1,5 +1,5 @@ #include "Blinky.h" -void Blinky::setTargetTile() { +void Blinky::setTargetTile(Entity& pacman) { }; diff --git a/src/Blinky.h b/src/Blinky.h index a736086..80b2a98 100644 --- a/src/Blinky.h +++ b/src/Blinky.h @@ -5,7 +5,7 @@ class Blinky : public Ghost { public: - void setTargetTile() override; + void setTargetTile(Entity& pacman); }; #endif diff --git a/src/Clyde.h b/src/Clyde.h index ce54e59..eeffaf9 100644 --- a/src/Clyde.h +++ b/src/Clyde.h @@ -5,7 +5,7 @@ class Clyde : public Ghost { public: - void setTargetTile() override; + void setTargetTile(Entity& pacman); }; #endif diff --git a/src/Ghost.h b/src/Ghost.h index 562eff9..0051e01 100644 --- a/src/Ghost.h +++ b/src/Ghost.h @@ -6,7 +6,6 @@ class Ghost : public Entity { public: - virtual void setTargetTile() = 0; protected: sf::Vector2i targetTile; }; diff --git a/src/Inky.h b/src/Inky.h index 04e77d3..bfb5b22 100644 --- a/src/Inky.h +++ b/src/Inky.h @@ -5,7 +5,7 @@ class Inky : public Ghost { public: - void setTargetTile() override; + void setTargetTile(Entity& pacman, Entity& blinky); }; #endif diff --git a/src/Pinky.h b/src/Pinky.h index a4adf20..9b07d8a 100644 --- a/src/Pinky.h +++ b/src/Pinky.h @@ -5,7 +5,7 @@ class Pinky : public Ghost { public: - void setTargetTile() override; + void setTargetTile(Entity& pacman); }; #endif From e7d999109d8f66e8ab151f8b1b5c502a81892725 Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Sat, 15 Nov 2025 20:56:25 -0500 Subject: [PATCH 5/6] add initial ghost logic --- src/Blinky.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- src/Blinky.h | 5 +++- src/Entity.h | 19 ++++++++++++++- src/Game.cpp | 8 ++++++- src/MazeMap.cpp | 10 ++++++++ src/MazeMap.h | 6 ++++- 6 files changed, 104 insertions(+), 5 deletions(-) diff --git a/src/Blinky.cpp b/src/Blinky.cpp index 92e7ab6..0cd9d59 100644 --- a/src/Blinky.cpp +++ b/src/Blinky.cpp @@ -1,5 +1,64 @@ #include "Blinky.h" +#include "Entity.h" +#include "MazeMap.h" +#include -void Blinky::setTargetTile(Entity& pacman) { +void Blinky::setTargetTile(sf::Vector2i target) { + targetTile = target; +} +void Blinky::setBestMove(Entity& pacman) { + if (!mazeMap) return; + + setTargetTile(pacman.getCurrentMazeTile()); + + sf::Vector2i currentTile = getCurrentMazeTile(); + MovementDir currentDir = getCurrentDirection(); + + MovementDir bestDirection = MovementDir::STATIC; + float minDistance = std::numeric_limits::max(); + + MovementDir directions[] = {MovementDir::UP, MovementDir::DOWN, MovementDir::LEFT, MovementDir::RIGHT}; + + for (MovementDir dir : directions) { + if ((currentDir == MovementDir::UP && dir == MovementDir::DOWN) || + (currentDir == MovementDir::DOWN && dir == MovementDir::UP) || + (currentDir == MovementDir::LEFT && dir == MovementDir::RIGHT) || + (currentDir == MovementDir::RIGHT && dir == MovementDir::LEFT)) { + continue; + } + + if (!mazeMap->entityCanMove(*this, dir)) { + continue; + } + + sf::Vector2i nextTile = currentTile; + switch (dir) { + case MovementDir::UP: + nextTile.y -= 1; + break; + case MovementDir::DOWN: + nextTile.y += 1; + break; + case MovementDir::LEFT: + nextTile.x -= 1; + break; + case MovementDir::RIGHT: + nextTile.x += 1; + break; + case MovementDir::STATIC: + break; + } + + float distance = mazeMap->distanceBetweenTiles(nextTile, targetTile); + + if (distance < minDistance) { + minDistance = distance; + bestDirection = dir; + } + } + + if (bestDirection != MovementDir::STATIC) { + queueDirection(bestDirection); + } }; diff --git a/src/Blinky.h b/src/Blinky.h index 80b2a98..a80f6e2 100644 --- a/src/Blinky.h +++ b/src/Blinky.h @@ -2,10 +2,13 @@ #define BLINKY_H #include "Ghost.h" +#include class Blinky : public Ghost { public: - void setTargetTile(Entity& pacman); + void setTargetTile(sf::Vector2i target); + + void setBestMove(Entity& pacman); }; #endif diff --git a/src/Entity.h b/src/Entity.h index 256b991..0672b84 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -16,6 +16,8 @@ #include #include +class MazeMap; + enum class MovementDir { STATIC, UP, @@ -35,7 +37,8 @@ public: currentDirection(MovementDir::STATIC), queuedDirection(MovementDir::STATIC), targetPosition(std::nullopt), - isMoving(false) {}; + isMoving(false), + mazeMap(nullptr) {}; void setAnimationTiles(sf::Texture& textureSheet, sf::Vector2i pixelLocation, const std::string& animationName, sf::Vector2i tileSize, unsigned int animationTiles, unsigned int pixelGap); @@ -61,12 +64,22 @@ public: void setMovementSpeed(sf::Vector2f newMovementSpeed) { movementSpeed = newMovementSpeed; } + void setCurrentMazeTile(sf::Vector2i mazeTile) { + currentMazeTile = mazeTile; + } + + sf::Vector2i getCurrentMazeTile() { return currentMazeTile; } + void adjustTargetPosition(sf::Vector2f offset) { if (targetPosition.has_value()) { targetPosition = targetPosition.value() + offset; } } + void setMazeMap(MazeMap* map) { mazeMap = map; } + + MazeMap* getMazeMap() { return mazeMap; } + protected: virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override; @@ -84,7 +97,11 @@ protected: std::optional targetPosition; + sf::Vector2i currentMazeTile; + bool isMoving; + + MazeMap* mazeMap; }; #endif diff --git a/src/Game.cpp b/src/Game.cpp index 87e9748..964803e 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -10,12 +10,12 @@ #include "Game.h" #include "Blinky.h" #include "Clyde.h" +#include "Entity.h" #include "Inky.h" #include "MazeMap.h" #include "Pinky.h" #include "ResourceManager.h" #include "Pacman.h" -#include "Ghost.h" json Game::loadConfig(const std::filesystem::path& configPath) { std::ifstream file(configPath); @@ -330,6 +330,12 @@ void Game::run() { pacman.update(); + //check if blinky is at an intersection + //if yes set target tile to pacmans tile + //calculate distance for all legal move options + //choose option with least distance for blinky to pacman + + map.handleTunnelWrapping(pacman); if (map.hasPellet(currentPacmanTile)) { diff --git a/src/MazeMap.cpp b/src/MazeMap.cpp index 544bfe7..d9b35d4 100644 --- a/src/MazeMap.cpp +++ b/src/MazeMap.cpp @@ -1,5 +1,7 @@ #include "MazeMap.h" +#include "Entity.h" #include +#include bool MazeMap::loadMaze(const std::vector& collisionData, const std::vector& pelletData, @@ -265,3 +267,11 @@ void MazeMap::handleTunnelWrapping(Entity& entity) { entity.setPosition({newX, pos.y}); } }; + +float MazeMap::distanceBetweenTiles(sf::Vector2i t1, sf::Vector2i t2) { + sf::Vector2i delta = {t1.x - t2.x, t1.y - t2.y}; + + float distance = std::sqrt(delta.x * delta.x + delta.y * delta.y); + + return distance; +}; diff --git a/src/MazeMap.h b/src/MazeMap.h index 90ad9cb..859429c 100644 --- a/src/MazeMap.h +++ b/src/MazeMap.h @@ -6,7 +6,9 @@ #include #include #include -#include "Entity.h" + +class Entity; +enum class MovementDir; enum class PelletType { NONE, @@ -56,6 +58,8 @@ public: bool isIntersectionTile(sf::Vector2i tileCoords) const; + float distanceBetweenTiles(sf::Vector2i t1, sf::Vector2i t2); + unsigned int getWidth() const { return width; } unsigned int getHeight() const { return height; } unsigned int getTileSize() const { return tileSize; } From bc9113cc3d8c86f3e79abab156c2fdeef491890a Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Mon, 17 Nov 2025 11:37:56 -0500 Subject: [PATCH 6/6] update game tile size to 3x scale --- src/Clyde.cpp | 2 +- src/Game.cpp | 100 +++++++++++++++++++++++++------------------------- src/Game.h | 4 +- src/Inky.cpp | 2 +- src/Pinky.cpp | 2 +- 5 files changed, 56 insertions(+), 54 deletions(-) diff --git a/src/Clyde.cpp b/src/Clyde.cpp index 1c5c2b0..13838ec 100644 --- a/src/Clyde.cpp +++ b/src/Clyde.cpp @@ -1,5 +1,5 @@ #include "Clyde.h" -void Clyde::setTargetTile() { +void Clyde::setTargetTile(Entity& pacman) { }; diff --git a/src/Game.cpp b/src/Game.cpp index 964803e..436589b 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -82,14 +82,16 @@ void Game::run() { resources.loadSound("siren4_firstloop", "assets/sounds/siren4_firstloop.wav"); resources.loadSound("start", "assets/sounds/start.wav"); - // Texture layout: [Pellet Maze Image] + gap (16px) + [Base Maze Image] + // Texture layout: [Pellet Maze Image] + gap (4px at base scale) + [Base Maze Image] // Original: 224px (28*8) + 4px gap at 8px tiles - // Scaled 4x: 896px (28*32) + 16px gap at 32px tiles + // Gap scales with tile size: (28 * tileSize) + (4 * scaleFactor) + const unsigned int mazePixelWidth = 28 * tileSize; + const unsigned int gapWidth = 4 * scaleFactor; map.loadMaze(resources.getMazeMap(), resources.getPelletMap(), resources.getTexture("all_textures"), tileSize, - {912, 0}, + {mazePixelWidth + gapWidth, 0}, {0, 0}); @@ -100,49 +102,49 @@ void Game::run() { Inky inky; Clyde clyde; - pacman.setAnimationTiles(resources.getTexture("all_textures"), {1824, 0}, "right_walking", {60, 60}, 2, 0); - pacman.setAnimationTiles(resources.getTexture("all_textures"), {1824, 64}, "left_walking", {60, 60}, 2, 0); - pacman.setAnimationTiles(resources.getTexture("all_textures"), {1824, 128}, "up_walking", {60, 60}, 2, 0); - pacman.setAnimationTiles(resources.getTexture("all_textures"), {1824, 192}, "down_walking", {60, 60}, 2, 0); - pacman.setAnimationTiles(resources.getTexture("all_textures"), {1952, 0}, "static", {60, 60}, 1, 0); - pacman.setAnimationTiles(resources.getTexture("all_textures"), {2016, 0}, "death", {60, 60}, 11, 4); + pacman.setAnimationTiles(resources.getTexture("all_textures"), {1368, 0}, "right_walking", {45, 45}, 2, 0); + pacman.setAnimationTiles(resources.getTexture("all_textures"), {1368, 48}, "left_walking", {45, 45}, 2, 0); + pacman.setAnimationTiles(resources.getTexture("all_textures"), {1368, 96}, "up_walking", {45, 45}, 2, 0); + pacman.setAnimationTiles(resources.getTexture("all_textures"), {1368, 144}, "down_walking", {45, 45}, 2, 0); + pacman.setAnimationTiles(resources.getTexture("all_textures"), {1464, 0}, "static", {45, 45}, 1, 0); + pacman.setAnimationTiles(resources.getTexture("all_textures"), {1512, 0}, "death", {45, 45}, 11, 3); pacman.setActiveSprite("static", 0); - pacman.setOrigin({30, 30}); + pacman.setOrigin({22.5, 22.5}); // Tile center = tile * tileSize + tileSize/2 - pacman.setPosition({14.5 * 32.0f - 16.0f, 24 * 32.0f - 16.0f}); + pacman.setPosition({14.5f * tileSize - (tileSize / 2.0f), 24.0f * tileSize - (tileSize / 2.0f)}); pacman.setMovementSpeed({perLoopMove, perLoopMove}); - blinky.setAnimationTiles(resources.getTexture("all_textures"), {1824, 256}, "right_walking", {60, 60}, 2, 4); - blinky.setAnimationTiles(resources.getTexture("all_textures"), {1952, 256}, "left_walking", {60, 60}, 2, 4); - blinky.setAnimationTiles(resources.getTexture("all_textures"), {2080, 256}, "up_walking", {60, 60}, 2, 4); - blinky.setAnimationTiles(resources.getTexture("all_textures"), {2208, 256}, "down_walking", {60, 60}, 2, 4); + blinky.setAnimationTiles(resources.getTexture("all_textures"), {1368, 192}, "right_walking", {45, 45}, 2, 3); + blinky.setAnimationTiles(resources.getTexture("all_textures"), {1464, 192}, "left_walking", {45, 45}, 2, 3); + blinky.setAnimationTiles(resources.getTexture("all_textures"), {1560, 192}, "up_walking", {45, 45}, 2, 3); + blinky.setAnimationTiles(resources.getTexture("all_textures"), {1656, 192}, "down_walking", {45, 45}, 2, 3); blinky.setActiveSprite("left_walking", 0); - blinky.setOrigin({30, 30}); - blinky.setPosition({14.5 * 32.0f - 16.0f, 12 * 32.0f - 16.0f}); + blinky.setOrigin({22.5, 22.5}); + blinky.setPosition({14.5f * tileSize - (tileSize / 2.0f), 12.0f * tileSize - (tileSize / 2.0f)}); - pinky.setAnimationTiles(resources.getTexture("all_textures"), {1824, 320}, "right_walking", {60, 60}, 2, 4); - pinky.setAnimationTiles(resources.getTexture("all_textures"), {1952, 320}, "left_walking", {60, 60}, 2, 4); - pinky.setAnimationTiles(resources.getTexture("all_textures"), {2080, 320}, "up_walking", {60, 60}, 2, 4); - pinky.setAnimationTiles(resources.getTexture("all_textures"), {2208, 320}, "down_walking", {60, 60}, 2, 4); + pinky.setAnimationTiles(resources.getTexture("all_textures"), {1368, 240}, "right_walking", {45, 45}, 2, 3); + pinky.setAnimationTiles(resources.getTexture("all_textures"), {1464, 240}, "left_walking", {45, 45}, 2, 3); + pinky.setAnimationTiles(resources.getTexture("all_textures"), {1560, 240}, "up_walking", {45, 45}, 2, 3); + pinky.setAnimationTiles(resources.getTexture("all_textures"), {1656, 240}, "down_walking", {45, 45}, 2, 3); pinky.setActiveSprite("down_walking", 0); - pinky.setOrigin({30, 30}); - pinky.setPosition({14.5 * 32.0f - 16.0f, 15 * 32.0f - 16.0f}); + pinky.setOrigin({22.5, 22.5}); + pinky.setPosition({14.5f * tileSize - (tileSize / 2.0f), 15.0f * tileSize - (tileSize / 2.0f)}); - inky.setAnimationTiles(resources.getTexture("all_textures"), {1824, 384}, "right_walking", {60, 60}, 2, 4); - inky.setAnimationTiles(resources.getTexture("all_textures"), {1952, 384}, "left_walking", {60, 60}, 2, 4); - inky.setAnimationTiles(resources.getTexture("all_textures"), {2080, 384}, "up_walking", {60, 60}, 2, 4); - inky.setAnimationTiles(resources.getTexture("all_textures"), {2208, 384}, "down_walking", {60, 60}, 2, 4); + inky.setAnimationTiles(resources.getTexture("all_textures"), {1368, 288}, "right_walking", {45, 45}, 2, 3); + inky.setAnimationTiles(resources.getTexture("all_textures"), {1464, 288}, "left_walking", {45, 45}, 2, 3); + inky.setAnimationTiles(resources.getTexture("all_textures"), {1560, 288}, "up_walking", {45, 45}, 2, 3); + inky.setAnimationTiles(resources.getTexture("all_textures"), {1656, 288}, "down_walking", {45, 45}, 2, 3); inky.setActiveSprite("up_walking", 0); - inky.setOrigin({30, 30}); - inky.setPosition({12.5 * 32.0f - 16.0f, 15 * 32.0f - 16.0f}); + inky.setOrigin({22.5, 22.5}); + inky.setPosition({12.5f * tileSize - (tileSize / 2.0f), 15.0f * tileSize - (tileSize / 2.0f)}); - clyde.setAnimationTiles(resources.getTexture("all_textures"), {1824, 448}, "right_walking", {60, 60}, 2, 4); - clyde.setAnimationTiles(resources.getTexture("all_textures"), {1952, 448}, "left_walking", {60, 60}, 2, 4); - clyde.setAnimationTiles(resources.getTexture("all_textures"), {2080, 448}, "up_walking", {60, 60}, 2, 4); - clyde.setAnimationTiles(resources.getTexture("all_textures"), {2208, 448}, "down_walking", {60, 60}, 2, 4); + clyde.setAnimationTiles(resources.getTexture("all_textures"), {1368, 336}, "right_walking", {45, 45}, 2, 3); + clyde.setAnimationTiles(resources.getTexture("all_textures"), {1464, 336}, "left_walking", {45, 45}, 2, 3); + clyde.setAnimationTiles(resources.getTexture("all_textures"), {1560, 336}, "up_walking", {45, 45}, 2, 3); + clyde.setAnimationTiles(resources.getTexture("all_textures"), {1656, 336}, "down_walking", {45, 45}, 2, 3); clyde.setActiveSprite("up_walking", 0); - clyde.setOrigin({30, 30}); - clyde.setPosition({16.5 * 32.0f - 16.0f, 15 * 32.0f - 16.0f}); + clyde.setOrigin({22.5, 22.5}); + clyde.setPosition({16.5f * tileSize - (tileSize / 2.0f), 15.0f * tileSize - (tileSize / 2.0f)}); auto window = sf::RenderWindow(sf::VideoMode(windowRes), windowName); @@ -167,23 +169,23 @@ void Game::run() { sf::Font bitFont = resources.getFont("bitFont"); sf::Text scoreText(bitFont); scoreText.setString(std::to_string(score)); - scoreText.setPosition({16, 32 * 31 + 16}); + scoreText.setPosition({16.0f, tileSize * 31.0f + 16.0f}); - sf::Sprite pacmanLifeOne(resources.getTexture("all_textures"), {{2340, 68}, {52, 52}}); - pacmanLifeOne.setOrigin({52, 0}); - pacmanLifeOne.setPosition({32 * 28, 32 * 31}); - - sf::Sprite pacmanLifeTwo(resources.getTexture("all_textures"), {{2340, 68}, {52, 52}}); - pacmanLifeTwo.setOrigin({52, 0}); - pacmanLifeTwo.setPosition({32 * 26.5, 32 * 31}); + sf::Sprite pacmanLifeOne(resources.getTexture("all_textures"), {{1755, 51}, {39, 39}}); + pacmanLifeOne.setOrigin({39, 0}); + pacmanLifeOne.setPosition({tileSize * 28.0f, tileSize * 31.0f}); - sf::Sprite fruitOne(resources.getTexture("all_textures"), {{1956, 192}, {60, 60}}); - fruitOne.setOrigin({60, 0}); - fruitOne.setPosition({32 * 16, 32 * 31}); + sf::Sprite pacmanLifeTwo(resources.getTexture("all_textures"), {{1755, 51}, {39, 39}}); + pacmanLifeTwo.setOrigin({39, 0}); + pacmanLifeTwo.setPosition({tileSize * 26.5f, tileSize * 31.0f}); - sf::Sprite fruitTwo(resources.getTexture("all_textures"), {{1956, 192}, {60, 60}}); - fruitTwo.setOrigin({60, 0}); - fruitTwo.setPosition({32 * 14, 32 * 31}); + sf::Sprite fruitOne(resources.getTexture("all_textures"), {{1467, 144}, {45, 45}}); + fruitOne.setOrigin({45, 0}); + fruitOne.setPosition({tileSize * 16.0f, tileSize * 31.0f}); + + sf::Sprite fruitTwo(resources.getTexture("all_textures"), {{1467, 144}, {45, 45}}); + fruitTwo.setOrigin({45, 0}); + fruitTwo.setPosition({tileSize * 14.0f, tileSize * 31.0f}); while (window.isOpen()) { diff --git a/src/Game.h b/src/Game.h index 2c9fd8b..dbeaeb5 100644 --- a/src/Game.h +++ b/src/Game.h @@ -25,9 +25,9 @@ private: const float perPixelMove; const int baseTileSize; - int scaleFactor = 4; + int scaleFactor = 3; - sf::Vector2u windowRes = {896, 1080}; + sf::Vector2u windowRes = {672, 810}; std::string windowName = "Pacmen"; }; diff --git a/src/Inky.cpp b/src/Inky.cpp index 37c6055..3b9d065 100644 --- a/src/Inky.cpp +++ b/src/Inky.cpp @@ -1,5 +1,5 @@ #include "Inky.h" -void Inky::setTargetTile() { +void Inky::setTargetTile(Entity& pacman, Entity& blinky) { }; diff --git a/src/Pinky.cpp b/src/Pinky.cpp index 472cea7..da912f9 100644 --- a/src/Pinky.cpp +++ b/src/Pinky.cpp @@ -1,5 +1,5 @@ #include "Pinky.h" -void Pinky::setTargetTile() { +void Pinky::setTargetTile(Entity& pacman) { };