From 652742b8a947e4a5c745c53a7acd621c7404e76c Mon Sep 17 00:00:00 2001 From: przemek83 <4788832+przemek83@users.noreply.github.com> Date: Fri, 13 Sep 2024 09:20:31 +0200 Subject: [PATCH] Remove some unsignedness from ints. --- src/Bullet.cpp | 2 +- src/PointUtils.cpp | 13 ++++--------- src/PointUtils.h | 4 +--- src/Screen.cpp | 11 +++++------ src/Screen.h | 11 +++++------ 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/Bullet.cpp b/src/Bullet.cpp index a3e06d2..56004e4 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -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; } diff --git a/src/PointUtils.cpp b/src/PointUtils.cpp index aade8a8..a9ff90b 100644 --- a/src/PointUtils.cpp +++ b/src/PointUtils.cpp @@ -4,21 +4,16 @@ namespace point_utils { -Point pointFromSigned(int x, int y) +bool isValidPoint(int x, int y, int objectSize) { - return {static_cast(x), static_cast(y)}; -} - -bool isValidPoint(int x, int y, unsigned int objectSize) -{ - const int maxCoordinate{static_cast( - 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); } diff --git a/src/PointUtils.h b/src/PointUtils.h index c32eda9..b8b3735 100644 --- a/src/PointUtils.h +++ b/src/PointUtils.h @@ -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 diff --git a/src/Screen.cpp b/src/Screen.cpp index 7479e03..0e763d3 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -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(x), static_cast(y), @@ -82,15 +82,14 @@ void Screen::drawBackground(ResourceType resourceType) const static_cast(getWidth()), static_cast(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( diff --git a/src/Screen.h b/src/Screen.h index 7fcc61e..1c40751 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -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;