diff --git a/build-debug/sfml-test b/build-debug/sfml-test index 03aef78..8ebb7db 100755 Binary files a/build-debug/sfml-test and b/build-debug/sfml-test differ diff --git a/build-release/sfml-test b/build-release/sfml-test index d939e56..c77b482 100755 Binary files a/build-release/sfml-test and b/build-release/sfml-test differ diff --git a/src/cell.cpp b/src/cell.cpp index ca76a85..20e80a3 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -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; diff --git a/src/cell.h b/src/cell.h index 9500939..3d6899f 100644 --- a/src/cell.h +++ b/src/cell.h @@ -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; diff --git a/src/entity.cpp b/src/entity.cpp new file mode 100644 index 0000000..33eeb7a --- /dev/null +++ b/src/entity.cpp @@ -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; +} diff --git a/src/entity.h b/src/entity.h index cc69958..f6dda32 100644 --- a/src/entity.h +++ b/src/entity.h @@ -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 diff --git a/src/game.cpp b/src/game.cpp index 4dab395..4e63e0d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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(hero_x) * cell_length, static_cast(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(0, 0); map[0][1] = std::make_unique(0, 1); map[1][0] = std::make_unique(1, 0); diff --git a/src/hero.cpp b/src/hero.cpp index 373590a..6f6b6ec 100644 --- a/src/hero.cpp +++ b/src/hero.cpp @@ -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) diff --git a/src/sfml-test.pro b/src/sfml-test.pro index 5a69dba..16853d5 100644 --- a/src/sfml-test.pro +++ b/src/sfml-test.pro @@ -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 \