• 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
blockitem.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 "blockitem.h"
19 #include "block.h"
20 
21 #include <QTimer>
22 
23 #include <KGameRenderer>
24 
25 BlockItem::BlockItem(Block* p_model, KGameRenderer* renderer) : ElementItem (p_model, renderer)
26 {
27  setSpriteKey(p_model->getImageId());
28  m_destructionTimer = NULL;
29  connect(p_model, SIGNAL(startDestructionAnimation()), this, SLOT(startDestructionAnimation()));
30 }
31 
32 BlockItem::~BlockItem()
33 {
34  delete m_destructionTimer;
35 }
36 
37 void BlockItem::startDestructionAnimation()
38 {
39  m_destructionCounter = 0;
40  m_destructionTimer = new QTimer(this);
41  m_destructionTimer->setInterval(300);
42  m_destructionTimer->start();
43  connect(m_destructionTimer, SIGNAL(timeout()), this, SLOT(destructionAnimation()));
44 
45  setSpriteKey("arena_block_highlight");
46 }
47 
48 void BlockItem::destructionAnimation()
49 {
50  m_destructionCounter++;
51  m_destructionTimer->setInterval(50);
52  setOpacity((5-m_destructionCounter)/5.0);
53  if(m_destructionCounter >= 5)
54  {
55  m_destructionTimer->stop();
56  delete m_destructionTimer;
57  m_destructionTimer = 0;
58  emit blockItemDestroyed(this);
59  }
60 }
QTimer::setInterval
void setInterval(int msec)
BlockItem::blockItemDestroyed
void blockItemDestroyed(BlockItem *blockItem)
signals the end of the destruction animation
BlockItem::m_destructionTimer
QTimer * m_destructionTimer
Timer used to animate explosion.
Definition: blockitem.h:38
BlockItem::m_destructionCounter
int m_destructionCounter
Number of frames for the destruction.
Definition: blockitem.h:41
BlockItem::BlockItem
BlockItem(Block *p_model, KGameRenderer *renderer)
Creates a new BlockItem instance.
Definition: blockitem.cpp:25
Element::getImageId
QString getImageId() const
Gets the path to the Element image.
Definition: element.cpp:73
QTimer
BlockItem::~BlockItem
~BlockItem()
Deletes the BlockItem instance.
Definition: blockitem.cpp:32
ElementItem
This class is the graphical representation of a game Element.
Definition: elementitem.h:30
QTimer::stop
void stop()
QTimer::start
void start(int msec)
blockitem.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Block
This class represents a block with the possibility of a bonus inside.
Definition: block.h:30
block.h
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