summaryrefslogtreecommitdiffstats
path: root/pacman-c++/bonuspoint.cpp
blob: 5bb470e6be7dfc69291162d31cc9ca9eda8d5b06 (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
#include "bonuspoint.h"
#include "constants.h"
#include "actor.h"

#define BONUSPOINTS_NUM_SPRITES 4

namespace
{
  QPixmap *pixmap = NULL;
}

BonusPoint::BonusPoint(QGraphicsItem *parent)
  : GameEntity(parent)
{
  /* empty object for servers */
  if (Constants::server)
    return;

  if (pixmap == NULL)
    pixmap = new QPixmap(":/bonuspoints");
  setPixmap(*pixmap);

  int rand = (int) (BONUSPOINTS_NUM_SPRITES * (qrand() / (RAND_MAX + 1.0)));
  setSprite(rand * 20 + Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height);
}

bool BonusPoint::enter(Actor* actor)
{
  actor->addRoundPoints(Constants::Game::bonus_point_value);
  m_eaten = true;
  return false;
}

void BonusPoint::onDie(Actor *actor)
{
  qDebug() << "here comes the cherry.. ";
  actor->eatingCherry();
}