Skip to content

Commit

Permalink
Remove some unsignedness from ints.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Sep 13, 2024
1 parent f4df2fe commit 652742b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool Bullet::move()
if (!point_utils::isValidPoint(px, py, size_))
return false;

setLocation(point_utils::pointFromSigned(px, py));
setLocation({px, py});

return true;
}
Expand Down
13 changes: 4 additions & 9 deletions src/PointUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@

namespace point_utils
{
Point pointFromSigned(int x, int y)
bool isValidPoint(int x, int y, int objectSize)
{
return {static_cast<unsigned int>(x), static_cast<unsigned int>(y)};
}

bool isValidPoint(int x, int y, unsigned int objectSize)
{
const int maxCoordinate{static_cast<int>(
Config::getInstance().getBoardWidth() - (objectSize - 1))};
const int maxCoordinate{Config::getInstance().getBoardWidth() -
(objectSize - 1)};
return (x < maxCoordinate) && (y < maxCoordinate) && (y >= 0) && (x >= 0);
}

bool isValidPoint(Point point)
{
const unsigned int maxCoordinate{Config::getInstance().getBoardWidth()};
const int maxCoordinate{Config::getInstance().getBoardWidth()};
return (point.x_ < maxCoordinate) && (point.y_ < maxCoordinate);
}

Expand Down
4 changes: 1 addition & 3 deletions src/PointUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace point_utils
{
Point pointFromSigned(int x, int y);

bool isValidPoint(int x, int y, unsigned int objectSize);
bool isValidPoint(int x, int y, int objectSize);

bool isValidPoint(Point point);
}; // namespace point_utils
11 changes: 5 additions & 6 deletions src/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void Screen::init()
::al_set_window_title(::al_get_current_display(), "TankBle");
}

void Screen::drawText(unsigned int x, unsigned y, const std::string& text) const
void Screen::drawText(int x, int y, const std::string& text) const
{
const ALLEGRO_COLOR white{::al_map_rgb(255, 255, 255)};
::al_draw_text(font_, white, static_cast<float>(x), static_cast<float>(y),
Expand Down Expand Up @@ -82,15 +82,14 @@ void Screen::drawBackground(ResourceType resourceType) const
static_cast<float>(getWidth()), static_cast<float>(getHeight()), 0);
}

void Screen::drawScaledSquareBitmap(ResourceType resourceType, unsigned int x,
unsigned int y, unsigned int size) const
void Screen::drawScaledSquareBitmap(ResourceType resourceType, int x, int y,
int size) const
{
drawScaledBitmap(resourceType, x, y, size, size);
}

void Screen::drawScaledBitmap(ResourceType resourceType, unsigned int x,
unsigned int y, unsigned int width,
unsigned int height) const
void Screen::drawScaledBitmap(ResourceType resourceType, int x, int y,
int width, int height) const
{
ALLEGRO_BITMAP* bitmapToUse{resources_.getBitmap(resourceType)};
::al_draw_scaled_bitmap(
Expand Down
11 changes: 5 additions & 6 deletions src/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ class Screen

static void init();

void drawText(unsigned int x, unsigned y, const std::string& text) const;
void drawText(int x, int y, const std::string& text) const;

void drawTextWithBackground(int x, int y, const std::string& text) const;

void drawBackground(ResourceType resourceType) const;

void drawScaledSquareBitmap(ResourceType resourceType, unsigned int x,
unsigned int y, unsigned int size) const;
void drawScaledSquareBitmap(ResourceType resourceType, int x, int y,
int size) const;

void drawScaledBitmap(ResourceType resourceType, unsigned int x,
unsigned int y, unsigned int width,
unsigned int height) const;
void drawScaledBitmap(ResourceType resourceType, int x, int y, int width,
int height) const;

void drawScaledBitmapWithRotation(ResourceType resourceType, int x, int y,
int size, int degrees) const;
Expand Down

0 comments on commit 652742b

Please sign in to comment.