File indexing completed on 2024-12-01 03:46:16
0001 /* 0002 SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "bonusitem.h" 0008 #include "bonus.h" 0009 0010 #include <QTimer> 0011 0012 #include <KGameRenderer> 0013 0014 BonusItem::BonusItem(Bonus* p_model, KGameRenderer* renderer) : ElementItem (p_model, renderer) 0015 { 0016 setSpriteKey(p_model->getImageId()); 0017 m_undestroyableExplosionID = 0; 0018 m_destructionTimer = nullptr; 0019 m_destructionCounter = 0; 0020 } 0021 0022 BonusItem::~BonusItem() 0023 { 0024 delete m_destructionTimer; 0025 } 0026 0027 void BonusItem::setUndestroyable(int nExplosionID) 0028 { 0029 m_undestroyableExplosionID = nExplosionID; 0030 } 0031 0032 void BonusItem::initDestruction(int nExplosionID) 0033 { 0034 if(m_undestroyableExplosionID == nExplosionID || dynamic_cast <Bonus*> (m_model)->isTaken()) 0035 { 0036 return; 0037 } 0038 0039 dynamic_cast <Bonus*> (m_model)->setDestroyed(); 0040 0041 m_destructionCounter = 0; 0042 m_destructionTimer = new QTimer(this); 0043 m_destructionTimer->setInterval(300); 0044 m_destructionTimer->start(); 0045 connect(m_destructionTimer, &QTimer::timeout, this, &BonusItem::destructionAnimation); 0046 } 0047 0048 void BonusItem::destructionAnimation() 0049 { 0050 m_destructionCounter++; 0051 m_destructionTimer->setInterval(50); 0052 setOpacity((5-m_destructionCounter)/5.0); 0053 if(m_destructionCounter >= 5) 0054 { 0055 m_destructionTimer->stop(); 0056 delete m_destructionTimer; 0057 m_destructionTimer = nullptr; 0058 Q_EMIT bonusItemDestroyed(this); 0059 } 0060 } 0061 0062 #include "moc_bonusitem.cpp"