From 36f159c33c52820fecea5e51ee18fbf3d5e7e5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B2=D0=B4=D0=B5=D0=B5=D0=B2=20=D0=95=D0=B2=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= <evavdeev@edu.hse.ru> Date: Fri, 21 Mar 2025 17:21:21 +0300 Subject: [PATCH] fireballs have flight direction --- source/Builder/Builders.cpp | 102 ++++++++++++++++++------------------ source/Config/Config.h | 4 +- source/Draw/Texture.cpp | 23 +++++++- source/Draw/Texture.h | 12 ++++- source/Game/IEntity.cpp | 2 +- source/Game/Pacman.cpp | 8 ++- source/Game/Pacman.h | 10 ++-- source/Maze/Maze.cpp | 10 ++-- source/Maze/Maze.h | 2 +- source/State/States.cpp | 8 +-- source/main.cpp | 51 ++++-------------- 11 files changed, 117 insertions(+), 115 deletions(-) diff --git a/source/Builder/Builders.cpp b/source/Builder/Builders.cpp index 21a227a..8c44667 100644 --- a/source/Builder/Builders.cpp +++ b/source/Builder/Builders.cpp @@ -2,7 +2,7 @@ #include <iostream> - +#include "../Config/Config.h" GameBuilderDirector::GameBuilderDirector(std::unique_ptr<IGameBuilder>&& ptr_builder, const sf::VideoMode& mode, const std::string& window_title, float dynamic_objects_ratio) : m_ptr_builder(std::move(ptr_builder)), m_mode(mode), m_window_title(window_title), m_dynamic_obj_ratio(dynamic_objects_ratio) { } @@ -101,42 +101,42 @@ void SimpleBuilder::set_rooms_sides() { for (size_t j = 0; j < m_rooms_in_row; ++j) { if (i == 0) { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::UP, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::UP)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::UP, side); + m_rooms.at(i).at(j)->get_side(Direction::UP)->prepare_for_drawing(); } else { side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i - 1).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::UP, side); + m_rooms.at(i).at(j)->set_side(Direction::UP, side); } if (i == m_rooms_in_col - 1) { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::DOWN, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::DOWN)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::DOWN, side); + m_rooms.at(i).at(j)->get_side(Direction::DOWN)->prepare_for_drawing(); } else { side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i + 1).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::DOWN, side); + m_rooms.at(i).at(j)->set_side(Direction::DOWN, side); } if (j == 0) { if (i == m_rooms_in_col / 2) { side = std::make_shared<Teleport>(*m_rooms.at(i).at(j), *m_rooms.at(i).at(m_rooms_in_row - 1)); - m_rooms.at(i).at(j)->set_side(Room::Direction::LEFT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::LEFT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::LEFT, side); + m_rooms.at(i).at(j)->get_side(Direction::LEFT)->prepare_for_drawing(); side = std::make_shared<Teleport>(*m_rooms.at(i).at(j), *m_rooms.at(i).at(m_rooms_in_row - 1)); - m_rooms.at(i).at(m_rooms_in_row - 1)->set_side(Room::Direction::RIGHT, side); - m_rooms.at(i).at(m_rooms_in_row - 1)->get_side(Room::Direction::RIGHT)->prepare_for_drawing(); + m_rooms.at(i).at(m_rooms_in_row - 1)->set_side(Direction::RIGHT, side); + m_rooms.at(i).at(m_rooms_in_row - 1)->get_side(Direction::RIGHT)->prepare_for_drawing(); } else { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::LEFT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::LEFT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::LEFT, side); + m_rooms.at(i).at(j)->get_side(Direction::LEFT)->prepare_for_drawing(); } } else { side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i).at(j - 1)); - m_rooms.at(i).at(j)->set_side(Room::Direction::LEFT, side); + m_rooms.at(i).at(j)->set_side(Direction::LEFT, side); } if (j == m_rooms_in_row - 1) { @@ -145,13 +145,13 @@ void SimpleBuilder::set_rooms_sides() { } else { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::RIGHT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::RIGHT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::RIGHT, side); + m_rooms.at(i).at(j)->get_side(Direction::RIGHT)->prepare_for_drawing(); } } else { side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i).at(j + 1)); - m_rooms.at(i).at(j)->set_side(Room::Direction::RIGHT, side); + m_rooms.at(i).at(j)->set_side(Direction::RIGHT, side); } } } @@ -188,36 +188,36 @@ void ComplexBuilder::set_rooms_sides() { if (i % 2 == 1) { //обрабатываем нечетные строки if (j % 2 == 0) { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::UP, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::UP)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::UP, side); + m_rooms.at(i).at(j)->get_side(Direction::UP)->prepare_for_drawing(); side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::DOWN, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::DOWN)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::DOWN, side); + m_rooms.at(i).at(j)->get_side(Direction::DOWN)->prepare_for_drawing(); } else { side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i - 1).at(j / 2)); - m_rooms.at(i).at(j)->set_side(Room::Direction::UP, side); + m_rooms.at(i).at(j)->set_side(Direction::UP, side); side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i + 1).at(j / 2)); - m_rooms.at(i).at(j)->set_side(Room::Direction::DOWN, side); + m_rooms.at(i).at(j)->set_side(Direction::DOWN, side); } if (j == 0) { if (i == m_rooms_in_col / 2) { side = std::make_shared<Teleport>(*m_rooms.at(i).at(j), *m_rooms.at(i).back()); - m_rooms.at(i).at(j)->set_side(Room::Direction::LEFT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::LEFT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::LEFT, side); + m_rooms.at(i).at(j)->get_side(Direction::LEFT)->prepare_for_drawing(); side = std::make_shared<Teleport>(*m_rooms.at(i).at(j), *m_rooms.at(i).back()); - m_rooms.at(i).back()->set_side(Room::Direction::RIGHT, side); - m_rooms.at(i).back()->get_side(Room::Direction::RIGHT)->prepare_for_drawing(); + m_rooms.at(i).back()->set_side(Direction::RIGHT, side); + m_rooms.at(i).back()->get_side(Direction::RIGHT)->prepare_for_drawing(); } else { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::LEFT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::LEFT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::LEFT, side); + m_rooms.at(i).at(j)->get_side(Direction::LEFT)->prepare_for_drawing(); } } else { side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i).at(j - 1)); - m_rooms.at(i).at(j)->set_side(Room::Direction::LEFT, side); + m_rooms.at(i).at(j)->set_side(Direction::LEFT, side); } if (j == m_rooms_in_row - 1) { if (i == m_rooms_in_col / 2) { @@ -225,13 +225,13 @@ void ComplexBuilder::set_rooms_sides() { } else { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::RIGHT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::RIGHT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::RIGHT, side); + m_rooms.at(i).at(j)->get_side(Direction::RIGHT)->prepare_for_drawing(); } } else { side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i).at(j + 1)); - m_rooms.at(i).at(j)->set_side(Room::Direction::RIGHT, side); + m_rooms.at(i).at(j)->set_side(Direction::RIGHT, side); } } else { @@ -242,49 +242,49 @@ void ComplexBuilder::set_rooms_sides() { else { side = std::make_shared<Teleport>(*m_rooms.at(i).at(j), *m_rooms.at(i).at(m_rooms.at(i).size() - 1)); - m_rooms.at(i).at(j)->set_side(Room::Direction::LEFT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::LEFT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::LEFT, side); + m_rooms.at(i).at(j)->get_side(Direction::LEFT)->prepare_for_drawing(); side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::RIGHT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::RIGHT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::RIGHT, side); + m_rooms.at(i).at(j)->get_side(Direction::RIGHT)->prepare_for_drawing(); side = std::make_shared<Teleport>(*m_rooms.at(i).at(j), *m_rooms.at(i).at(m_rooms.at(i).size() - 1)); - m_rooms.at(i).at(m_rooms.at(i).size() - 1)->set_side(Room::Direction::RIGHT, side); - m_rooms.at(i).at(m_rooms.at(i).size() - 1)->get_side(Room::Direction::RIGHT)->prepare_for_drawing(); + m_rooms.at(i).at(m_rooms.at(i).size() - 1)->set_side(Direction::RIGHT, side); + m_rooms.at(i).at(m_rooms.at(i).size() - 1)->get_side(Direction::RIGHT)->prepare_for_drawing(); side = std::make_shared<Wall>(*m_rooms.at(i).at(m_rooms.at(i).size() - 1)); - m_rooms.at(i).at(m_rooms.at(i).size() - 1)->set_side(Room::Direction::LEFT, side); - m_rooms.at(i).at(m_rooms.at(i).size() - 1)->get_side(Room::Direction::LEFT)->prepare_for_drawing(); + m_rooms.at(i).at(m_rooms.at(i).size() - 1)->set_side(Direction::LEFT, side); + m_rooms.at(i).at(m_rooms.at(i).size() - 1)->get_side(Direction::LEFT)->prepare_for_drawing(); ++counter; } } else { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::RIGHT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::RIGHT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::RIGHT, side); + m_rooms.at(i).at(j)->get_side(Direction::RIGHT)->prepare_for_drawing(); side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::LEFT, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::LEFT)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::LEFT, side); + m_rooms.at(i).at(j)->get_side(Direction::LEFT)->prepare_for_drawing(); } if (i == 0) { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::UP, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::UP)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::UP, side); + m_rooms.at(i).at(j)->get_side(Direction::UP)->prepare_for_drawing(); } else { side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i - 1).at(j * 2 + 1)); - m_rooms.at(i).at(j)->set_side(Room::Direction::UP, side); + m_rooms.at(i).at(j)->set_side(Direction::UP, side); } if (i == m_rooms_in_col - 1) { side = std::make_shared<Wall>(*m_rooms.at(i).at(j)); - m_rooms.at(i).at(j)->set_side(Room::Direction::DOWN, side); - m_rooms.at(i).at(j)->get_side(Room::Direction::DOWN)->prepare_for_drawing(); + m_rooms.at(i).at(j)->set_side(Direction::DOWN, side); + m_rooms.at(i).at(j)->get_side(Direction::DOWN)->prepare_for_drawing(); } else { side = std::make_shared<Pass>(*m_rooms.at(i).at(j), *m_rooms.at(i + 1).at(j * 2 + 1)); - m_rooms.at(i).at(j)->set_side(Room::Direction::DOWN, side); + m_rooms.at(i).at(j)->set_side(Direction::DOWN, side); } } } diff --git a/source/Config/Config.h b/source/Config/Config.h index d81965a..e094123 100644 --- a/source/Config/Config.h +++ b/source/Config/Config.h @@ -49,4 +49,6 @@ namespace config { const sf::Color GAME_COLOR_TELEPORT{ 255, 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 +} + +enum Direction { INVALID = -1, LEFT, RIGHT, UP, DOWN }; \ No newline at end of file diff --git a/source/Draw/Texture.cpp b/source/Draw/Texture.cpp index 58f2984..7dbae25 100644 --- a/source/Draw/Texture.cpp +++ b/source/Draw/Texture.cpp @@ -21,8 +21,27 @@ MenuTexture::MenuTexture() { m_tex.setRepeated(true); } +sf::Texture& SpellTexture::get_texture() { + switch (m_dir) { + case Direction::UP: + return m_up; + case Direction::DOWN: + return m_down; + case Direction::RIGHT: + return m_right; + case Direction::LEFT: + return m_left; + } + +} + SpellTexture::SpellTexture() { - if (!m_tex.loadFromFile(std::string(TEXTURE_PATH) + "fireball.png")) + if (!m_right.loadFromFile(std::string(TEXTURE_PATH) + "fireball.png")) + throw std::runtime_error("Can't added Texture for Fireball"); + if (!m_down.loadFromFile(std::string(TEXTURE_PATH) + "fireball_down.png")) + throw std::runtime_error("Can't added Texture for Fireball"); + if (!m_left.loadFromFile(std::string(TEXTURE_PATH) + "fireball_left.png")) + throw std::runtime_error("Can't added Texture for Fireball"); + if (!m_up.loadFromFile(std::string(TEXTURE_PATH) + "fireball_up.png")) throw std::runtime_error("Can't added Texture for Fireball"); - m_tex.setRepeated(true); } \ No newline at end of file diff --git a/source/Draw/Texture.h b/source/Draw/Texture.h index ab76201..968e363 100644 --- a/source/Draw/Texture.h +++ b/source/Draw/Texture.h @@ -1,13 +1,16 @@ #pragma once #include <SFML/Graphics.hpp> +#include "../Config/Config.h" + class Texture { public: Texture(const Texture& tex) = delete; Texture& operator=(const Texture& tex) = delete; virtual sf::Texture& get_texture() = 0; + void set_dir(Direction dir) { m_dir = dir; } protected: - sf::Texture m_tex; + Direction m_dir = Direction::RIGHT; Texture() = default; }; @@ -17,6 +20,7 @@ public: static PacmanTexture& Instance() { static PacmanTexture tex; return tex; } sf::Texture& get_texture() override { return m_tex; } private: + sf::Texture m_tex; PacmanTexture(); }; @@ -25,6 +29,7 @@ public: static EnemyTexture& Instance() { static EnemyTexture tex; return tex; } sf::Texture& get_texture() override { return m_tex; } private: + sf::Texture m_tex; EnemyTexture(); }; @@ -33,6 +38,7 @@ public: static GoldTexture& Instance() { static GoldTexture tex; return tex; } sf::Texture& get_texture() override { return m_tex; } private: + sf::Texture m_tex; GoldTexture(); }; @@ -42,13 +48,15 @@ public: static MenuTexture& Instance() { static MenuTexture tex; return tex; } sf::Texture& get_texture() override { return m_tex; } private: + sf::Texture m_tex; MenuTexture(); }; class SpellTexture : public Texture { public: static SpellTexture& Instance() { static SpellTexture tex; return tex; } - sf::Texture& get_texture() override { return m_tex; } + sf::Texture& get_texture() override; private: + sf::Texture m_up, m_right, m_down, m_left; SpellTexture(); }; \ No newline at end of file diff --git a/source/Game/IEntity.cpp b/source/Game/IEntity.cpp index 6c2324b..01942d0 100644 --- a/source/Game/IEntity.cpp +++ b/source/Game/IEntity.cpp @@ -82,7 +82,7 @@ void Enemy::action(Room* room) { side = 2; } } - auto direction = static_cast<Room::Direction>(side); + auto direction = static_cast<Direction>(side); m_ptr_room->get_side(direction)->enter(this); m_stopwatch.restart(); //запускаем секундомер сначала } diff --git a/source/Game/Pacman.cpp b/source/Game/Pacman.cpp index a1e74de..016157b 100644 --- a/source/Game/Pacman.cpp +++ b/source/Game/Pacman.cpp @@ -5,7 +5,7 @@ Pacman::Pacman() { set_texture(&PacmanTexture::Instance()); } -void Pacman::move(Room::Direction direction) { +void Pacman::move(Direction direction) { m_dir = direction; m_ptr_room->get_side(direction)->enter(this); } @@ -24,6 +24,9 @@ void Pacman::ultimate(){ } void Pacman::draw_into(sf::RenderWindow& window) const { + if (m_mp < 300) { + m_mp += 1.0 / 60; + } for (auto& spell : m_spells) { spell.draw_into(window); } @@ -55,7 +58,7 @@ std::unique_ptr<IGameEvent> Pacman::visit(Enemy* ptr_enemy) { } -Fireball::Fireball(Room::Direction direction, Room* room) { +Fireball::Fireball(Direction direction, Room* room) { m_direct = direction; m_ptr_room = room; set_texture(&SpellTexture::Instance()); @@ -67,6 +70,7 @@ void Fireball::draw_into(sf::RenderWindow& window) const { } void Fireball::prepare_for_drawing(){ + m_ptr_tex->set_dir(m_direct); m_sprite.setTexture(m_ptr_tex->get_texture()); m_sprite.setScale(0.1, 0.1); m_sprite.setPosition(m_ptr_room->get_position() + sf::Vector2f(-10, -10)); diff --git a/source/Game/Pacman.h b/source/Game/Pacman.h index c725f9a..ae1ffa2 100644 --- a/source/Game/Pacman.h +++ b/source/Game/Pacman.h @@ -5,7 +5,7 @@ class Fireball : public IEntity, public IVisitor { public: - Fireball(Room::Direction direction, Room* room); + Fireball(Direction direction, Room* room); void draw_into(sf::RenderWindow& window) const override; void prepare_for_drawing() override; void move(); @@ -14,7 +14,7 @@ public: void set_texture(Texture* ptr_texture) { m_ptr_tex = ptr_texture; } private: size_t m_wall = 0; - Room::Direction m_direct; + Direction m_direct; mutable sf::Sprite m_sprite; Texture* m_ptr_tex; }; @@ -22,7 +22,7 @@ private: class Pacman :public IEntity, public IVisitor { public: Pacman(); - void move(Room::Direction direction); + void move(Direction direction); void spell(); void ultimate(); void draw_into(sf::RenderWindow& window) const override; @@ -32,8 +32,8 @@ public: void set_texture(Texture* ptr_texture) { m_ptr_tex = ptr_texture; } std::vector<Fireball> m_spells; private: - Room::Direction m_dir; - size_t m_mp = 100; + Direction m_dir; + mutable float m_mp = 100; sf::Sprite m_sprite; Texture* m_ptr_tex; }; diff --git a/source/Maze/Maze.cpp b/source/Maze/Maze.cpp index 0c7f56e..d37bfb6 100644 --- a/source/Maze/Maze.cpp +++ b/source/Maze/Maze.cpp @@ -28,7 +28,7 @@ std::shared_ptr<IRoomSide> Room::get_side(Direction side) { return m_sides.at(side); } -Room::Direction Room::get_direction(IRoomSide* ptr_side) { +Direction Room::get_direction(IRoomSide* ptr_side) { if (ptr_side == m_sides.at(UP).get()) { return UP; } if (ptr_side == m_sides.at(RIGHT).get()) { return RIGHT; } if (ptr_side == m_sides.at(DOWN).get()) { return DOWN; } @@ -103,22 +103,22 @@ void Wall::prepare_for_drawing() { float size = config::ROOM_SIZE; switch (m_room.get_direction(this)) { - case Room::UP: + case Direction::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: + case Direction::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: + case Direction::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: + case Direction::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; diff --git a/source/Maze/Maze.h b/source/Maze/Maze.h index 68a0dbb..a176cd1 100644 --- a/source/Maze/Maze.h +++ b/source/Maze/Maze.h @@ -27,7 +27,7 @@ private: sf::RectangleShape m_rectangle; public: std::array<std::shared_ptr<IRoomSide>, 4> m_sides; - enum Direction { INVALID = -1, LEFT, RIGHT, UP, DOWN }; + //enum Direction { INVALID = -1, LEFT, RIGHT, UP, DOWN }; public: Room(float size); float get_size(); diff --git a/source/State/States.cpp b/source/State/States.cpp index b0b8bf0..5a73321 100644 --- a/source/State/States.cpp +++ b/source/State/States.cpp @@ -153,21 +153,21 @@ void GameState::process_key_pressed(sf::Keyboard::Key code) { switch (code) { case sf::Keyboard::W: m_context_manager.save_context(); - m_context_manager.get_context().pacman.move(Room::UP); + m_context_manager.get_context().pacman.move(Direction::UP); break; case sf::Keyboard::S: m_context_manager.save_context(); - m_context_manager.get_context().pacman.move(Room::DOWN); + m_context_manager.get_context().pacman.move(Direction::DOWN); break; case sf::Keyboard::A: m_context_manager.save_context(); - m_context_manager.get_context().pacman.move(Room::LEFT); + m_context_manager.get_context().pacman.move(Direction::LEFT); break; case sf::Keyboard::D: m_context_manager.save_context(); - m_context_manager.get_context().pacman.move(Room::RIGHT); + m_context_manager.get_context().pacman.move(Direction::RIGHT); break; } } diff --git a/source/main.cpp b/source/main.cpp index fd070db..1c3cfd6 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -5,48 +5,17 @@ int main() { return app.run(); } -//#include <SFML/Graphics.hpp> +//#include <iostream> // -//int main() { -// sf::RenderWindow window(sf::VideoMode(800, 600), "Seamless Scrolling Background"); -// -// // Загружаем текстуру -// sf::Texture texture; -// if (!texture.loadFromFile(std::string(TEXTURE_PATH) + "menu.png")) { -// return -1; -// } -// -// texture.setRepeated(true); // Включаем повторение текстуры -// -// // Создаем спрайт с большим текстурным прямоугольником -// sf::Sprite sprite(texture); -// sprite.setTextureRect(sf::IntRect(0, 0, 1600, 600)); // Дважды ширина окна -// -// float offset = 0; -// float scrollSpeed = 100.f; // Скорость прокрутки -// sf::Clock clock; +//struct MyStruct { +// char c; +// int i_1; +// int i_2; +//}; // -// while (window.isOpen()) { -// sf::Event event; -// while (window.pollEvent(event)) { -// if (event.type == sf::Event::Closed) -// window.close(); -// } -// -// float deltaTime = clock.restart().asSeconds(); -// offset += scrollSpeed * deltaTime; -// -// // Делаем зацикливание -// if (offset >= 800) { // Как только сместились на ширину окна, сбрасываем -// offset -= 800; -// } -// -// sprite.setTextureRect(sf::IntRect(offset, 0, 800, 600)); -// -// window.clear(); -// window.draw(sprite); -// window.display(); -// } +//int main() { +// MyStruct a; +// std::cout << sizeof(a); // -// return 0; +// return 0; //} \ No newline at end of file -- GitLab