From 36bbf5b888be9d58d2f38a33349c6a3127814c2d Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Mon, 10 Nov 2025 11:36:20 -0500 Subject: [PATCH] add inital pacman position --- src/Game.cpp | 2 ++ src/MazeMap.cpp | 10 ++++++++++ src/MazeMap.h | 3 +++ 3 files changed, 15 insertions(+) diff --git a/src/Game.cpp b/src/Game.cpp index 0144814..36f9983 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -69,6 +69,8 @@ void Game::run() { 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.setActiveSprite("static", 0); + pacman.setOrigin({30, 30}); + pacman.setPosition({32 * 14.5 - 16, 32 * 24 - 16}); 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); diff --git a/src/MazeMap.cpp b/src/MazeMap.cpp index b5c62de..bffd51f 100644 --- a/src/MazeMap.cpp +++ b/src/MazeMap.cpp @@ -1,4 +1,5 @@ #include "MazeMap.h" +#include bool MazeMap::loadMaze(const std::vector& collisionData, const std::vector& pelletData, @@ -102,3 +103,12 @@ void MazeMap::draw(sf::RenderTarget& target, sf::RenderStates states) const { target.draw(pelletVertices, states); } + +// assumes maze is drawn at 0,0 +sf::Vector2i MazeMap::getTileCoords(sf::Vector2f screenPos) { + int tileX = static_cast(screenPos.x / tileSize); + int tileY = static_cast(screenPos.y / tileSize); + + return {tileX, tileY}; +}; + diff --git a/src/MazeMap.h b/src/MazeMap.h index a66f195..740f7e8 100644 --- a/src/MazeMap.h +++ b/src/MazeMap.h @@ -3,6 +3,7 @@ #include +#include #include #include @@ -26,6 +27,8 @@ public: int convert2DCoords(int x, int y) const { return x + y * width; } bool isLegalTile(int x, int y) const; + sf::Vector2i getTileCoords(sf::Vector2f screenPos); + unsigned int getWidth() const { return width; } unsigned int getHeight() const { return height; } unsigned int getTileSize() const { return tileSize; }