Pacman.cpp 1.47 KiB
#include "pacman.h"
#include "../Context/Context.h"
//PACMAN
Pacman::Pacman() {
	m_circle = sf::CircleShape(config::GAME_PACMAN_SIZE/2);
	m_circle.setOrigin({ config::GAME_PACMAN_SIZE/2, config::GAME_PACMAN_SIZE/2 });
	m_circle.setFillColor(config::GAME_COLOR_PACMAN);
void Pacman::move(Room::Direction direction) {
	m_ptr_room->get_side(direction)->enter(this);
void Pacman::draw_into(sf::RenderWindow& window) const {
	window.draw(m_circle);
void Pacman::prepare_for_drawing() {
	m_circle.setPosition(m_ptr_room->get_position());
std::unique_ptr<IGameEvent> Pacman::visit(Food* ptr_food) {
	if (ptr_food->get_location() != this->get_location())
		return {};
	return std::make_unique<DeleteStaticEntity>(std::move(std::unique_ptr<IStaticEntity>(ptr_food)));
std::unique_ptr<IGameEvent> Pacman::visit(Enemy* ptr_enemy) {
	if (ptr_enemy->get_location() != this->get_location())
		return {};
	return std::make_unique<LostGame>();
//DELETESTATIC
DeleteStaticEntity::DeleteStaticEntity(std::unique_ptr<IStaticEntity> ptr) : m_ptr_entity(std::move(ptr)) {};
void DeleteStaticEntity::handle(GameContext& context) const {
	for (auto it = context.static_objects.begin(); it != context.static_objects.end(); ++it) {
		if (m_ptr_entity == (*it)) {
			context.static_objects.erase(it);
//LOSTGAME
void LostGame::handle(GameContext& context) const {
	context.state = GameContext::LOST;
//WINGAME
void WinGame::handle(GameContext& context) const {
	context.state = GameContext::WIN;