mirror of
https://github.com/dylanbenzi/pacmen-sfml.git
synced 2026-11-27 00:17:01 +00:00
modify methods to only use vectors
This commit is contained in:
+3
-3
@@ -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:
|
||||
|
||||
+47
-13
@@ -60,10 +60,10 @@ bool MazeMap::loadMaze(const std::vector<int>& 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<int>(width) &&
|
||||
y >= 0 && y < static_cast<int>(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<int>(width) &&
|
||||
tilePos.y >= 0 && tilePos.y < static_cast<int>(height);
|
||||
}
|
||||
|
||||
//bool MazeMap::isLegalTile(int x, int y) const {
|
||||
// return x >= 0 && x < static_cast<int>(width) &&
|
||||
// y >= 0 && y < static_cast<int>(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) {
|
||||
|
||||
+13
-5
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user