Replace floats by doubles

This commit is contained in:
Corentin Jabot 2021-07-05 11:40:10 +02:00
parent b5b9d9c168
commit ba515eaca5
8 changed files with 15 additions and 15 deletions

View File

@ -43,11 +43,11 @@ std::array<std::array<int, COLUMNS>, ROWS> Board::board = {{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 30
}};
bool Board::isWalkableForPacMan(Position point, float d, Direction direction) {
bool Board::isWalkableForPacMan(Position point, double d, Direction direction) {
return isWalkable(point, d, direction, true);
}
bool Board::isWalkableForGhost(Position point, float d, Direction direction) {
bool Board::isWalkableForGhost(Position point, double d, Direction direction) {
return isWalkable(point, d, direction, false);
}
@ -63,11 +63,11 @@ bool Board::isInPen(Position point) {
return board[int(point.y)][int(point.x)] == int(Cell::pen);
}
bool Board::isWalkable(Position point, float position_delta, Direction direction, bool pacman) {
bool Board::isWalkable(Position point, double position_delta, Direction direction, bool pacman) {
if (point.x <= 0 || point.x >= COLUMNS - 1)
return true;
auto cellAtPosition = [&](Position point, float position_delta, Direction direction) {
auto cellAtPosition = [&](Position point, double position_delta, Direction direction) {
switch (direction) {
case Direction::LEFT:
return board[int(point.y)][int(point.x - position_delta)];

View File

@ -22,8 +22,8 @@ public:
pen = 5,
};
[[nodiscard]] static bool isWalkableForPacMan(Position point, float d, Direction direction) ;
[[nodiscard]] static bool isWalkableForGhost(Position point, float d, Direction direction) ;
[[nodiscard]] static bool isWalkableForPacMan(Position point, double d, Direction direction) ;
[[nodiscard]] static bool isWalkableForGhost(Position point, double d, Direction direction) ;
[[nodiscard]] static bool isWalkableForGost(Position point, Position origin, bool isEyes) ;
[[nodiscard]] static bool isWalkable(Position point) ;
@ -50,7 +50,7 @@ public:
static Position clydeScatterTarget() { return { 0, 30 }; }
private:
[[nodiscard]] static bool isWalkable(Position point, float d, Direction direction, bool pacman) ;
[[nodiscard]] static bool isWalkable(Position point, double d, Direction direction, bool pacman) ;
static std::array<
std::array<int, COLUMNS>,
ROWS>

View File

@ -60,7 +60,7 @@ void Canvas::renderPellets(const Pellets & pellets) {
Sprite pellet = getSprite(pellets.currentSprite());
std::vector<PositionInt> pelletPositions = pellets.currentPositions();
for (const auto & pos : pelletPositions) {
renderSprite(pellet, { float(pos.x), float(pos.y) });
renderSprite(pellet, { double(pos.x), double(pos.y) });
}
}
@ -68,7 +68,7 @@ void Canvas::renderSuperPellets(const SuperPellets & superPellets) {
Sprite pellet = getSprite(superPellets.currentSprite());
std::vector<PositionInt> superPelletPositions = superPellets.currentPositions();
for (const auto & pos : superPelletPositions) {
renderSprite(pellet, { float(pos.x), float(pos.y) });
renderSprite(pellet, { double(pos.x), double(pos.y) });
}
}

View File

@ -81,7 +81,7 @@ bool Ghost::isInPen(const Board & board) const {
void Ghost::updatePosition(std::chrono::milliseconds time_delta, const Board & board) {
updateDirection(board);
float position_delta = (0.004 * time_delta.count()) * speed();
double position_delta = (0.004 * time_delta.count()) * speed();
switch (direction) {
case Direction::NONE:

View File

@ -61,7 +61,7 @@ void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta, bool
}
void PacMan::updateMazePosition(std::chrono::milliseconds time_delta, const Board & board) {
float position_delta = 0.004 * time_delta.count();
double position_delta = 0.004 * time_delta.count();
// Handle teleport
if (pos.x >= COLUMNS - 1 && direction == Direction::RIGHT) {

View File

@ -24,7 +24,7 @@ void PacManAnimation::updateAnimationPosition(std::chrono::milliseconds time_del
if (dead && animation_position >= 11)
return;
animation_position_delta += (0.02) * float(time_delta.count());
animation_position_delta += (0.02) * double(time_delta.count());
animation_position = int(animation_position + animation_position_delta);
if (!dead)

View File

@ -18,7 +18,7 @@ public:
private:
uint8_t animation_position = 0;
float animation_position_delta = 0.0;
double animation_position_delta = 0.0;
const PositionInt down_animation[4]{ Atlas::pacman_down_wide, Atlas::pacman_down_narrow, Atlas::pacman_closed, Atlas::pacman_down_narrow };
const PositionInt left_animation[4]{ Atlas::pacman_left_wide, Atlas::pacman_left_narrow, Atlas::pacman_closed, Atlas::pacman_left_narrow };
const PositionInt right_animation[4]{ Atlas::pacman_right_wide, Atlas::pacman_right_narrow, Atlas::pacman_closed, Atlas::pacman_right_narrow };

View File

@ -3,8 +3,8 @@
#include <SFML/Graphics.hpp>
struct Position {
float x;
float y;
double x;
double y;
};
struct PositionInt {