diff --git a/assets/enemy_blue.png b/assets/enemy_blue.png deleted file mode 100644 index e0c9ee5c0734dc2bc006b9af7f0facc6a49d46c5..0000000000000000000000000000000000000000 Binary files a/assets/enemy_blue.png and /dev/null differ diff --git a/assets/enemy_pink.png b/assets/enemy_pink.png deleted file mode 100644 index 27e30bf41f5d49b6212e9a6e569e3be86e78e379..0000000000000000000000000000000000000000 Binary files a/assets/enemy_pink.png and /dev/null differ diff --git a/assets/enemy_red.png b/assets/enemy_red.png deleted file mode 100644 index 09d1807594eac4d072bf7af6cc9e1d6294218466..0000000000000000000000000000000000000000 Binary files a/assets/enemy_red.png and /dev/null differ diff --git a/assets/enemy_yellow.png b/assets/enemy_yellow.png deleted file mode 100644 index 028c7b2d74a31c20c4cc5aefcc3dc9e9e61fee05..0000000000000000000000000000000000000000 Binary files a/assets/enemy_yellow.png and /dev/null differ diff --git a/source/BasicAbstractions/Assets.cpp b/source/BasicAbstractions/Assets.cpp index 297ec8920f279a4eb54b094adaf77526a24c856e..15a8b8069e621a5b669d1f445dbb6f6c5852e8d5 100644 --- a/source/BasicAbstractions/Assets.cpp +++ b/source/BasicAbstractions/Assets.cpp @@ -1,4 +1,7 @@ #include "Assets.h" +#include <array> +#include <random> +#include <Configuration.h> sf::Font& Assets::GetFont() { static sf::Font font; @@ -16,38 +19,42 @@ sf::Texture& Assets::GetPacmanTexture() { return texture; } -sf::Texture& Assets::GetEnemyRedTexture() { - static sf::Texture texture; - if (texture.getSize() != sf::Vector2u{0, 0}) - return texture; - if (!texture.loadFromFile(config::ENEMY_RED_FILE)) - throw std::runtime_error("Failed to load texture: enemy red"); - return texture; -} - -sf::Texture& Assets::GetEnemyPinkTexture() { - static sf::Texture texture; - if (texture.getSize() != sf::Vector2u{0, 0}) - return texture; - if (!texture.loadFromFile(config::ENEMY_PINK_FILE)) - throw std::runtime_error("Failed to load texture: enemy pink"); - return texture; +sf::Texture& Assets::GetEnemyTexture() { + static std::array<sf::Texture, config::ENEMY_TEXTURES_NUMBER> textures; + if (textures[0].getSize() == sf::Vector2u{0, 0}) { + if (!textures[0].loadFromFile(config::ENEMY_RED_FILE)) + throw std::runtime_error("Failed to load texture: enemy red"); + if (!textures[1].loadFromFile(config::ENEMY_BLUE_FILE)) + throw std::runtime_error("Failed to load texture: enemy blue"); + if (!textures[2].loadFromFile(config::ENEMY_YELLOW_FILE)) + throw std::runtime_error("Failed to load texture: enemy yellow"); + if (!textures[3].loadFromFile(config::ENEMY_PINK_FILE)) + throw std::runtime_error("Failed to load texture: enemy pink"); + } + static std::mt19937 gen{std::random_device{}()}; + static std::uniform_int_distribution<size_t> dist{0, config::ENEMY_TEXTURES_NUMBER-1}; + return textures[dist(gen)]; } -sf::Texture& Assets::GetEnemyYellowTexture() { - static sf::Texture texture; - if (texture.getSize() != sf::Vector2u{0, 0}) - return texture; - if (!texture.loadFromFile(config::ENEMY_YELLOW_FILE)) - throw std::runtime_error("Failed to load texture: enemy yellow"); - return texture; -} - -sf::Texture& Assets::GetEnemyBlueTexture() { - static sf::Texture texture; - if (texture.getSize() != sf::Vector2u{0, 0}) - return texture; - if (!texture.loadFromFile(config::ENEMY_BLUE_FILE)) - throw std::runtime_error("Failed to load texture: enemy blue"); - return texture; +sf::Texture& Assets::GetFoodTexture() { + static std::array<sf::Texture, config::FOOD_TEXTURES_NUMBER> textures; + if (textures[0].getSize() == sf::Vector2u{0, 0}) { + if (!textures[0].loadFromFile(config::FOOD_1)) + throw std::runtime_error("Failed to load texture: food 1"); + if (!textures[1].loadFromFile(config::FOOD_2)) + throw std::runtime_error("Failed to load texture: food 2"); + if (!textures[2].loadFromFile(config::FOOD_3)) + throw std::runtime_error("Failed to load texture: food 3"); + if (!textures[3].loadFromFile(config::FOOD_4)) + throw std::runtime_error("Failed to load texture: food 4"); + if (!textures[4].loadFromFile(config::FOOD_5)) + throw std::runtime_error("Failed to load texture: food 5"); + if (!textures[5].loadFromFile(config::FOOD_6)) + throw std::runtime_error("Failed to load texture: food 6"); + if (!textures[6].loadFromFile(config::FOOD_7)) + throw std::runtime_error("Failed to load texture: food 7"); + } + static std::mt19937 gen{std::random_device{}()}; + static std::uniform_int_distribution<size_t> dist{0, config::FOOD_TEXTURES_NUMBER-1}; + return textures[dist(gen)]; } \ No newline at end of file diff --git a/source/BasicAbstractions/Assets.h b/source/BasicAbstractions/Assets.h index 31816baa42ae92262aeeecf0e180c7ef3c510feb..665c0fbc3b8f748482b7a586237f4122cab78223 100644 --- a/source/BasicAbstractions/Assets.h +++ b/source/BasicAbstractions/Assets.h @@ -1,12 +1,10 @@ #pragma once -#include <Configuration.h> +#include <SFML/Graphics.hpp> struct Assets final { Assets() = delete; static sf::Font& GetFont(); static sf::Texture& GetPacmanTexture(); - static sf::Texture& GetEnemyRedTexture(); - static sf::Texture& GetEnemyYellowTexture(); - static sf::Texture& GetEnemyBlueTexture(); - static sf::Texture& GetEnemyPinkTexture(); + static sf::Texture& GetEnemyTexture(); + static sf::Texture& GetFoodTexture(); }; \ No newline at end of file diff --git a/source/Configuration.h b/source/Configuration.h index 5296a7a73f52c22d2489354cd35615150112c244..d2648696fbfb0e8b408b8fa183b8459b310a8ce8 100644 --- a/source/Configuration.h +++ b/source/Configuration.h @@ -3,7 +3,7 @@ namespace config { // Общее: - constexpr unsigned int FRAME_RATE_LIMIT = 10; + constexpr unsigned int FRAME_RATE_LIMIT = 60; // Меню: const sf::VideoMode SELECT_LEVEL_VIDEO_MODE{ 400, 600 }; const sf::Vector2f BUTTON_SIZE = { static_cast<float>(SELECT_LEVEL_VIDEO_MODE.width)/1.6f, @@ -25,11 +25,20 @@ namespace config { // РРіСЂР°: const sf::VideoMode GAME_VIDEO_MODE{ 1080, 720 }; constexpr char PACMAN_FILE[] = ASSETS_PATH "pacman.png"; - constexpr char ENEMY_PINK_FILE[] = ASSETS_PATH "enemy_pink.png"; - constexpr char ENEMY_RED_FILE[] = ASSETS_PATH "enemy_red.png"; - constexpr char ENEMY_BLUE_FILE[] = ASSETS_PATH "enemy_blue.png"; - constexpr char ENEMY_YELLOW_FILE[] = ASSETS_PATH "enemy_yellow.png"; + constexpr char ENEMY_PINK_FILE[] = ASSETS_PATH "enemies/enemy_pink.png"; + constexpr char ENEMY_RED_FILE[] = ASSETS_PATH "enemies/enemy_red.png"; + constexpr char ENEMY_BLUE_FILE[] = ASSETS_PATH "enemies/enemy_blue.png"; + constexpr char ENEMY_YELLOW_FILE[] = ASSETS_PATH "enemies/enemy_yellow.png"; + constexpr size_t ENEMY_TEXTURES_NUMBER = 4; constexpr size_t ENEMY_ON_SPRITE_COUNT = 8; + constexpr char FOOD_1[] = ASSETS_PATH "food/onigiri.png"; + constexpr char FOOD_2[] = ASSETS_PATH "food/sushi_roll_1.png"; + constexpr char FOOD_3[] = ASSETS_PATH "food/sushi_roll_2.png"; + constexpr char FOOD_4[] = ASSETS_PATH "food/sushi_roll_3.png"; + constexpr char FOOD_5[] = ASSETS_PATH "food/sushi_roll_4.png"; + constexpr char FOOD_6[] = ASSETS_PATH "food/sushi_roll_5.png"; + constexpr char FOOD_7[] = ASSETS_PATH "food/sushi_roll_6.png"; + constexpr size_t FOOD_TEXTURES_NUMBER = 7; constexpr char EASY_GAME_TITLE[] = "Level: Easy"; constexpr char MEDIUM_GAME_TITLE[] = "Level: Medium"; constexpr char HARD_GAME_TITLE[] = "Level: Hard"; @@ -39,7 +48,7 @@ namespace config { constexpr float HARD_GAME_ENEMY_RATIO = 0.07f; constexpr float ROOM_SIZE = 50; constexpr float GAME_ENEMY_SIZE = ROOM_SIZE * 0.8; - constexpr float GAME_FOOD_SIZE = ROOM_SIZE * 0.1; + constexpr float GAME_FOOD_SIZE = ROOM_SIZE * 0.2; constexpr float ENEMY_SPEED_MEDIEUM = 100; constexpr float ENEMY_SPEED_HARD = 150; constexpr float ENEMY_SPEED_EXTREME = 250; @@ -72,7 +81,6 @@ namespace config { const sf::Color SELECT_LEVEL_BACKGROUND_COLOR{ 230,230,230 }; 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_COLOR_BACKGROUND_INGAME{ 230,230,230 }; const sf::Color TEXT_COLOR_NOTIFICATION{ 0, 0, 0, 255}; const sf::Color NOTIFICATION_BANNER_COLOR_PLAY{ 0, 100, 255, 200 }; @@ -95,7 +103,6 @@ namespace config { const sf::Color SELECT_LEVEL_BACKGROUND_COLOR_DARK{ 30, 30, 30 }; const sf::Color GAME_COLOR_ROOM_DARK{ 50, 50, 50 }; const sf::Color GAME_COLOR_WALL_DARK{ 200, 200, 200 }; - const sf::Color GAME_FOOD_COLOR_DARK{ 0, 150, 75 }; const sf::Color GAME_COLOR_BACKGROUND_INGAME_DARK{ 20, 20, 20 }; const sf::Color TEXT_COLOR_NOTIFICATION_DARK{ 255, 255, 255, 255 }; const sf::Color NOTIFICATION_BANNER_COLOR_PLAY_DARK{ 0, 50, 150, 200 }; diff --git a/source/States/GameState/Entities/DynamicEntities/DynamicEntities.cpp b/source/States/GameState/Entities/DynamicEntities/DynamicEntities.cpp index ea9069f2a7c3945b1cb81fcb5f58ad63ad901336..900a5bc2880da8e4388c33422e964f8b2e30cf4f 100644 --- a/source/States/GameState/Entities/DynamicEntities/DynamicEntities.cpp +++ b/source/States/GameState/Entities/DynamicEntities/DynamicEntities.cpp @@ -5,19 +5,12 @@ Enemy::Enemy(const float speed) : m_speed(speed) { std::mt19937 gen{std::random_device{}()}; std::uniform_int_distribution<size_t> dist{0, 3}; - const sf::Texture* texture; - switch (dist(gen)) { - case 0: texture = &Assets::GetEnemyRedTexture(); break; - case 1: texture = &Assets::GetEnemyYellowTexture(); break; - case 2: texture = &Assets::GetEnemyBlueTexture(); break; - case 3: texture = &Assets::GetEnemyPinkTexture(); break; - default: texture = &Assets::GetEnemyRedTexture(); break;; - } + const sf::Texture& texture = Assets::GetEnemyTexture(); - m_sprite.setTexture(*texture); + m_sprite.setTexture(texture); m_sprite.setTextureRect(sf::IntRect(0, 0, - static_cast<int>(texture->getSize().x / config::ENEMY_ON_SPRITE_COUNT), static_cast<int>(texture->getSize().y))); - m_sprite.setOrigin(static_cast<float>(texture->getSize().x) / (2.f * config::ENEMY_ON_SPRITE_COUNT), static_cast<float>(texture->getSize().y) / 2.f); + static_cast<int>(texture.getSize().x / config::ENEMY_ON_SPRITE_COUNT), static_cast<int>(texture.getSize().y))); + m_sprite.setOrigin(static_cast<float>(texture.getSize().x) / (2.f * config::ENEMY_ON_SPRITE_COUNT), static_cast<float>(texture.getSize().y) / 2.f); m_distance_limit = m_speed / config::ROOM_SIZE; } diff --git a/source/States/GameState/Entities/StaticEntities/StaticEntities.cpp b/source/States/GameState/Entities/StaticEntities/StaticEntities.cpp index f17ff1916900256d80f9f79296ecf30b6161ca87..a92069e1100a23d4d61bfaa8cf263e0774ed1068 100644 --- a/source/States/GameState/Entities/StaticEntities/StaticEntities.cpp +++ b/source/States/GameState/Entities/StaticEntities/StaticEntities.cpp @@ -1,10 +1,11 @@ #include <States/GameState/Entities/StaticEntities/StaticEntities.h> #include <Configuration.h> +#include <BasicAbstractions/Assets.h> #include <Themes/Themes.h> -Food::Food() : m_circle(config::GAME_FOOD_SIZE, 6) { - m_circle.setFillColor(Themes::Instance().get_game_food_color()); - m_circle.setOrigin({config::GAME_FOOD_SIZE, config::GAME_FOOD_SIZE}); +Food::Food() : m_rect({ config::GAME_FOOD_SIZE, config::GAME_FOOD_SIZE }) { + m_rect.setOrigin({config::GAME_FOOD_SIZE, config::GAME_FOOD_SIZE}); + m_rect.setTexture(&Assets::GetFoodTexture()); } std::unique_ptr<IStaticEntity> Food::clone() const { @@ -12,7 +13,7 @@ std::unique_ptr<IStaticEntity> Food::clone() const { } void Food::draw_into(sf::RenderWindow& window) const { - window.draw(m_circle); + window.draw(m_rect); } void Food::prepare_for_first_drawing() { @@ -20,5 +21,5 @@ void Food::prepare_for_first_drawing() { } void Food::prepare_for_drawing() { - m_circle.setPosition(m_ptr_room->get_position()); + m_rect.setPosition(m_ptr_room->get_position()); } \ No newline at end of file diff --git a/source/States/GameState/Entities/StaticEntities/StaticEntities.h b/source/States/GameState/Entities/StaticEntities/StaticEntities.h index f4ba0ee493ce34831897c9a6ea9e81a2db15bef8..39ed19daaadb23005dbd49079a3c4763b04ca648 100644 --- a/source/States/GameState/Entities/StaticEntities/StaticEntities.h +++ b/source/States/GameState/Entities/StaticEntities/StaticEntities.h @@ -13,8 +13,8 @@ public: void draw_into(sf::RenderWindow& window) const override; void prepare_for_first_drawing() override; void prepare_for_drawing() override; - sf::FloatRect getBounds() const { return m_circle.getGlobalBounds(); } + sf::FloatRect getBounds() const { return m_rect.getGlobalBounds(); } std::unique_ptr<IGameEvent> accept(IVisitor* ptr_visitor) override { return ptr_visitor->visit(this); } private: - sf::CircleShape m_circle; + sf::RectangleShape m_rect; }; \ No newline at end of file diff --git a/source/Themes/Themes.cpp b/source/Themes/Themes.cpp index eae022ed17ca1ad6ddaef24ba21ee1b051537483..a052ea042f1a2bd1609cd668e0b14915d321b167 100644 --- a/source/Themes/Themes.cpp +++ b/source/Themes/Themes.cpp @@ -14,7 +14,6 @@ void Themes::change_theme() { SELECT_LEVEL_BACKGROUND_COLOR = config::SELECT_LEVEL_BACKGROUND_COLOR; GAME_COLOR_ROOM = config::GAME_COLOR_ROOM; GAME_COLOR_WALL = config::GAME_COLOR_WALL; - GAME_FOOD_COLOR = config::GAME_FOOD_COLOR; GAME_COLOR_BACKGROUND_INGAME = config::GAME_COLOR_BACKGROUND_INGAME; TEXT_COLOR_NOTIFICATION = config::TEXT_COLOR_NOTIFICATION; NOTIFICATION_BANNER_COLOR_PLAY = config::NOTIFICATION_BANNER_COLOR_PLAY; @@ -39,7 +38,6 @@ void Themes::change_theme() { SELECT_LEVEL_BACKGROUND_COLOR = config::SELECT_LEVEL_BACKGROUND_COLOR_DARK; GAME_COLOR_ROOM = config::GAME_COLOR_ROOM_DARK; GAME_COLOR_WALL = config::GAME_COLOR_WALL_DARK; - GAME_FOOD_COLOR = config::GAME_FOOD_COLOR_DARK; GAME_COLOR_BACKGROUND_INGAME = config::GAME_COLOR_BACKGROUND_INGAME_DARK; TEXT_COLOR_NOTIFICATION = config::TEXT_COLOR_NOTIFICATION_DARK; NOTIFICATION_BANNER_COLOR_PLAY = config::NOTIFICATION_BANNER_COLOR_PLAY_DARK; diff --git a/source/Themes/Themes.h b/source/Themes/Themes.h index 5e309273df11cf6f6839c28f219b3fc0725e2ec4..d28424dcb509c5116e5de13b2f459d2760aaedd8 100644 --- a/source/Themes/Themes.h +++ b/source/Themes/Themes.h @@ -15,7 +15,6 @@ public: [[nodiscard]] sf::Color get_select_level_background_color() const { return SELECT_LEVEL_BACKGROUND_COLOR; } [[nodiscard]] sf::Color get_game_color_room() const { return GAME_COLOR_ROOM; } [[nodiscard]] sf::Color get_game_color_wall() const { return GAME_COLOR_WALL; } - [[nodiscard]] sf::Color get_game_food_color() const { return GAME_FOOD_COLOR; } [[nodiscard]] sf::Color get_game_color_background_in_game() const { return GAME_COLOR_BACKGROUND_INGAME; } [[nodiscard]] sf::Color get_text_color_notification() const { return TEXT_COLOR_NOTIFICATION; } [[nodiscard]] sf::Color get_notification_banner_color_play() const { return NOTIFICATION_BANNER_COLOR_PLAY; } @@ -41,7 +40,6 @@ private: sf::Color SELECT_LEVEL_BACKGROUND_COLOR = config::SELECT_LEVEL_BACKGROUND_COLOR_DARK; sf::Color GAME_COLOR_ROOM = config::GAME_COLOR_ROOM_DARK; sf::Color GAME_COLOR_WALL = config::GAME_COLOR_WALL_DARK; - sf::Color GAME_FOOD_COLOR = config::GAME_FOOD_COLOR_DARK; sf::Color GAME_COLOR_BACKGROUND_INGAME = config::GAME_COLOR_BACKGROUND_INGAME_DARK; sf::Color TEXT_COLOR_NOTIFICATION = config::TEXT_COLOR_NOTIFICATION_DARK; sf::Color NOTIFICATION_BANNER_COLOR_PLAY = config::NOTIFICATION_BANNER_COLOR_PLAY_DARK;