• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

granatier

  • sources
  • kde-4.14
  • kdegames
  • granatier
  • src
bonusitem.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "bonusitem.h"
19 #include "bonus.h"
20 
21 #include <QTimer>
22 
23 #include <KGameRenderer>
24 
25 BonusItem::BonusItem(Bonus* p_model, KGameRenderer* renderer) : ElementItem (p_model, renderer)
26 {
27  setSpriteKey(p_model->getImageId());
28  m_undestroyableExplosionID = 0;
29  m_destructionTimer = NULL;
30  m_destructionCounter = 0;
31 }
32 
33 BonusItem::~BonusItem()
34 {
35  delete m_destructionTimer;
36 }
37 
38 void BonusItem::setUndestroyable(int nExplosionID)
39 {
40  m_undestroyableExplosionID = nExplosionID;
41 }
42 
43 void BonusItem::initDestruction(int nExplosionID)
44 {
45  if(m_undestroyableExplosionID == nExplosionID || dynamic_cast <Bonus*> (m_model)->isTaken())
46  {
47  return;
48  }
49 
50  dynamic_cast <Bonus*> (m_model)->setDestroyed();
51 
52  m_destructionCounter = 0;
53  m_destructionTimer = new QTimer(this);
54  m_destructionTimer->setInterval(300);
55  m_destructionTimer->start();
56  connect(m_destructionTimer, SIGNAL(timeout()), this, SLOT(destructionAnimation()));
57 }
58 
59 void BonusItem::destructionAnimation()
60 {
61  m_destructionCounter++;
62  m_destructionTimer->setInterval(50);
63  setOpacity((5-m_destructionCounter)/5.0);
64  if(m_destructionCounter >= 5)
65  {
66  m_destructionTimer->stop();
67  delete m_destructionTimer;
68  m_destructionTimer = 0;
69  emit bonusItemDestroyed(this);
70  }
71 }
QTimer::setInterval
void setInterval(int msec)
Bonus
This class represents a Bonus for the Player.
Definition: bonus.h:29
BonusItem::~BonusItem
~BonusItem()
Deletes the BonusItem instance.
Definition: bonusitem.cpp:33
Element::getImageId
QString getImageId() const
Gets the path to the Element image.
Definition: element.cpp:73
bonusitem.h
QTimer
ElementItem::m_model
Element * m_model
The instance of Element the ElementItem will represent.
Definition: elementitem.h:40
BonusItem::setUndestroyable
void setUndestroyable(int nExplosionID)
Sets the undestroyable explosion IDs.
Definition: bonusitem.cpp:38
ElementItem
This class is the graphical representation of a game Element.
Definition: elementitem.h:30
BonusItem::initDestruction
void initDestruction(int nExplosionID)
Inits the destruction.
Definition: bonusitem.cpp:43
BonusItem::bonusItemDestroyed
void bonusItemDestroyed(BonusItem *bonusItem)
signals the end of the destruction animation
bonus.h
QTimer::stop
void stop()
QTimer::start
void start(int msec)
BonusItem::BonusItem
BonusItem(Bonus *p_model, KGameRenderer *renderer)
Creates a new BonusItem instance.
Definition: bonusitem.cpp:25
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

granatier

Skip menu "granatier"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal