diff --git a/lib/Ghost.cpp b/lib/Ghost.cpp index 68f4eec..33acd00 100644 --- a/lib/Ghost.cpp +++ b/lib/Ghost.cpp @@ -178,7 +178,7 @@ void Ghost::updateDirection(const GameState & gameState) { if (opposite_direction) continue; - const GridPosition grid_position = { int64_t(move.position.x), int64_t(move.position.y) }; + const GridPosition grid_position = { size_t(move.position.x), size_t(move.position.y) }; const bool can_walk = isWalkableForGhost(grid_position, current_grid_position, isEyes()); if (!can_walk) continue; diff --git a/lib/Inky.cpp b/lib/Inky.cpp index ab8d268..6b258ac 100644 --- a/lib/Inky.cpp +++ b/lib/Inky.cpp @@ -53,8 +53,8 @@ Position Inky::target(const GameState & gameState) const { // And selects a point on the line crossing blinky and this position that is at twice that distance // away from blinky - targetPosition.x += int64_t((targetPosition.x - blinkyPosition.x) / distanceBetweenBlinkyAndTarget) * 2; - targetPosition.y += int64_t((targetPosition.y - blinkyPosition.y) / distanceBetweenBlinkyAndTarget) * 2; + targetPosition.x += size_t((targetPosition.x - blinkyPosition.x) / distanceBetweenBlinkyAndTarget) * 2; + targetPosition.y += size_t((targetPosition.y - blinkyPosition.y) / distanceBetweenBlinkyAndTarget) * 2; return gridPositionToPosition(targetPosition); } diff --git a/lib/PacMan.cpp b/lib/PacMan.cpp index a78ea5f..c67f4ed 100644 --- a/lib/PacMan.cpp +++ b/lib/PacMan.cpp @@ -64,13 +64,13 @@ void PacMan::updateMazePosition(std::chrono::milliseconds time_delta) { auto moveToPosition = [position_delta](Position point, Direction move_direction) { switch (move_direction) { case Direction::LEFT: - return GridPosition{ int64_t(point.x - position_delta), int64_t(point.y) }; + return GridPosition{ size_t(point.x - position_delta), size_t(point.y) }; case Direction::RIGHT: - return GridPosition{ int64_t(point.x + pacman_size), int64_t(point.y) }; + return GridPosition{ size_t(point.x + pacman_size), size_t(point.y) }; case Direction::UP: - return GridPosition{ int64_t(point.x), int64_t(point.y - position_delta) }; + return GridPosition{ size_t(point.x), size_t(point.y - position_delta) }; case Direction::DOWN: - return GridPosition{ int64_t(point.x), int64_t(point.y + pacman_size) }; + return GridPosition{ size_t(point.x), size_t(point.y + pacman_size) }; case Direction::NONE: default: return positionToGridPosition(point); diff --git a/lib/PacManAnimation.cpp b/lib/PacManAnimation.cpp index 37e2b5e..7ad5716 100644 --- a/lib/PacManAnimation.cpp +++ b/lib/PacManAnimation.cpp @@ -32,7 +32,7 @@ void PacManAnimation::updateAnimationPosition(std::chrono::milliseconds time_del return; animation_position_delta += (0.02) * double(time_delta.count()); - animation_position = int64_t(animation_position + animation_position_delta); + animation_position = size_t(animation_position + animation_position_delta); if (!dead) animation_position = animation_position % 4; diff --git a/lib/include/Atlas.hpp b/lib/include/Atlas.hpp index d5226f3..530d885 100644 --- a/lib/include/Atlas.hpp +++ b/lib/include/Atlas.hpp @@ -47,8 +47,8 @@ constexpr GridPosition eyeSprite(Direction direction) { constexpr GridPosition ghostSprite(Ghost ghost, Direction direction, bool alternative) { assert(ghost >= Ghost::blinky && ghost <= Ghost::clyde && "Invalid Ghost"); - auto y = static_cast(ghost); - int64_t x = 0; + auto y = static_cast(ghost); + size_t x = 0; switch (direction) { case Direction::RIGHT: x = 0; diff --git a/lib/include/PacManAnimation.hpp b/lib/include/PacManAnimation.hpp index 4c4e520..42dcde0 100644 --- a/lib/include/PacManAnimation.hpp +++ b/lib/include/PacManAnimation.hpp @@ -18,7 +18,7 @@ public: void pause(); private: - int64_t animation_position = 0; + size_t animation_position = 0; double animation_position_delta = 0.0; }; diff --git a/lib/include/Position.hpp b/lib/include/Position.hpp index 40eb798..712bff1 100644 --- a/lib/include/Position.hpp +++ b/lib/include/Position.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace pacman { @@ -10,13 +11,14 @@ struct Position { }; struct GridPosition { - int64_t x; - int64_t y; - constexpr GridPosition(int64_t x, int64_t y) : x(x), y(y) {} + size_t x; + size_t y; + constexpr GridPosition(size_t x, size_t y) : x(x), y(y) {} }; inline GridPosition positionToGridPosition(Position pos) { - return { int64_t(std::round(pos.x)), int64_t(std::round(pos.y)) }; + assert(pos.x >= 0 && pos.y >= 0 && "Position should have positive values"); + return { size_t(std::round(pos.x)), size_t(std::round(pos.y)) }; } inline Position gridPositionToPosition(GridPosition pos) {