File indexing completed on 2024-02-18 04:03:23

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 "blockitem.h"
0008 #include "block.h"
0009 
0010 #include <QTimer>
0011 
0012 #include <KGameRenderer>
0013 
0014 BlockItem::BlockItem(Block* p_model, KGameRenderer* renderer) : ElementItem (p_model, renderer)
0015 {
0016     setSpriteKey(p_model->getImageId());
0017     m_destructionTimer = nullptr;
0018     connect(p_model, &Block::startDestructionAnimation, this, &BlockItem::startDestructionAnimation);
0019 }
0020 
0021 BlockItem::~BlockItem()
0022 {
0023     delete m_destructionTimer;
0024 }
0025 
0026 void BlockItem::startDestructionAnimation()
0027 {
0028     m_destructionCounter = 0;
0029     m_destructionTimer = new QTimer(this);
0030     m_destructionTimer->setInterval(300);
0031     m_destructionTimer->start();
0032     connect(m_destructionTimer, &QTimer::timeout, this, &BlockItem::destructionAnimation);
0033 
0034     setSpriteKey(QStringLiteral("arena_block_highlight"));
0035 }
0036 
0037 void BlockItem::destructionAnimation()
0038 {
0039     m_destructionCounter++;
0040     m_destructionTimer->setInterval(50);
0041     setOpacity((5-m_destructionCounter)/5.0);
0042     if(m_destructionCounter >= 5)
0043     {
0044         m_destructionTimer->stop();
0045         delete m_destructionTimer;
0046         m_destructionTimer = nullptr;
0047         Q_EMIT blockItemDestroyed(this);
0048     }
0049 }
0050 
0051 #include "moc_blockitem.cpp"