Commit ec81d704 authored by Авдеев Евгений Владимирович's avatar Авдеев Евгений Владимирович
Browse files

fixed pacman texture for each direction

parent 6e9737f0
No related merge requests found
Showing with 32 additions and 8 deletions
+32 -8
#include "Texture.h"
PacmanTexture::PacmanTexture() {
if (!m_tex.loadFromFile(std::string(TEXTURE_PATH) + "pacman.png"))
throw std::runtime_error("Can't added Texture for Pacman");
if (!m_right.loadFromFile(std::string(TEXTURE_PATH) + "pacman.png"))
throw std::runtime_error("Can't added Texture for pacman");
if (!m_down.loadFromFile(std::string(TEXTURE_PATH) + "pacman_down.png"))
throw std::runtime_error("Can't added Texture for pacman");
if (!m_left.loadFromFile(std::string(TEXTURE_PATH) + "pacman_left.png"))
throw std::runtime_error("Can't added Texture for pacman");
if (!m_up.loadFromFile(std::string(TEXTURE_PATH) + "pacman_up.png"))
throw std::runtime_error("Can't added Texture for pacman");
}
sf::Texture& PacmanTexture::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;
}
}
EnemyTexture::EnemyTexture() {
if (!m_tex.loadFromFile(std::string(TEXTURE_PATH) + "spider.png"))
throw std::runtime_error("Can't added Texture for Enemy");
......
......@@ -18,9 +18,9 @@ protected:
class PacmanTexture : public Texture {
public:
static PacmanTexture& Instance() { static PacmanTexture tex; return tex; }
sf::Texture& get_texture() override { return m_tex; }
sf::Texture& get_texture() override;
private:
sf::Texture m_tex;
sf::Texture m_up, m_right, m_down, m_left;
PacmanTexture();
};
......
......@@ -58,7 +58,7 @@ static void kill_all(GameContext& context) {
}
void Ultimate::handle(GameContext& context) const {
m_sound.play();
//m_sound.play();
cv::VideoCapture cap(std::string(VIDEO_PATH) + "ultimate.mp4"); //
if (!cap.isOpened()) {
......
......@@ -2,6 +2,7 @@
#include <iostream>
#include "../Config/Config.h"
Pacman::Pacman() {
m_clock.restart();
set_texture(&PacmanTexture::Instance());
}
......@@ -37,6 +38,7 @@ void Pacman::draw_into(sf::RenderWindow& window) const {
}
void Pacman::prepare_for_drawing() {
m_ptr_tex->set_dir(m_dir);
m_sprite.setTexture(m_ptr_tex->get_texture());
m_sprite.setScale(0.07, 0.07);
m_sprite.setPosition(m_ptr_room->get_position() + sf::Vector2f(-20, -20));
......@@ -62,8 +64,9 @@ std::unique_ptr<IGameEvent> Fireball::visit(Enemy* ptr_enemy){
}
std::unique_ptr<IGameEvent> Pacman::visit(Enemy* ptr_enemy) {
if (ptr_enemy->get_location() != this->get_location())
if (ptr_enemy->get_location() != this->get_location() || m_clock.getElapsedTime().asSeconds() < 5) {
return {};
}
return std::make_unique<LostGame>();
}
......@@ -75,7 +78,6 @@ Fireball::Fireball(Direction direction, Room* room) {
}
void Fireball::draw_into(sf::RenderWindow& window) const {
//std::cout << "x = " << m_sprite.getPosition().x << "; y = " << m_sprite.getPosition().y << '\n';
window.draw(m_sprite);
}
......
......@@ -35,9 +35,10 @@ public:
std::vector<Fireball> m_spells;
private:
mutable float m_mp = config::PACMAN_START_MP;
Direction m_dir;
Direction m_dir = Direction::RIGHT;
sf::Sprite m_sprite;
Texture* m_ptr_tex;
sf::Clock m_clock;
};
......
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