From ce48af53646cd9e7ec762fc1ac176b3aa620b11d Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 5 May 2011 00:57:07 +0200 Subject: - refactorized the whole project and made a few subprojects - replaced tcp with enet - added connect dialog - some smaller bugfixes --- pacman-c++/common/block.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 pacman-c++/common/block.cpp (limited to 'pacman-c++/common/block.cpp') diff --git a/pacman-c++/common/block.cpp b/pacman-c++/common/block.cpp new file mode 100644 index 0000000..7f9dd14 --- /dev/null +++ b/pacman-c++/common/block.cpp @@ -0,0 +1,56 @@ +#include "block.h" +#include "constants.h" +#include "actor.h" +#include "util.h" +#include + +QMap Block::m_pixmaps; + +Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent) + : GameEntity(color, parent), m_neighbours(neighbours) +{ + m_type = Type; + + /* empty object for servers */ + if (Constants::server) + return; + + if (m_pixmaps.find(color) == m_pixmaps.end()) + { + unsigned int colid = (color == Color::none) ? 0 : Util::floorLog2(color) + 1; + QString pixmapName = ":/" + QString("block%1").arg(colid); + m_pixmaps[color] = QPixmap(pixmapName); + } + setPixmap(m_pixmaps.find(color).value()); + setNeighbours(m_neighbours); +} + +unsigned int Block::neighbours() +{ + return m_neighbours; +} + +void Block::setNeighbours(unsigned int neighbours) +{ + m_neighbours = neighbours; + setSprite(neighbours * Constants::sprite_offset, 0, Constants::field_size.width, Constants::field_size.height); +} + +bool Block::checkEnter(Actor * /* actor */) +{ + if (m_color == Color::none) + return false; + return true; +} + +GameEntity::EnteredState Block::enter(Actor *actor) +{ + if (m_color != Color::none && m_color != actor->color()) + return DestroyedActor; + return Nothing; +} + +void Block::onDie(Actor *actor) +{ + actor->die(); +} -- cgit v1.2.3