Commit 581a115a authored by Сулимов Игорь Андреевич's avatar Сулимов Игорь Андреевич
Browse files

Completed Room

parent db89415e
No related merge requests found
Showing with 113 additions and 15 deletions
+113 -15
......@@ -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"
)
......
......@@ -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
......@@ -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
#pragma once
#include "config.h"
#include "Config.h"
#include "IDrawable.h"
#include "Commands/ISelectCommand.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:
......
......@@ -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:
......
......@@ -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
#include "config.h"
#include "Config.h"
#include "Draw/MyFont.h"
MyFont::MyFont() {
......
#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
#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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment