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

Made Teleport and started work of BonusBuilder

parent a8f3995d
No related merge requests found
Showing with 247 additions and 18 deletions
+247 -18
......@@ -23,6 +23,7 @@ add_executable(pac-man
"source/MazeContent/Buildings/Room.cpp"
"source/MazeContent/Buildings/Wall.cpp"
"source/MazeContent/Buildings/Pass.cpp"
"source/MazeContent/Buildings/Teleport.cpp"
"source/MazeContent/Entities/IEntity.cpp"
"source/MazeContent/Entities/Pacman.cpp"
"source/MazeContent/Entities/StaticEntities/Food.cpp"
......@@ -33,6 +34,7 @@ add_executable(pac-man
"source/Builder/Builders/CommonBuilder.cpp"
"source/Builder/Builders/SimpleBuilder.cpp"
"source/Builder/Builders/ComplexBuilder.cpp"
"source/Builder/Builders/BonusBuilder.cpp"
"source/Events/DeleteStaticEntity.cpp"
"source/Events/LostGame.cpp"
)
......
File added
#pragma once
#include "Builder/Builders/CommonBuilder.h"
class BonusBuider: public CommonBuilder {
public:
void create_rooms() override; ///@todo
void set_rooms_sides() override; ///@todo
public:
BonusBuider(float width, float height, float room_size);
};
\ No newline at end of file
......@@ -6,9 +6,15 @@ namespace config {
const unsigned int FRAME_RATE_LIMIT = 60;
// Меню:
const sf::Vector2f BUTTON_SIZE = { 250, 100 };
const size_t BUTTON_FONT_SIZE = static_cast<size_t>(BUTTON_SIZE.y / 1.5f);
const size_t BUTTON_FONT_SIZE_BASE = static_cast<size_t>(BUTTON_SIZE.y / 1.5f);
const size_t BUTTON_FONT_SIZE_VARIANT_1 = static_cast<size_t>(BUTTON_SIZE.y / 1.80f);
const size_t BUTTON_FONT_SIZE_VARIANT_2 = static_cast<size_t>(BUTTON_SIZE.y / 2.2f);
const size_t BUTTON_FONT_SIZE = static_cast<size_t>(BUTTON_SIZE.y / 2.1f);
const float BUTTON_FRAME_THICKNESS = 2.0f;
const char FONT_FILE[] = "Calibri-Light.ttf";
const char FONT_FILE_BASE[] = "Calibri-Light.ttf";
const char FONT_FILE_VARIANT_1[] = "android2.ttf";
const char FONT_FILE_VARIANT_2[] = "Oxygene1_RUS_by_KanycTa.ttf";
const char FONT_FILE[] = "Font Over.otf";
const char SELECT_LEVEL_TITLE[] = "Select Level";
const sf::VideoMode SELECT_LEVEL_VIDEO_MODE{ 400, 600 };
const char BUTTON_TEXT_EASY[] = "Easy";
......@@ -26,7 +32,7 @@ namespace config {
const float MEDIUM_GAME_ENEMY_RATIO = 0.03f;
const float HARD_GAME_ENEMY_RATIO = 0.05f;
const float ROOM_SIZE_EASY = 140;
const float ROOM_SIZE_MEADIUM = 70;
const float ROOM_SIZE_MEADIUM = 50;
const float ROOM_SIZE = 50;
const float GAME_ENEMY_SIZE = ROOM_SIZE * 0.7;
const float GAME_FOOD_SIZE = ROOM_SIZE * 0.2;
......@@ -37,17 +43,29 @@ namespace config {
const sf::Keyboard::Key KEY_UP = sf::Keyboard::W;
const sf::Keyboard::Key KEY_DOWN = sf::Keyboard::S;
// Цвета:
const sf::Color BUTTON_COLOR_TEXT{ 0, 0, 0 };
const sf::Color BUTTON_COLOR_FILL{ 180, 180, 180 };
const sf::Color BUTTON_COLOR_SELECTION{ 255, 180, 180 };
const sf::Color BUTTON_COLOR_FRAME{ 0, 0, 0 };
const sf::Color SELECT_LEVEL_BACKGROUND_COLOR{ 230,230,230 };
const sf::Color GAME_COLOR_BACKGROUND_INGAME{ 230,230,230 };
const sf::Color BUTTON_COLOR_TEXT_BASE{ 0, 0, 0 };
const sf::Color BUTTON_COLOR_TEXT{ 37, 35, 35 };
const sf::Color BUTTON_COLOR_FILL_BASE{ 180, 180, 180 };
const sf::Color BUTTON_COLOR_FILL{ 181,111,217 };
const sf::Color BUTTON_COLOR_SELECTION_BASE{ 255, 180, 180 };
const sf::Color BUTTON_COLOR_SELECTION{ 202,151,238 };
const sf::Color BUTTON_COLOR_FRAME_BASE{ 0, 0, 0 };
const sf::Color BUTTON_COLOR_FRAME{ 250, 166, 38 };
const sf::Color SELECT_LEVEL_BACKGROUND_COLOR_BASE{ 230,230,230 };
const sf::Color SELECT_LEVEL_BACKGROUND_COLOR{ 84,147,255 };
const sf::Color GAME_COLOR_BACKGROUND_INGAME_BASE{ 230,230,230 };
const sf::Color GAME_COLOR_BACKGROUND_INGAME{ 84,147,255 };
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_BASE{ 250, 150, 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_FOOD_COLOR{ 0, 200, 100 };
const sf::Color GAME_ENEMY_COLOR{ 255, 50, 0 };
const sf::Color GAME_COLOR_ROOM_BASE{ 255, 255, 255 };
const sf::Color GAME_COLOR_ROOM{ 230, 239, 233 };
const sf::Color GAME_COLOR_WALL_BASE{ 0, 0, 0 };
const sf::Color GAME_COLOR_WALL{ 250, 166, 38 };
const sf::Color GAME_COLOR_TELEPORT{ 255, 0, 0 };
const sf::Color GAME_FOOD_COLOR_BASE{ 0, 200, 100 };
const sf::Color GAME_FOOD_COLOR{ 83, 200, 108 };
const sf::Color GAME_ENEMY_COLOR_BASE{ 255, 50, 0 };
const sf::Color GAME_ENEMY_COLOR{ 255, 62, 65 };
}
\ No newline at end of file
#pragma once
#include "MazeContent/Buildings/Room.h"
class Teleport : public IRoomSide {
public:
void enter(IEntity* entity) override;
void prepare_for_drawing() override;
void draw_into(sf::RenderWindow& window) const override;
public:
Teleport(std::vector<std::unique_ptr<Room>> rooms) : m_rooms(std::move(rooms)) {}
private:
std::vector<std::unique_ptr<Room>> m_rooms;
std::vector<std::array<sf::Vertex, 2>> lines;
};
\ No newline at end of file
#include "Builder/Builders/BonusBuilder.h"
#include "MazeContent/Buildings/Wall.h"
#include "MazeContent/Buildings/Pass.h"
#include "MazeContent/Buildings/Teleport.h"
#include "iostream"
BonusBuider::BonusBuider(float width, float height, float room_size):
CommonBuilder(width, height, room_size) {}
void BonusBuider::create_rooms() {
size_t rows = static_cast<int>(m_height / m_room_size) % 2 == 0 ? m_height / m_room_size - 1 : m_height / m_room_size;
size_t cols = static_cast<int>(m_width / m_room_size) % 2 == 0 ? m_width / m_room_size - 1 : m_width / m_room_size;
sf::Vector2f top_left_origin_pos{ (m_width - cols * m_room_size) / 2 + m_room_size / 2,
(m_height - rows * m_room_size) / 2 + m_room_size / 2 };
for (size_t i = 0; i < rows; ++i) {
std::vector<std::unique_ptr<Room>> row;
for (size_t j = 0; j < cols; ++j) {
// auto room = std::make_unique<Room>(m_room_size);
if (i % 2 == 1 || j % 2 == 1) {
auto room = std::make_unique<Room>(m_room_size);
room->set_position(sf::Vector2f{ top_left_origin_pos.x + j * m_room_size,
top_left_origin_pos.y + i * m_room_size });
row.emplace_back(std::move(room));
}
}
m_rooms.emplace_back(std::move(row));
}
}
void BonusBuider::set_rooms_sides() {
for (size_t i = 0; i < m_rooms.size(); ++i) {
for (size_t j = 0; j < m_rooms.at(i).size(); ++j) {
if (i % 2 == 0) {
auto left_wall_1 = std::make_shared<Wall>(*m_rooms[i][j]);
auto right_wall_1 = std::make_shared<Wall>(*m_rooms[i][j]);
m_rooms[i][j]->set_side(Room::LEFT, left_wall_1);
m_rooms[i][j]->set_side(Room::RIGHT, right_wall_1);
if (i == 0) {
auto up_wall_1 = std::make_shared<Wall>(*m_rooms[i][j]);
auto my_down_pass = std::make_shared<Pass>(*m_rooms[i][j], *m_rooms[i + 1][2 * j + 1]);
auto neighbour_down_pass = std::make_shared<Pass>(*m_rooms[i + 1][2 * j + 1], *m_rooms[i + 2][j]);
m_rooms[i][j]->set_side(Room::UP, up_wall_1);
m_rooms[i][j]->set_side(Room::DOWN, my_down_pass);
m_rooms[i + 1][2 * j + 1]->set_side(Room::UP, my_down_pass);
m_rooms[i + 1][2 * j + 1]->set_side(Room::DOWN, neighbour_down_pass);
m_rooms[i + 2][j]->set_side(Room::UP, neighbour_down_pass);
} else if (i == m_rooms.size() - 1) {
auto down_wall_1 = std::make_shared<Wall>(*m_rooms[i][j]);
auto my_up_pass = std::make_shared<Pass>(*m_rooms[i][j], *m_rooms[i - 1][2 * j + 1]);
auto neighbour_up_pass = std::make_shared<Pass>(*m_rooms[i - 1][2 * j + 1], *m_rooms[i - 2][j]);
m_rooms[i][j]->set_side(Room::DOWN, down_wall_1);
m_rooms[i][j]->set_side(Room::UP, my_up_pass);
m_rooms[i - 1][2 * j + 1]->set_side(Room::DOWN, my_up_pass);
m_rooms[i - 1][2 * j + 1]->set_side(Room::UP, neighbour_up_pass);
m_rooms[i - 2][j]->set_side(Room::DOWN, neighbour_up_pass);
}
}
else if (j % 2 == 0) {
auto up_wall_2 = std::make_shared<Wall>(*m_rooms[i][j]);
auto down_wall_2 = std::make_shared<Wall>(*m_rooms[i][j]);
m_rooms[i][j]->set_side(Room::UP, up_wall_2);
m_rooms[i][j]->set_side(Room::DOWN, down_wall_2);
if (j == 0) {
auto left_wall_2 = std::make_shared<Wall>(*m_rooms[i][j]);
m_rooms[i][j]->set_side(Room::LEFT, left_wall_2);
}
else if (j == m_rooms.at(i).size() - 1) {
auto right_wall_2 = std::make_shared<Wall>(*m_rooms[i][j]);
m_rooms[i][j]->set_side(Room::RIGHT, right_wall_2);
}
}
else if (j % 2 == 1) {
auto left_pass = std::make_shared<Pass>(*m_rooms[i][j], *m_rooms[i][j - 1]);
auto right_pass = std::make_shared<Pass>(*m_rooms[i][j], *m_rooms[i][j + 1]);
m_rooms[i][j]->set_side(Room::LEFT, left_pass);
m_rooms[i][j - 1]->set_side(Room::RIGHT, left_pass);
m_rooms[i][j]->set_side(Room::RIGHT, right_pass);
m_rooms[i][j + 1]->set_side(Room::LEFT, right_pass);
if (!(i == 1 || i == m_rooms.size() - 2)) {
auto up_pass = std::make_shared<Pass>(*m_rooms[i][j], *m_rooms[i - 1][(j -1) / 2]);
auto down_pass = std::make_shared<Pass>(*m_rooms[i][j], *m_rooms[i + 1][(j -1) / 2]);
m_rooms[i][j]->set_side(Room::UP, up_pass);
m_rooms[i - 1][(j -1) / 2]->set_side(Room::DOWN, up_pass);
m_rooms[i][j]->set_side(Room::DOWN, down_pass);
m_rooms[i + 1][(j -1) / 2]->set_side(Room::UP, down_pass);
}
}
}
}
}
\ No newline at end of file
......@@ -33,6 +33,14 @@ Menu::Menu(IStateManager& state_manager) {
config::HARD_GAME_TITLE,
config::HARD_GAME_ENEMY_RATIO);
// auto bonus_director = std::make_unique<GameBuilderDirector>(
// std::make_unique<ComplexBuilder>(
// config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
// config::ROOM_SIZE),
// config::GAME_VIDEO_MODE,
// config::HARD_GAME_TITLE,
// config::HARD_GAME_ENEMY_RATIO);
auto easy_command = std::make_unique<GameCommand>(state_manager, std::move(easy_director));
auto medium_command = std::make_unique<GameCommand>(state_manager, std::move(medium_director));
auto hard_command = std::make_unique<GameCommand>(state_manager, std::move(hard_director));
......
......@@ -3,10 +3,8 @@
#include "Config.h"
void Pass::enter(IEntity* entity) {
if (entity->get_location() == &m_room1) {
if (entity->get_location() == &m_room1)
entity->set_location(&m_room2);
}
else {
else
entity->set_location(&m_room1);
}
}
\ No newline at end of file
#include "MazeContent/Buildings/Teleport.h"
#include "MazeContent/Entities/IEntity.h"
#include "Config.h"
void Teleport::prepare_for_drawing() {
for (size_t i = 0; i < m_rooms.size(); ++i) {
sf::Vector2f pos = m_rooms.at(i)->get_position();
switch (m_rooms.at(i)->get_direction(this)) {
case Room::LEFT:
lines.emplace_back(std::array<sf::Vertex, 2>{
sf::Vertex{sf::Vector2f(pos.x - m_rooms.at(i)->get_size() / 2,
pos.y - m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT},
sf::Vertex{sf::Vector2f(pos.x - m_rooms.at(i)->get_size() / 2,
pos.y + m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT}
});
//
// m_line[0] = sf::Vertex{sf::Vector2f(pos.x - m_rooms.at(i)->get_size() / 2,
// pos.y - m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT};
// m_line[1] = sf::Vertex{sf::Vector2f(pos.x - m_rooms.at(i)->get_size() / 2,
// pos.y + m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT};
break;
case Room::RIGHT:
lines.emplace_back(std::array<sf::Vertex, 2>{
sf::Vertex{sf::Vector2f(pos.x + m_rooms.at(i)->get_size() / 2,
pos.y - m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT},
sf::Vertex{sf::Vector2f(pos.x + m_rooms.at(i)->get_size() / 2,
pos.y + m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT}
});
// m_line[0] = sf::Vertex{sf::Vector2f(pos.x + m_rooms.at(i)->get_size() / 2,
// pos.y - m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT};
// m_line[1] = sf::Vertex{sf::Vector2f(pos.x + m_rooms.at(i)->get_size() / 2,
// pos.y + m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT};
break;
case Room::UP:
lines.emplace_back(std::array<sf::Vertex, 2>{
sf::Vertex{sf::Vector2f(pos.x - m_rooms.at(i)->get_size() / 2,
pos.y - m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT},
sf::Vertex{sf::Vector2f(pos.x + m_rooms.at(i)->get_size() / 2,
pos.y - m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT}
});
// m_line[0] = sf::Vertex{sf::Vector2f(pos.x - m_rooms.at(i)->get_size() / 2,
// pos.y - m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT};
// m_line[1] = sf::Vertex{sf::Vector2f(pos.x + m_rooms.at(i)->get_size() / 2,
// pos.y - m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT};
break;
case Room::DOWN:
lines.emplace_back(std::array<sf::Vertex, 2>{
sf::Vertex{sf::Vector2f(pos.x - m_rooms.at(i)->get_size() / 2,
pos.y + m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT},
sf::Vertex{sf::Vector2f(pos.x + m_rooms.at(i)->get_size() / 2,
pos.y + m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT}
});
// m_line[0] = sf::Vertex{sf::Vector2f(pos.x - m_rooms.at(i)->get_size() / 2,
// pos.y + m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT};
// m_line[1] = sf::Vertex{sf::Vector2f(pos.x + m_rooms.at(i)->get_size() / 2,
// pos.y + m_rooms.at(i)->get_size() / 2), config::GAME_COLOR_TELEPORT};
break;
default:
throw std::runtime_error("Invalid side in the room!");
}
}
}
void Teleport::enter(IEntity* entity) {
size_t number = m_rooms.size();
for (size_t i = 0; i < number; ++i) {
if (entity->get_location() == m_rooms.at(i).get())
entity->set_location(m_rooms.at(rand() % number).get());
}
}
void Teleport::draw_into(sf::RenderWindow& window) const {
for (const auto& line : lines)
window.draw(line.data(), 2, sf::Lines);
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ void Wall::prepare_for_drawing() {
break;
default:
throw std::runtime_error("Invvalid side in the room!");
throw std::runtime_error("Invalid side in the room!");
}
}
......
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