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 a346fcb commit 359a139
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 47 deletions.
16 changes: 8 additions & 8 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class Config

unsigned int getFps() const;
unsigned int getTileCount() const { return tileCount_; }
unsigned int getTileSize() const { return tileSize_; }
int getTileSize() const { return tileSize_; }
unsigned int getBulletSize() const { return bulletSize_; }
unsigned int getBoardWidth() const { return boardWidth_; }
unsigned int getBoardHeight() const { return boardHeight_; }
unsigned int getSatusWidth() const { return statusWidth_; }
int getBoardWidth() const { return boardWidth_; }
int getBoardHeight() const { return boardHeight_; }
int getSatusWidth() const { return statusWidth_; }
float getSpeedFactor() const { return speedFactor_; }

static unsigned int getRandomSeed();
Expand All @@ -47,11 +47,11 @@ class Config
const unsigned int defaultFps_{static_cast<unsigned int>(FPS::FPS_30)};
const unsigned int tileCount_{20};
static constexpr unsigned int defaultTileSize_{30};
unsigned int tileSize_{defaultTileSize_};
int tileSize_{defaultTileSize_};
unsigned int bulletSize_{};
unsigned int boardWidth_{};
unsigned int boardHeight_{};
unsigned int statusWidth_{};
int boardWidth_{};
int boardHeight_{};
int statusWidth_{};
float speedFactor_{};
const std::chrono::seconds fireDelay_{2};
};
4 changes: 2 additions & 2 deletions src/Drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Drawable::Drawable(Point point) : point_(point) {}

Drawable::~Drawable() = default;

void Drawable::setX(unsigned int x) { point_.x_ = x; }
void Drawable::setX(int x) { point_.x_ = x; }

void Drawable::setY(unsigned int y) { point_.y_ = y; }
void Drawable::setY(int y) { point_.y_ = y; }

void Drawable::setLocation(Point point) { point_ = point; }

Expand Down
8 changes: 4 additions & 4 deletions src/Drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class Drawable
virtual ResourceType getResourceType() const = 0;
virtual Point getCenter() const = 0;

void setX(unsigned int x);
void setY(unsigned int y);
void setX(int x);
void setY(int y);

unsigned int getX() const { return point_.x_; }
unsigned int getY() const { return point_.y_; }
int getX() const { return point_.x_; }
int getY() const { return point_.y_; }

void setLocation(Point point);
Point getLocation() const;
Expand Down
4 changes: 2 additions & 2 deletions src/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

struct Point
{
unsigned int x_;
unsigned int y_;
int x_;
int y_;
};

inline bool operator==(const Point& lhs, const Point& rhs)
Expand Down
8 changes: 3 additions & 5 deletions src/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ void Screen::drawText(unsigned int x, unsigned y, const std::string& text) const
ALLEGRO_ALIGN_CENTER, text.c_str());
}

void Screen::drawTextWithBackground(unsigned int x, unsigned int y,
const std::string& text) const
void Screen::drawTextWithBackground(int x, int y, const std::string& text) const
{
const unsigned int margin{10};
const int margin{10};
const float radius{10};
const unsigned int height{
static_cast<unsigned int>(::al_get_font_line_height(font_))};
const int height{::al_get_font_line_height(font_)};
const float width{
static_cast<float>(::al_get_text_width(font_, text.c_str()))};
const float halfOfWidth{width / 2.F};
Expand Down
3 changes: 1 addition & 2 deletions src/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class Screen

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

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

void drawBackground(ResourceType resourceType) const;

Expand Down
12 changes: 3 additions & 9 deletions src/Status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Status::update(TankStats newStats, const Screen& screen)

void Status::draw(const Screen& screen) const
{
const unsigned int spacer{getHeight() / 5};
const int spacer{getHeight() / 5};
screen.drawTextWithBackground(getCenter().x_, spacer * 1,
"Lives: " + std::to_string(stats_.lives_));
screen.drawTextWithBackground(getCenter().x_, spacer * 2,
Expand All @@ -41,12 +41,6 @@ ResourceType Status::getResourceType() const
return ResourceType::BACKGROUND;
}

unsigned int Status::getHeight()
{
return Config::getInstance().getBoardHeight();
}
int Status::getHeight() { return Config::getInstance().getBoardHeight(); }

unsigned int Status::getWeidth()
{
return Config::getInstance().getSatusWidth();
}
int Status::getWeidth() { return Config::getInstance().getSatusWidth(); }
4 changes: 2 additions & 2 deletions src/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Status : public Drawable
ResourceType getResourceType() const override;

private:
static unsigned int getHeight();
static unsigned int getWeidth();
static int getHeight();
static int getWeidth();

TankStats stats_{};
};
10 changes: 5 additions & 5 deletions src/Tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool Tank::canFire(TimePoint currentTime) const
Config::getInstance().getFireDelay();
}

bool Tank::hit(unsigned int power)
bool Tank::hit(int power)
{
if (power > stats_.shield_)
stats_.shield_ = 0;
Expand Down Expand Up @@ -181,12 +181,12 @@ void Tank::respawn()
direction_ = (isPlayerControlled() ? Direction::UP : Direction::DOWN);
}

unsigned int Tank::getCalculatedSpeed(float speedFactor) const
int Tank::getCalculatedSpeed(float speedFactor) const
{
const unsigned int tileSize{Config::getInstance().getTileSize()};
const int tileSize{Config::getInstance().getTileSize()};
float speed{std::round(static_cast<float>(stats_.speed_) * speedFactor)};
if (!isPlayerControlled())
while ((speed >= 1) && tileSize % static_cast<unsigned int>(speed) != 0)
while ((speed >= 1) && ((tileSize % static_cast<int>(speed)) != 0))
speed -= 1;
return std::max(1U, static_cast<unsigned int>(speed));
return std::max(1, static_cast<int>(speed));
}
16 changes: 8 additions & 8 deletions src/Tank.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Tank : public Drawable
Bullet fire(TimePoint currentTime);
bool canFire(TimePoint currentTime) const;

bool hit(unsigned int power);
bool hit(int power);
void move(Point point);
bool isPlayerControlled() const;

Expand All @@ -51,12 +51,12 @@ class Tank : public Drawable
void addLife();
void respawn();

unsigned int getCalculatedSpeed(float speedFactor) const;
int getCalculatedSpeed(float speedFactor) const;

static const unsigned int BASIC_ATTACK{1};
static const unsigned int BASIC_HEALTH{1};
static const unsigned int BASIC_SPEED{2};
static const unsigned int SINGLE_LIFE{1};
static const int BASIC_ATTACK{1};
static const int BASIC_HEALTH{1};
static const int BASIC_SPEED{2};
static const int SINGLE_LIFE{1};

std::map<TankType, TankStats> typesStats_{
{TankType::PLAYER_TIER_1,
Expand All @@ -82,6 +82,6 @@ class Tank : public Drawable
TankType type_{};
TankStats stats_{};
TimePoint lastFire_{TimePoint()};
const unsigned int initialX_{};
const unsigned int initialY_{};
const int initialX_{};
const int initialY_{};
};

0 comments on commit 359a139

Please sign in to comment.