summaryrefslogtreecommitdiffstats
path: root/pacman-c++/block.cpp
blob: 40876624db38b20b2b19c7e75c68cb182c60198d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "block.h"
#include "constants.h"
#include "actor.h"
#include "util.h"
#include <QtDebug>

QMap<Color::Color, QPixmap> 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 */)
{
  return (m_color != Color::none);
}

bool Block::enter(Actor *actor)
{
  if (m_color != actor->color())
  {
    //TODO: actor dies + game ends
  }
  return true;
}