modify collisions

This commit is contained in:
2025-11-10 12:02:32 -05:00
parent 9d7c162dfa
commit 83f033f62b
4 changed files with 14 additions and 12 deletions
+2
View File
@@ -41,6 +41,8 @@ public:
void move(MovementDir dir);
sf::Vector2f getMovementSpeed() const { return movementSpeed; }
protected:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
+2 -1
View File
@@ -70,7 +70,8 @@ void Game::run() {
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});
// Tile center = tile * tileSize + tileSize/2
pacman.setPosition({14.5 * 32.0f - 16.0f, 24 * 32.0f - 16.0f});
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);
+9 -10
View File
@@ -113,28 +113,27 @@ sf::Vector2i MazeMap::getTileCoords(sf::Vector2f screenPos) {
};
bool MazeMap::entityCanMove(Entity& entity, MovementDir dir) {
sf::Vector2i coords = getTileCoords(entity.getPosition());
int xTile = coords.x;
int yTile = coords.y;
sf::Vector2f currentPos = entity.getPosition();
sf::Vector2f newPos = currentPos;
sf::Vector2f movementSpeed = entity.getMovementSpeed();
switch (dir) {
case MovementDir::UP:
return !isWall(xTile, yTile - 1);
newPos.y -= movementSpeed.y;
break;
case MovementDir::DOWN:
return !isWall(xTile, yTile + 1);
newPos.y += movementSpeed.y;
break;
case MovementDir::LEFT:
return !isWall(xTile - 1, yTile);
newPos.x -= movementSpeed.x;
break;
case MovementDir::RIGHT:
return !isWall(xTile + 1, yTile);
newPos.x += movementSpeed.x;
break;
case MovementDir::STATIC:
return true;
break;
};
return false;
sf::Vector2i newTileCoords = getTileCoords(newPos);
return !isWall(newTileCoords.x, newTileCoords.y);
};
+1 -1
View File
@@ -1,12 +1,12 @@
#ifndef MAZEMAP_H
#define MAZEMAP_H
#include "Entity.h"
#include <SFML/Graphics.hpp>
#include <SFML/System/Vector2.hpp>
#include <vector>
#include <filesystem>
#include "Entity.h"
class MazeMap : public sf::Drawable, public sf::Transformable {
public: