Fix conversions warnings
This commit is contained in:
parent
36fc3f5a74
commit
bc83fa77c3
7 changed files with 12 additions and 12 deletions
|
@ -7,7 +7,7 @@
|
||||||
namespace pacman {
|
namespace pacman {
|
||||||
|
|
||||||
Canvas::Canvas()
|
Canvas::Canvas()
|
||||||
: window(sf::VideoMode((viewDimensions().width / 2), (viewDimensions().height / 2)),
|
: window(sf::VideoMode(std::uint32_t(viewDimensions().width / 2), std::uint32_t(viewDimensions().height / 2)),
|
||||||
"Pacman",
|
"Pacman",
|
||||||
sf::Style::Titlebar | sf::Style::Close),
|
sf::Style::Titlebar | sf::Style::Close),
|
||||||
view(sf::FloatRect(0, 0, float(viewDimensions().width), float(viewDimensions().height))) {
|
view(sf::FloatRect(0, 0, float(viewDimensions().width), float(viewDimensions().height))) {
|
||||||
|
@ -124,8 +124,8 @@ void Canvas::renderLives(int lives) {
|
||||||
const size_t y = TARGET_MAZE_HEIGHT;
|
const size_t y = TARGET_MAZE_HEIGHT;
|
||||||
|
|
||||||
Sprite pacmanSprite = getSprite(liveSprite);
|
Sprite pacmanSprite = getSprite(liveSprite);
|
||||||
for (int i = 0; i < lives - 1; i++) {
|
for (auto i = 0; i < lives - 1; i++) {
|
||||||
auto life_position = i * SPRITE_WIDTH * 1.5f;
|
auto life_position = float(i) * SPRITE_WIDTH * 1.5f;
|
||||||
sf::Vector2f pos{ x + life_position, y };
|
sf::Vector2f pos{ x + life_position, y };
|
||||||
pacmanSprite.setPosition(pos.x, pos.y);
|
pacmanSprite.setPosition(pos.x, pos.y);
|
||||||
window.draw(pacmanSprite);
|
window.draw(pacmanSprite);
|
||||||
|
|
|
@ -29,7 +29,7 @@ Position Clyde::target(const GameState & gameState) const {
|
||||||
return targetPosition;
|
return targetPosition;
|
||||||
|
|
||||||
const auto pacManPosition = gameState.pacMan.positionInGrid();
|
const auto pacManPosition = gameState.pacMan.positionInGrid();
|
||||||
auto distanceFomPacMan = std::hypot(pos.x - pacManPosition.x, pos.y - pacManPosition.y);
|
auto distanceFomPacMan = std::hypot(pos.x - double(pacManPosition.x), pos.y - double(pacManPosition.y));
|
||||||
if (distanceFomPacMan > 8)
|
if (distanceFomPacMan > 8)
|
||||||
targetPosition = gridPositionToPosition(pacManPosition);
|
targetPosition = gridPositionToPosition(pacManPosition);
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ bool Ghost::isInPen() const {
|
||||||
void Ghost::updatePosition(std::chrono::milliseconds time_delta, const GameState & gameState) {
|
void Ghost::updatePosition(std::chrono::milliseconds time_delta, const GameState & gameState) {
|
||||||
updateDirection(gameState);
|
updateDirection(gameState);
|
||||||
|
|
||||||
double position_delta = (0.004 * time_delta.count()) * speed(gameState);
|
double position_delta = (0.004 * double(time_delta.count())) * speed(gameState);
|
||||||
|
|
||||||
const auto old_position = pos;
|
const auto old_position = pos;
|
||||||
const GridPosition old_grid_position = positionToGridPosition(old_position);
|
const GridPosition old_grid_position = positionToGridPosition(old_position);
|
||||||
|
@ -197,7 +197,7 @@ void Ghost::updateDirection(const GameState & gameState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ghost::updateAnimation(std::chrono::milliseconds time_delta) {
|
void Ghost::updateAnimation(std::chrono::milliseconds time_delta) {
|
||||||
timeForAnimation += time_delta.count();
|
timeForAnimation += double(time_delta.count());
|
||||||
if (timeForAnimation >= 250) {
|
if (timeForAnimation >= 250) {
|
||||||
timeForAnimation = 0;
|
timeForAnimation = 0;
|
||||||
animationIndex = (animationIndex + 1) % 4;
|
animationIndex = (animationIndex + 1) % 4;
|
||||||
|
|
|
@ -49,12 +49,12 @@ Position Inky::target(const GameState & gameState) const {
|
||||||
|
|
||||||
// Then it calculates the distance between Blinky and this position
|
// Then it calculates the distance between Blinky and this position
|
||||||
const auto & blinkyPosition = gameState.blinky.positionInGrid();
|
const auto & blinkyPosition = gameState.blinky.positionInGrid();
|
||||||
auto distanceBetweenBlinkyAndTarget = std::hypot(blinkyPosition.x - targetPosition.x, blinkyPosition.y - targetPosition.y);
|
double distanceBetweenBlinkyAndTarget = std::hypot(blinkyPosition.x - targetPosition.x, blinkyPosition.y - targetPosition.y);
|
||||||
|
|
||||||
// And selects a point on the line crossing blinky and this position that is at twice that distance
|
// And selects a point on the line crossing blinky and this position that is at twice that distance
|
||||||
// away from blinky
|
// away from blinky
|
||||||
targetPosition.x += size_t((targetPosition.x - blinkyPosition.x) / distanceBetweenBlinkyAndTarget) * 2;
|
targetPosition.x += std::size_t((double(targetPosition.x) - double(blinkyPosition.x)) / distanceBetweenBlinkyAndTarget) * 2;
|
||||||
targetPosition.y += size_t((targetPosition.y - blinkyPosition.y) / distanceBetweenBlinkyAndTarget) * 2;
|
targetPosition.y += std::size_t((double(targetPosition.y) - double(blinkyPosition.y)) / distanceBetweenBlinkyAndTarget) * 2;
|
||||||
|
|
||||||
return gridPositionToPosition(targetPosition);
|
return gridPositionToPosition(targetPosition);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ void PacMan::updateMazePosition(std::chrono::milliseconds time_delta) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double position_delta = 0.004 * time_delta.count();
|
const double position_delta = 0.004 * double(time_delta.count());
|
||||||
const auto pacman_size = 1;
|
const auto pacman_size = 1;
|
||||||
|
|
||||||
auto moveToPosition = [position_delta, pacman_size](Position point, Direction move_direction) {
|
auto moveToPosition = [position_delta, pacman_size](Position point, Direction move_direction) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ void PacManAnimation::updateAnimationPosition(std::chrono::milliseconds time_del
|
||||||
return;
|
return;
|
||||||
|
|
||||||
animation_position_delta += (0.02) * double(time_delta.count());
|
animation_position_delta += (0.02) * double(time_delta.count());
|
||||||
animation_position = size_t(animation_position + animation_position_delta);
|
animation_position += size_t(animation_position_delta);
|
||||||
|
|
||||||
if (!dead)
|
if (!dead)
|
||||||
animation_position = animation_position % 4;
|
animation_position = animation_position % 4;
|
||||||
|
|
|
@ -42,7 +42,7 @@ protected:
|
||||||
Atlas::Ghost spriteSet;
|
Atlas::Ghost spriteSet;
|
||||||
Direction direction = Direction::NONE;
|
Direction direction = Direction::NONE;
|
||||||
double timeForAnimation = 0;
|
double timeForAnimation = 0;
|
||||||
int animationIndex = 0;
|
std::size_t animationIndex = 0;
|
||||||
State state = State::Chase;
|
State state = State::Chase;
|
||||||
std::chrono::milliseconds timeFrighten = {};
|
std::chrono::milliseconds timeFrighten = {};
|
||||||
std::chrono::milliseconds timeChase = {};
|
std::chrono::milliseconds timeChase = {};
|
||||||
|
|
Loading…
Reference in a new issue