diff --git a/CMakeLists.txt b/CMakeLists.txt index 8524300509755cd22fc9218fc65ea27c0ee1a557..e3e750ca7777f582072fab0ec1d1db484a5069a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ add_executable(pac-man "source/Draw/Button.cpp" "source/Draw/MyFont.cpp" "source/Commands/ExitCommand.cpp" + "source/Maze_Content/Room.cpp" ) diff --git a/include/Commands/ExitCommand.h b/include/Commands/ExitCommand.h index d51d0ed40721b7319a50cf7112df94d7848fd0e1..bedffb302acd9c4778f2dc94130e53823216a59a 100644 --- a/include/Commands/ExitCommand.h +++ b/include/Commands/ExitCommand.h @@ -4,7 +4,7 @@ class ExitCommand: public ChangeStateCommand { public: - void execute() override; ///@todo + void execute() override; public: ExitCommand(IStateManager& state_manager); }; \ No newline at end of file diff --git a/include/config.h b/include/Config.h similarity index 93% rename from include/config.h rename to include/Config.h index ffdca333526186877bcffc1dba5d9fe905e27667..0c2cc149b1f48034794b045f393505b25ea28723 100644 --- a/include/config.h +++ b/include/Config.h @@ -23,7 +23,7 @@ namespace config { // const float EASY_GAME_ENEMY_RATIO = 0.0f; // const float MEDIUM_GAME_ENEMY_RATIO = 0.03f; // const float HARD_GAME_ENEMY_RATIO = 0.07f; -// const float ROOM_SIZE = 50; + const float ROOM_SIZE = 50; // const float GAME_ENEMY_SIZE = ROOM_SIZE * 0.7; // const float GAME_FOOD_SIZE = ROOM_SIZE * 0.2; // Пакмэн: @@ -42,8 +42,8 @@ namespace config { // const sf::Color GAME_COLOR_BACKGROUND_WIN{ 0, 255, 0 }; // const sf::Color GAME_COLOR_BACKGROUND_LOST{ 255, 0, 0 }; // const sf::Color GAME_COLOR_PACMAN{ 250, 150, 0 }; -// const sf::Color GAME_COLOR_ROOM{ 255, 255, 255 }; -// const sf::Color GAME_COLOR_WALL{ 0, 0, 0 }; + const sf::Color GAME_COLOR_ROOM{ 255, 255, 255 }; + const sf::Color GAME_COLOR_WALL{ 0, 0, 0 }; // const sf::Color GAME_FOOD_COLOR{ 0, 200, 100 }; // const sf::Color GAME_ENEMY_COLOR{ 255, 50, 0 }; } \ No newline at end of file diff --git a/include/Draw/Button.h b/include/Draw/Button.h index 573031eb5ca1097bfbd385886c2bda6465520a0e..c908ba8f9d4e800b32fdf1ad91cb550b5b0d9ce0 100644 --- a/include/Draw/Button.h +++ b/include/Draw/Button.h @@ -1,6 +1,6 @@ #pragma once -#include "config.h" +#include "Config.h" #include "IDrawable.h" #include "Commands/ISelectCommand.h" diff --git a/include/MazeContent/Maze.h b/include/MazeContent/Maze.h index 5fea69d0405c229915fb988d8be64e018a9f9d4e..a7f099c969c90cd2bf43f45c894fd58f05c95fab 100644 --- a/include/MazeContent/Maze.h +++ b/include/MazeContent/Maze.h @@ -4,7 +4,7 @@ class Maze: public IDrawable { public: - void draw_into(sf::RenderWindow& window) const override; ///@todo + void draw_into(sf::RenderWindow& window) const override; public: Maze(std::vector<std::unique_ptr<Room>>&& rooms): m_rooms(std::move(rooms)) {} private: diff --git a/include/MazeContent/Room.h b/include/MazeContent/Room.h index 3a8a9de71d8772eea94c82704332dfd6fc5a2246..5362f54bc57a01b147ec98ab0b77b27704608ca7 100644 --- a/include/MazeContent/Room.h +++ b/include/MazeContent/Room.h @@ -5,14 +5,14 @@ class Room: public IDrawable { public: enum Direction { INVALID = -1, LEFT, RIGHT, UP, DOWN }; - float get_size(); ///@todo - void set_position(sf::Vector2f); ///@todo - sf::Vector2f get_position(); ///@todo - void set_side(Direction side, IRoomSide prt_side); ///@todo - IRoomSide get_side(Direction side); ///@todo - Direction get_direction(IRoomSide prt_side); ///@todo + float get_size() const noexcept; + void set_position(const sf::Vector2f& pos) noexcept; + sf::Vector2f get_position() const noexcept; + void set_side(Direction side, std::shared_ptr<IRoomSide> ptr_side) noexcept; + std::shared_ptr<IRoomSide> get_side(Direction side); + Direction get_direction(IRoomSide* ptr_side); public: - Room(float size); ///@todo + Room(float size); public: std::array<std::shared_ptr<IRoomSide>, 4> m_sides; private: diff --git a/include/States/ExitState.h b/include/States/ExitState.h index dc8826242752a0b77f7a5219a9b56c5a5c9af152..92ccdadee6b8e755ffe1112afcf7fcf92faceb61 100644 --- a/include/States/ExitState.h +++ b/include/States/ExitState.h @@ -6,5 +6,5 @@ class ExitState: public IState { public: bool do_step() override { return false; } public: - ExitState(IStateManager& state_manager); + ExitState(IStateManager& state_manager): IState(state_manager) {}; }; \ No newline at end of file diff --git a/source/Draw/MyFont.cpp b/source/Draw/MyFont.cpp index 0389c99e0a5dc8154810b5fb9461e67eeaad551c..118d2140db65b73a74e52029f258401ba91d3373 100644 --- a/source/Draw/MyFont.cpp +++ b/source/Draw/MyFont.cpp @@ -1,4 +1,4 @@ -#include "config.h" +#include "Config.h" #include "Draw/MyFont.h" MyFont::MyFont() { diff --git a/source/Maze_Content/Room.cpp b/source/Maze_Content/Room.cpp new file mode 100644 index 0000000000000000000000000000000000000000..78c3aadfe4a52c9398e4413da2689081780902c2 --- /dev/null +++ b/source/Maze_Content/Room.cpp @@ -0,0 +1,38 @@ +#include "MazeContent/Room.h" +#include "Config.h" + +Room::Room(float size) : m_rectangle{ {size, size} } { + m_rectangle.setOrigin(m_rectangle.getSize() / 2.f); + m_rectangle.setFillColor(config::GAME_COLOR_ROOM); +} + +float Room::get_size() const noexcept { + return m_rectangle.getSize().x; +} + +void Room::set_position(const sf::Vector2f& pos) noexcept { + m_rectangle.setPosition(pos); +} + +sf::Vector2f Room::get_position() const noexcept { + return m_rectangle.getPosition(); +} + +void Room::set_side(Direction side, std::shared_ptr<IRoomSide> ptr_side) noexcept { + if (side == INVALID) + return; + m_sides.at(side) = std::move(ptr_side); + m_sides.at(side)->prepare_for_drawing(); +} + +std::shared_ptr<IRoomSide> Room::get_side(Direction side) { + return m_sides.at(side); +} + +Room::Direction Room::get_direction(IRoomSide* ptr_side) { + if (m_sides.at(LEFT).get() == ptr_side) return LEFT; + else if (m_sides.at(RIGHT).get() == ptr_side) return RIGHT; + else if (m_sides.at(UP).get() == ptr_side) return UP; + else if (m_sides.at(DOWN).get() == ptr_side) return DOWN; + return INVALID; +} \ No newline at end of file diff --git a/source/Maze_Content/Wall.cpp b/source/Maze_Content/Wall.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cfd301010f93d3eacab3afad0052d2b8e4231f75 --- /dev/null +++ b/source/Maze_Content/Wall.cpp @@ -0,0 +1,59 @@ +#include "MazeContent/Wall.h" +#include "Config.h" + +//void Wall::prepare_for_drawing() { +// sf::Vector2f pos = m_room.get_position(); +// float size = config::ROOM_SIZE; +// +// switch (m_room.get_direction(this)) { +// case Room::UP: +// m_line[0] = sf::Vertex({ pos.x - size / 2, pos.y - size / 2 }, config::GAME_COLOR_WALL); +// m_line[1] = sf::Vertex({ pos.x + size / 2, pos.y - size / 2 }, config::GAME_COLOR_WALL); +// break; +// +// case Room::RIGHT: +// m_line[0] = sf::Vertex({ pos.x + size / 2, pos.y - size / 2 }, config::GAME_COLOR_WALL); +// m_line[1] = sf::Vertex({ pos.x + size / 2, pos.y + size / 2 }, config::GAME_COLOR_WALL); +// break; +// +// case Room::DOWN: +// m_line[0] = sf::Vertex({ pos.x + size / 2, pos.y + size / 2 }, config::GAME_COLOR_WALL); +// m_line[1] = sf::Vertex({ pos.x - size / 2, pos.y + size / 2 }, config::GAME_COLOR_WALL); +// break; +// +// case Room::LEFT: +// m_line[0] = sf::Vertex({ pos.x - size / 2, pos.y + size / 2 }, config::GAME_COLOR_WALL); +// m_line[1] = sf::Vertex({ pos.x - size / 2, pos.y - size / 2 }, config::GAME_COLOR_WALL); +// break; +// +// default: +// throw std::runtime_error("There is invalid side in some room"); +// } +//} +// +//void Wall::prepare_for_drawing() { +// if (m_room.get_direction(this) == Room::LEFT) { +// m_line[0] = sf::Vertex{ sf::Vector2f(m_room.get_position().x - m_room.get_size() / 2, +// m_room.get_position().y - m_room.get_size() / 2), config::GAME_COLOR_WALL }; +// m_line[1] = sf::Vertex{ sf::Vector2f(m_room.get_position().x - m_room.get_size() / 2, +// m_room.get_position().y + m_room.get_size() / 2), config::GAME_COLOR_WALL }; +// } +// else if (m_room.get_direction(this) == Room::RIGHT) { +// m_line[0] = sf::Vertex{ sf::Vector2f(m_room.get_position().x + m_room.get_size() / 2, +// m_room.get_position().y - m_room.get_size() / 2), config::GAME_COLOR_WALL }; +// m_line[1] = sf::Vertex{ sf::Vector2f(m_room.get_position().x + m_room.get_size() / 2, +// m_room.get_position().y + m_room.get_size() / 2), config::GAME_COLOR_WALL }; +// } +// else if (m_room.get_direction(this) == Room::UP) { +// m_line[0] = sf::Vertex{ sf::Vector2f( m_room.get_position().x - m_room.get_size() / 2, +// m_room.get_position().y - m_room.get_size() / 2 ), config::GAME_COLOR_WALL }; +// m_line[1] = sf::Vertex{ sf::Vector2f( m_room.get_position().x + m_room.get_size() / 2, +// m_room.get_position().y - m_room.get_size() / 2), config::GAME_COLOR_WALL }; +// } +// else if (m_room.get_direction(this) == Room::DOWN) { +// m_line[0] = sf::Vertex{ sf::Vector2f(m_room.get_position().x - m_room.get_size() / 2, +// m_room.get_position().y + m_room.get_size() / 2), config::GAME_COLOR_WALL }; +// m_line[1] = sf::Vertex{ sf::Vector2f(m_room.get_position().x + m_room.get_size() / 2, +// m_room.get_position().y + m_room.get_size() / 2), config::GAME_COLOR_WALL }; +// } +//} \ No newline at end of file