File indexing completed on 2024-12-08 03:45:36
0001 /* 0002 SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de> 0003 SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> 0004 SPDX-FileCopyrightText: 2007-2008 Pierre-BenoƮt Besse <besse.pb@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef BOMB_H 0010 #define BOMB_H 0011 0012 #include "element.h" 0013 0014 class QTimer; 0015 0016 /** 0017 * @brief This class describes the common characteristics and behaviour of the bomb item. 0018 */ 0019 class Bomb : public Element 0020 { 0021 0022 Q_OBJECT 0023 0024 protected: 0025 0026 /** The Bomb x-speed */ 0027 qreal m_xSpeed; 0028 0029 /** The Bomb y-speed */ 0030 qreal m_ySpeed; 0031 0032 /** The Bomb speed */ 0033 qreal m_speed; 0034 0035 /** The Bomb detonation has already started */ 0036 bool m_detonated; 0037 0038 /** The Bomb detonation power */ 0039 int m_bombPower; 0040 0041 /** The Bomb ID */ 0042 int m_bombID; 0043 0044 /** The ID of the Bomb that causes the explosion */ 0045 int m_explosionID; 0046 0047 /** Timer used to make the bomb detonate */ 0048 QTimer* m_detonationCountdownTimer; 0049 0050 /** Timer used for the throw bonus and mortar */ 0051 QTimer* m_mortarTimer; 0052 0053 int m_mortarState; 0054 0055 bool m_thrown; 0056 bool m_stopOnCenter; 0057 0058 bool m_falling; 0059 0060 public: 0061 0062 /** 0063 * Creates a new Bomb instance. 0064 * @param fX the initial x-coordinate 0065 * @param fY the initial y-coordinate 0066 * @param p_arena the Arena the Bomb is on 0067 * @param nBombID the unique bomb ID 0068 * @param nDetonationCountdown the time until detonation 0069 */ 0070 Bomb(qreal fX, qreal fY, Arena* p_arena, int nBombID, int nDetonationCountdown); 0071 0072 /** 0073 * Deletes the Bomb instance. 0074 */ 0075 ~Bomb() override; 0076 0077 /** 0078 * Makes the Bomb go up. 0079 */ 0080 void goUp(); 0081 0082 /** 0083 * Makes the Bomb go down. 0084 */ 0085 void goDown(); 0086 0087 /** 0088 * Makes the Bomb go to the right. 0089 */ 0090 void goRight(); 0091 0092 /** 0093 * Makes the Bomb go to the left. 0094 */ 0095 void goLeft(); 0096 0097 /** 0098 * Updates the Bomb move. 0099 */ 0100 void updateMove(); 0101 0102 /** 0103 * Moves the Bomb function of its current coordinates and speed. 0104 * If the Bomb reaches a border, it circles around the arena and continue its way from the other side. 0105 */ 0106 void move(qreal x, qreal y); 0107 0108 /** 0109 * Gets the Bomb x-speed value. 0110 * @return the x-speed value 0111 */ 0112 qreal getXSpeed() const; 0113 0114 /** 0115 * Gets the Bomb y-speed value. 0116 * @return the y-speed value 0117 */ 0118 qreal getYSpeed() const; 0119 0120 /** 0121 * Gets the Bomb speed. 0122 * @return the Bomb speed 0123 */ 0124 qreal getSpeed(); 0125 0126 /** 0127 * Set the Bomb x-speed value. 0128 * @param p_xSpeed the x-speed to set 0129 */ 0130 void setXSpeed(qreal p_xSpeed); 0131 0132 /** 0133 * Set the Bomb y-speed value. 0134 * @param p_ySpeed the y-speed to set 0135 */ 0136 void setYSpeed(qreal p_ySpeed); 0137 0138 /** 0139 * The direction to throw 0140 * @param nDirection direction 0141 */ 0142 void setThrown(int nDirection); 0143 0144 /** 0145 * The direction to move 0146 * @param nDirection direction 0147 */ 0148 void setKicked(int nDirection); 0149 0150 /** 0151 * Power of the bomb 0152 * @return the Bomb power 0153 */ 0154 int bombPower(); 0155 0156 /** 0157 * Sets the Power of the bomb 0158 * @param bombPower the Bomb power 0159 */ 0160 void setBombPower(int bombPower); 0161 0162 /** 0163 * @return state if the bomb is already detonated 0164 */ 0165 bool isDetonated(); 0166 0167 /** 0168 * sets the explosion ID and detonation countdown 0169 * @param nBombID the Bomb ID that causes the detonation 0170 * @param nDetonationTimeout the new detonation timeout 0171 */ 0172 void initDetonation(int nBombID, int nDetonationTimeout); 0173 0174 /** 0175 * @return the explosion ID 0176 */ 0177 int explosionID(); 0178 0179 /** 0180 * Pauses bomb timer. 0181 */ 0182 void pause(); 0183 0184 /** 0185 * Resumes bomb timer. 0186 */ 0187 void resume(); 0188 0189 public Q_SLOTS: 0190 /** 0191 * Manages the Bomb explosion 0192 */ 0193 void detonate(); 0194 0195 void slot_detonationCompleted(); 0196 0197 void updateMortarState(); 0198 0199 protected: 0200 0201 /** 0202 * Checks the Bomb gets on a Cell center during its next movement. 0203 * @return true if the Bomb is on a Cell center, false otherwise 0204 */ 0205 bool onCenter(); 0206 0207 /** 0208 * Moves the Bomb on the center of its current Cell. 0209 */ 0210 void moveOnCenter(); 0211 0212 Q_SIGNALS: 0213 /** 0214 * Emitted when the Bomb is exploded. 0215 * @param bomb this bomb 0216 */ 0217 void bombDetonated(Bomb* bomb); 0218 0219 /** 0220 * Emitted to refill the player bomb armory 0221 */ 0222 void releaseBombArmory(); 0223 0224 /** 0225 * Emitted when the Bomb is thrown by the mortar or by the player. 0226 * @param nMortarState the current state of the mortar 0227 * @param nMortarRampEnd the mortar ramp end 0228 * @param nMortarPeak the mortar peak 0229 * @param nMortarGround the mortar ground 0230 */ 0231 void mortar(int nMortarState, int nMortarRampEnd, int nMortarPeak, int nMortarGround); 0232 0233 /** 0234 * Emitted when the bomb is falling in a hole 0235 */ 0236 void falling(); 0237 }; 0238 0239 #endif 0240