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

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 BOMBEXPLOSIONITEM_H
0009 #define BOMBEXPLOSIONITEM_H
0010 
0011 #include "granatierglobals.h"
0012 
0013 #include <KGameRenderedItem>
0014 
0015 class Bomb;
0016 class KGameRenderer;
0017 
0018 /**
0019  * @brief This class is the graphical representation of a Bomb explosion.
0020  */
0021 class BombExplosionItem : public QObject, public KGameRenderedItem
0022 {
0023 
0024 Q_OBJECT
0025 
0026 public:
0027 
0028 protected:
0029 
0030     /** The direction of the blast */
0031     Granatier::Direction::Type m_direction;
0032 
0033     /** The bomb power */
0034     int m_bombPower;
0035 
0036     /** The ID of the Bomb that causes the explosion */
0037     int m_explosionID;
0038 
0039     /** The scale factor from the svg for the pixmap */
0040     qreal m_svgScaleFactor;
0041 
0042     QSize m_itemSizeSet;
0043     QSize m_itemSizeReal;
0044 
0045 public:
0046 
0047     /**
0048      * Creates a new BombExplosionItem instance.
0049      * @param p_model the Bomb model
0050      * @param direction the dirction of the explosion
0051      * @param bombPower the power of the bomb at the position of this BombExplosionItem
0052      * @param renderer the KGameRenderer
0053      * @param svgScaleFactor the scale factor of the pixmap
0054      */
0055     BombExplosionItem(Bomb* p_model, Granatier::Direction::Type direction, int bombPower, KGameRenderer* renderer, qreal svgScaleFactor);
0056 
0057     /**
0058      * Deletes the BombExplosionItem instance.
0059      */
0060     ~BombExplosionItem() override;
0061 
0062     /**
0063      * Overrides the default shape function to make it a small circle
0064      * This function is used to determinate collision between items
0065      * @return QPainterPath the new shape of the Bomb
0066      */
0067     QPainterPath shape() const override;
0068 
0069     /**
0070     * @return the explosion ID
0071     */
0072     int explosionID();
0073 
0074     /**
0075      * Updates the BombExplosionItem coordinates.
0076      * @param p_x the new x-coordinate
0077      * @param p_y the new y-coordinate
0078      */
0079     virtual void setPosition(qreal p_x, qreal p_y);
0080 
0081     /**
0082      * updates the animation
0083      * @param nFrame the next animation frame
0084      */
0085      void updateAnimationn(int nFrame);
0086 
0087 public Q_SLOTS:
0088 
0089     /**
0090      * Updates the graphics after a resize
0091      * @param svgScaleFactor the scaling factor between svg and rendered pixmap
0092      */
0093     virtual void updateGraphics(qreal svgScaleFactor);
0094 };
0095 
0096 #endif
0097