File indexing completed on 2024-05-05 04:02:04
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 John-Paul Stanford <jp@stanwood.org.uk> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef EXPLODABLE_H 0008 #define EXPLODABLE_H 0009 0010 // KDEGames 0011 #include <KGameRenderedItem> 0012 0013 class BomberBoard; 0014 0015 /** 0016 * This is a game object that can explode. 0017 */ 0018 class Explodable : public KGameRenderedItem 0019 { 0020 public: 0021 /** The states that a bomb can be in */ 0022 enum class State { 0023 Moving, 0024 Exploding, 0025 Exploded 0026 }; 0027 0028 /** The width of the explosion relative to the tile */ 0029 static const qreal EXPLOSION_RELATIVE_SIZE_W; 0030 /** The height of the explosion relative to the tile */ 0031 static const qreal EXPLOSION_RELATIVE_SIZE_H; 0032 0033 explicit Explodable(const QString & mainSvg, const QString & explosionSvg, 0034 qreal relativeWidth, qreal relativeHeight, 0035 KGameRenderer * renderer, BomberBoard * board); 0036 ~Explodable() override; 0037 0038 /** 0039 * Updates bomb position and pixmap. 0040 * This method is called once per frame. 0041 */ 0042 void update(); 0043 0044 /** 0045 * Sets width and height of bomb. Using the current tile size. 0046 * \param tileSize The size of the tile 0047 */ 0048 void resize(const QSize & tileSize); 0049 0050 /** 0051 * Sets the velocity of the explodable object 0052 * \param velocity The velocity of the object 0053 */ 0054 void setVelocity(qreal velocity); 0055 0056 /** 0057 * Used to get the velocity of the explodable object 0058 * \return The velocity 0059 */ 0060 qreal velocity() const; 0061 0062 /** 0063 * Rechecks the number of frames of bomb animation and sets new pixmaps. 0064 * This method is useful when changing game theme. 0065 */ 0066 void resetPixmaps(); 0067 0068 /** 0069 * Used to set the bomb's position 0070 * \param xPos Set the x position of the item 0071 * \param yPos Set the y position of the item 0072 */ 0073 void setPosition(qreal xPos, qreal yPos); 0074 0075 /** 0076 * Return the position of the bomb 0077 * \return The position of the bomb 0078 */ 0079 QPointF position() const; 0080 0081 /** 0082 * Set the current frame to a random frame from the frame set 0083 */ 0084 void setRandomFrame(); 0085 0086 /** 0087 * Returns bomb's bounding rect expected in next frame 0088 * used by collision test 0089 * \return The items next bounding rect 0090 */ 0091 QRectF nextBoundingRect() const; 0092 0093 /** 0094 * Get the current state of the bomb 0095 * \return The current state of the bomb 0096 */ 0097 Explodable::State state() const; 0098 0099 /** 0100 * Set the current state of the bomb 0101 * \param state The state to set the bomb too 0102 */ 0103 void setState(Explodable::State state); 0104 0105 protected: 0106 qreal m_xPos; 0107 qreal m_yPos; 0108 QRectF m_nextBoundingRect; 0109 0110 private: 0111 BomberBoard * m_board; 0112 0113 qreal m_velocity; 0114 0115 /** 0116 * The state the bomb is currently in 0117 */ 0118 State m_state; 0119 0120 /** The tile size last time the bomb was resized */ 0121 QSize m_lastSize; 0122 0123 qreal m_relativeHeight; 0124 qreal m_relativeWidth; 0125 QString m_mainSvg; 0126 QString m_explosionSvg; 0127 }; 0128 0129 #endif