From 561389f1a949f024af8c79ecb84cdc5529b62a15 Mon Sep 17 00:00:00 2001 From: Sulimov Igor Andreevich <igansulimov@edu.hse.ru> Date: Wed, 26 Mar 2025 12:37:20 +0300 Subject: [PATCH] Final commit, I believe (made textures and fixed bugs) --- include/MazeContent/Entities/Pacman.h | 1 - .../MazeContent/Entities/StaticEntities/Food.h | 5 +++++ .../Entities/DynamicEntities/Enemy.cpp | 4 ++-- source/MazeContent/Entities/Pacman.cpp | 3 +-- .../MazeContent/Entities/StaticEntities/Food.cpp | 15 ++++++++++----- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/MazeContent/Entities/Pacman.h b/include/MazeContent/Entities/Pacman.h index 0135e1a..3ba3863 100644 --- a/include/MazeContent/Entities/Pacman.h +++ b/include/MazeContent/Entities/Pacman.h @@ -2,7 +2,6 @@ #include "IEntity.h" #include <Visit/IVisitor.h> - #include "Draw/Textures/PacmanTexture.h" class Pacman: public IEntity, public IVisitor { diff --git a/include/MazeContent/Entities/StaticEntities/Food.h b/include/MazeContent/Entities/StaticEntities/Food.h index 3b96b31..0a5afc3 100644 --- a/include/MazeContent/Entities/StaticEntities/Food.h +++ b/include/MazeContent/Entities/StaticEntities/Food.h @@ -1,6 +1,7 @@ #pragma once #include "IStaticEntity.h" +#include "Draw/Textures/FoodTexture.h" class Food: public IStaticEntity { public: @@ -8,8 +9,12 @@ public: void draw_into(sf::RenderWindow& window) const override; std::unique_ptr<IStaticEntity> clone() const override; std::unique_ptr<IGameEvent> accept(IVisitor* ptr_visitor) override; +private: + void set_texture(Texture* ptr_texture); public: Food(); private: sf::CircleShape m_circle; + sf::Sprite m_sprite; + Texture* m_ptr_texture; }; \ No newline at end of file diff --git a/source/MazeContent/Entities/DynamicEntities/Enemy.cpp b/source/MazeContent/Entities/DynamicEntities/Enemy.cpp index 7ef0e02..768249d 100644 --- a/source/MazeContent/Entities/DynamicEntities/Enemy.cpp +++ b/source/MazeContent/Entities/DynamicEntities/Enemy.cpp @@ -29,7 +29,7 @@ void Enemy::prepare_for_drawing() { m_sprite.setTextureRect(sf::IntRect(0, 3 * (m_ptr_texture->get_texture().getSize().y) / (2 * m_rect_count), m_ptr_texture->get_texture().getSize().x / m_rect_count, (m_ptr_texture->get_texture().getSize().y))); } - m_sprite.setPosition(m_ptr_room->get_position() + sf::Vector2f(-20, -20)); + m_sprite.setPosition(m_ptr_room->get_position() + sf::Vector2f(-25, -25)); m_sprite.setScale(0.15, 0.15); } @@ -42,9 +42,9 @@ void Enemy::action() { if (miliseconds < rand() % 10000) return; auto direction = static_cast<Room::Direction>(rand() % 4); + m_direction = static_cast<config::Direction>(direction); m_ptr_room->get_side(direction)->enter(this); m_stopwatch.restart(); - m_direction = static_cast<config::Direction>(direction); } std::unique_ptr<IGameEvent> Enemy::accept(IVisitor* ptr_visitor) { diff --git a/source/MazeContent/Entities/Pacman.cpp b/source/MazeContent/Entities/Pacman.cpp index 3249134..1dd9d68 100644 --- a/source/MazeContent/Entities/Pacman.cpp +++ b/source/MazeContent/Entities/Pacman.cpp @@ -18,7 +18,6 @@ void Pacman::prepare_for_drawing() { if (m_direction == config::RIGHT) { m_sprite.setTextureRect(sf::IntRect(0, 0, m_ptr_texture->get_texture().getSize().x / m_rect_count, (m_ptr_texture->get_texture().getSize().y) / 4)); - m_sprite.setOrigin(m_ptr_texture->get_texture().getSize().x / 2 + 5, m_ptr_texture->get_texture().getSize().y / 2 + 5); } else if (m_direction == config::DOWN) { m_sprite.setTextureRect(sf::IntRect(0, (m_ptr_texture->get_texture().getSize().y) / (4), m_ptr_texture->get_texture().getSize().x / m_rect_count, (m_ptr_texture->get_texture().getSize().y) / (4))); @@ -29,7 +28,7 @@ void Pacman::prepare_for_drawing() { m_sprite.setTextureRect(sf::IntRect(0, 3 * (m_ptr_texture->get_texture().getSize().y) / (2 * m_rect_count), m_ptr_texture->get_texture().getSize().x / m_rect_count, (m_ptr_texture->get_texture().getSize().y))); } - m_sprite.setPosition(m_ptr_room->get_position() + sf::Vector2f(-20, -20)); + m_sprite.setPosition(m_ptr_room->get_position() + sf::Vector2f(-27, -27)); m_sprite.setScale(0.15, 0.15); } diff --git a/source/MazeContent/Entities/StaticEntities/Food.cpp b/source/MazeContent/Entities/StaticEntities/Food.cpp index 1532839..61bc3ed 100644 --- a/source/MazeContent/Entities/StaticEntities/Food.cpp +++ b/source/MazeContent/Entities/StaticEntities/Food.cpp @@ -2,21 +2,26 @@ #include "Config.h" #include <Events/IGameEvent.h> -Food::Food() : m_circle{config::GAME_FOOD_SIZE / 2} { - m_circle.setOrigin(m_circle.getRadius(), m_circle.getRadius()); - m_circle.setFillColor(config::GAME_FOOD_COLOR); +Food::Food() { + set_texture(&FoodTexture::Instance()); } std::unique_ptr<IStaticEntity> Food::clone() const { return std::make_unique<Food>(*this); } +void Food::set_texture(Texture* ptr_texture) { + m_ptr_texture = ptr_texture; +} + void Food::prepare_for_drawing() { - m_circle.setPosition(m_ptr_room->get_position()); + m_sprite.setTexture(m_ptr_texture->get_texture()); + m_sprite.setPosition(m_ptr_room->get_position() + sf::Vector2f(-18, -18)); + m_sprite.setScale(0.15, 0.15); } void Food::draw_into(sf::RenderWindow& window) const { - window.draw(m_circle); + window.draw(m_sprite); } std::unique_ptr<IGameEvent> Food::accept(IVisitor* ptr_visitor) { -- GitLab