File indexing completed on 2024-05-05 04:02:09

0001 /*
0002     SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de>
0003     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef BOMBITEM_H
0009 #define BOMBITEM_H
0010 
0011 #include "elementitem.h"
0012 
0013 class Bomb;
0014 class QTimer;
0015 class KGameRenderer;
0016 
0017 /**
0018  * @brief This class is the graphical representation of a Bomb.
0019  */
0020 class BombItem : public ElementItem
0021 {
0022 
0023     Q_OBJECT
0024 
0025     friend class GameScene;
0026 
0027 protected:
0028 
0029     /** Timer used to make the bomb pulse */
0030     QTimer* m_pulseTimer;
0031 
0032     /** Timer used to animate explosion */
0033     QTimer* m_explosionTimer;
0034 
0035     /** Timing for the explosion */
0036     QList <int> m_listExplosionTiming;
0037 
0038     /** Counter for the animaton frames */
0039     int m_animationCounter;
0040 
0041     /** Counter for falling animation */
0042     int m_fallingAnimationCounter;
0043 
0044     /** Flag to stop the animation if the bomb is fallin in a hole or TODO: a dud bomb */
0045     bool m_dudBomb;
0046 
0047     int m_x;
0048     int m_y;
0049 
0050 public:
0051 
0052     /**
0053      * Creates a new BombItem instance.
0054      * @param p_model the Bomb model
0055      * @param renderer the KGameRenderer
0056      */
0057     BombItem(Bomb* p_model, KGameRenderer* renderer);
0058 
0059     /**
0060      * Deletes the BombItem instance.
0061      */
0062     ~BombItem() override;
0063 
0064     /**
0065      * Overrides the default shape function to make it a small circle
0066      * This function is used to determinate collision between items
0067      * @return QPainterPath the new shape of the Bomb
0068      */
0069     QPainterPath shape() const override;
0070 
0071     /**
0072      * Pauses the BombItem animation.
0073      */
0074     void pauseAnim();
0075 
0076     /**
0077      * Resumes the BombItem animation.
0078      */
0079     void resumeAnim();
0080 
0081 public Q_SLOTS:
0082 
0083     /**
0084      * Updates the BombItem coordinates.
0085      * @param p_x the new x-coordinate
0086      * @param p_y the new y-coordinate
0087      */
0088     void update(qreal p_x, qreal p_y) override;
0089 
0090 private Q_SLOTS:
0091     /**
0092      * Starts the bomb detonation
0093      */
0094     virtual void startDetonation();
0095 
0096     /**
0097      * Makes the bomb pulse
0098      */
0099     virtual void pulse();
0100 
0101     /**
0102     * Animates the explosion
0103     */
0104     virtual void updateAnimation();
0105 
0106     /**
0107      * Animates the mortar
0108      */
0109     void updateMortarAnimation(int animationCounter, int nMortarRampEnd, int nMortarPeak);
0110 
0111     /**
0112     * Animates the explosion
0113     */
0114     virtual void updateMortar(int nMortarState, int nMortarRampEnd, int nMortarPeak, int nMortarGround);
0115 
0116     /**
0117     * the animation when falling in a hole
0118     */
0119     virtual void fallingAnimation();
0120 
0121 Q_SIGNALS:
0122     /**
0123      * signals end of the explosion
0124      * @param bombItem this bombItem
0125      */
0126     void bombItemFinished(BombItem* bombItem);  //explosion finished
0127 
0128     /**
0129      * signals next animation frame
0130      * @param bombItem this BombItem
0131      * @param nFrame the next animation frame
0132      */
0133     void animationFrameChanged(BombItem* bombItem, int nFrame);
0134 };
0135 
0136 #endif
0137