Fix syntax errors and warnings

master
NaiJi ✨ 4 years ago
parent f24193b309
commit fbf18501d7

Binary file not shown.

Binary file not shown.

@ -10,6 +10,9 @@ Cell::Cell(coordinate cell_x, coordinate cell_y, const sf::Color &color) :
cell_color(color)
{}
Cell::~Cell()
{}
sf::Color Cell::color() const noexcept
{
return cell_color;

@ -24,9 +24,9 @@ public:
coordinate cell_y = 0,
const sf::Color &color = sf::Color::White);
virtual ~Cell() = 0;
virtual ~Cell() override;
inline sf::Color color() const noexcept;
sf::Color color() const noexcept;
/// Determine if Hero can move onto this cell or not
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) = 0;

@ -0,0 +1,31 @@
#include "entity.h"
Entity::Entity(coordinate _x, coordinate _y) :
pos_x(_x), pos_y(_y)
{}
Entity::~Entity()
{}
/// Get current Entity position
void Entity::position(coordinate &x, coordinate &y) const noexcept
{
x = pos_x;
y = pos_y;
}
void Entity::setPosition(coordinate x, coordinate y)
{
pos_x = x;
pos_y = y;
}
coordinate Entity::x() const noexcept
{
return pos_x;
}
coordinate Entity::y() const noexcept
{
return pos_y;
}

@ -10,37 +10,21 @@ protected:
coordinate pos_x, pos_y;
public:
Entity(coordinate _x = 0, coordinate _y = 0) :
pos_x(_x), pos_y(_y)
{}
Entity(coordinate _x = 0, coordinate _y = 0);
virtual ~Entity() = 0;
/// Get current Entity position
void position(coordinate &x, coordinate &y) const noexcept
{
x = pos_x;
y = pos_y;
}
void position(coordinate &x, coordinate &y) const noexcept;
/// Set Entity position explicitly
void setPosition(coordinate x, coordinate y)
{
pos_x = x;
pos_y = y;
}
void setPosition(coordinate x, coordinate y);
/// Get current x of the Entity position
coordinate x() const noexcept
{
return pos_x;
}
coordinate x() const noexcept;
/// Get current y of the Entity position
coordinate y() const noexcept
{
return pos_y;
}
coordinate y() const noexcept;
};
#endif // ENTITY_H

@ -113,7 +113,7 @@ void Game::renderMap()
{
const Map &map = level->mapArray();
coordinate painter_x = 0, painter_y = 0;
float painter_x = 0, painter_y = 0;
// Brush for cell sprites
sf::RectangleShape rectangle_brush;
@ -157,7 +157,7 @@ void Game::renderMap()
// Place the hero sprite
rectangle_brush.setFillColor(sf::Color::White);
rectangle_brush.setPosition(hero_x * cell_length, hero_y * cell_length);
rectangle_brush.setPosition(static_cast<float>(hero_x) * cell_length, static_cast<float>(hero_y) * cell_length);
main_window.draw(rectangle_brush);
main_window.draw(text);
}
@ -177,6 +177,7 @@ void Game::loadLevel(int level_index)
// Hardcoding is temporary!
hero->setPosition(1, 1);
hero->setCharges(2);
map[0][0] = std::make_unique<WallCell>(0, 0);
map[0][1] = std::make_unique<WallCell>(0, 1);
map[1][0] = std::make_unique<WallCell>(1, 0);

@ -2,7 +2,8 @@
Hero::Hero(coordinate position_x, coordinate position_y, int initial_charges) :
Entity(position_x, position_y),
hero_charges(initial_charges)
hero_charges(initial_charges),
on_exit(false)
{}
void Hero::refillCharges(int append_charges)

@ -3,8 +3,11 @@ CONFIG += c++17
CONFIG -= console app_bundle
CONFIG -= qt
QMAKE_CXXFLAGS = -Wall -Werror -Wextra -Wpedantic -Wconversion -std=c++17 -O2 -g
SOURCES += \
cell.cpp \
entity.cpp \
game.cpp \
hero.cpp \
level.cpp \

Loading…
Cancel
Save