Merge branch 'main' of github.com:mod-cpp/pacman

This commit is contained in:
Ólafur Waage 2021-09-10 11:04:44 +02:00
commit e07616ea52
9 changed files with 17 additions and 19 deletions

3
.gitmodules vendored
View file

@ -1,3 +0,0 @@
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git

View file

@ -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;

View file

@ -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);
}

View file

@ -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);

View file

@ -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;

View file

@ -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<int64_t>(ghost);
int64_t x = 0;
auto y = static_cast<size_t>(ghost);
size_t x = 0;
switch (direction) {
case Direction::RIGHT:
x = 0;

View file

@ -18,7 +18,7 @@ public:
void pause();
private:
int64_t animation_position = 0;
size_t animation_position = 0;
double animation_position_delta = 0.0;
};

View file

@ -1,6 +1,7 @@
#pragma once
#include <cmath>
#include <cassert>
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) {

1
vcpkg

@ -1 +0,0 @@
Subproject commit 1257354a3ab0bebd8abe95281ca561537853578c