1 /*
2     SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de>
3     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
4     SPDX-FileCopyrightText: 2007-2008 Pierre-Benoît Besse <besse.pb@gmail.com>
5 
6     SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 
9 #ifndef BOMB_H
10 #define BOMB_H
11 
12 #include "element.h"
13 
14 class QTimer;
15 
16 /**
17  * @brief This class describes the common characteristics and behaviour of the bomb item.
18  */
19 class Bomb : public Element
20 {
21 
22     Q_OBJECT
23 
24 protected:
25 
26     /** The Bomb x-speed */
27     qreal m_xSpeed;
28 
29     /** The Bomb y-speed */
30     qreal m_ySpeed;
31 
32     /** The Bomb speed */
33     qreal m_speed;
34 
35     /** The Bomb detonation has already started */
36     bool m_detonated;
37 
38     /** The Bomb detonation power */
39     int m_bombPower;
40 
41     /** The Bomb ID */
42     int m_bombID;
43 
44     /** The ID of the Bomb that causes the explosion */
45     int m_explosionID;
46 
47     /** Timer used to make the bomb detonate */
48     QTimer* m_detonationCountdownTimer;
49 
50     /** Timer used for the throw bonus and mortar */
51     QTimer* m_mortarTimer;
52 
53     int m_mortarState;
54 
55     bool m_thrown;
56     bool m_stopOnCenter;
57 
58     bool m_falling;
59 
60 public:
61 
62     /**
63     * Creates a new Bomb instance.
64     * @param fX the initial x-coordinate
65     * @param fY the initial y-coordinate
66     * @param p_arena the Arena the Bomb is on
67     * @param nBombID the unique bomb ID
68     * @param nDetonationCountdown the time until detonation
69     */
70     Bomb(qreal fX, qreal fY, Arena* p_arena, int nBombID, int nDetonationCountdown);
71 
72     /**
73     * Deletes the Bomb instance.
74     */
75     ~Bomb() override;
76 
77     /**
78     * Makes the Bomb go up.
79     */
80     void goUp();
81 
82     /**
83     * Makes the Bomb go down.
84     */
85     void goDown();
86 
87     /**
88     * Makes the Bomb go to the right.
89     */
90     void goRight();
91 
92     /**
93     * Makes the Bomb go to the left.
94     */
95     void goLeft();
96 
97     /**
98     * Updates the Bomb move.
99     */
100     void updateMove();
101 
102     /**
103     * Moves the Bomb function of its current coordinates and speed.
104     * If the Bomb reaches a border, it circles around the arena and continue its way from the other side.
105     */
106     void move(qreal x, qreal y);
107 
108     /**
109     * Gets the Bomb x-speed value.
110     * @return the x-speed value
111     */
112     qreal getXSpeed() const;
113 
114     /**
115     * Gets the Bomb y-speed value.
116     * @return the y-speed value
117     */
118     qreal getYSpeed() const;
119 
120     /**
121     * Gets the Bomb speed.
122     * @return the Bomb speed
123     */
124     qreal getSpeed();
125 
126     /**
127     * Set the Bomb x-speed value.
128     * @param p_xSpeed the x-speed to set
129     */
130     void setXSpeed(qreal p_xSpeed);
131 
132     /**
133     * Set the Bomb y-speed value.
134     * @param p_ySpeed the y-speed to set
135     */
136     void setYSpeed(qreal p_ySpeed);
137 
138     /**
139     * The direction to throw
140     * @param nDirection direction
141     */
142     void setThrown(int nDirection);
143 
144     /**
145     * The direction to move
146     * @param nDirection direction
147     */
148     void setKicked(int nDirection);
149 
150     /**
151     * Power of the bomb
152     * @return the Bomb power
153     */
154     int bombPower();
155 
156     /**
157     * Sets the Power of the bomb
158     * @param bombPower the Bomb power
159     */
160     void setBombPower(int bombPower);
161 
162     /**
163     * @return state if the bomb is already detonated
164     */
165     bool isDetonated();
166 
167     /**
168     * sets the explosion ID and detonation countdown
169     * @param nBombID the Bomb ID that causes the detonation
170     * @param nDetonationTimeout the new detonation timeout
171     */
172     void initDetonation(int nBombID, int nDetonationTimeout);
173 
174     /**
175     * @return the explosion ID
176     */
177     int explosionID();
178 
179     /**
180     * Pauses bomb timer.
181     */
182     void pause();
183 
184     /**
185     * Resumes bomb timer.
186     */
187     void resume();
188 
189 public Q_SLOTS:
190     /**
191     * Manages the Bomb explosion
192     */
193     void detonate();
194 
195     void slot_detonationCompleted();
196 
197     void updateMortarState();
198 
199 protected:
200 
201     /**
202     * Checks the Bomb gets on a Cell center during its next movement.
203     * @return true if the Bomb is on a Cell center, false otherwise
204     */
205     bool onCenter();
206 
207     /**
208     * Moves the Bomb on the center of its current Cell.
209     */
210     void moveOnCenter();
211 
212 Q_SIGNALS:
213     /**
214     * Emitted when the Bomb is exploded.
215     * @param bomb this bomb
216     */
217     void bombDetonated(Bomb* bomb);
218 
219     /**
220     * Emitted to refill the player bomb armory
221     */
222     void releaseBombArmory();
223 
224     /**
225     * Emitted when the Bomb is thrown by the mortar or by the player.
226     * @param nMortarState the current state of the mortar
227     * @param nMortarRampEnd the mortar ramp end
228     * @param nMortarPeak the mortar peak
229     * @param nMortarGround the mortar ground
230     */
231     void mortar(int nMortarState, int nMortarRampEnd, int nMortarPeak, int nMortarGround);
232 
233     /**
234     * Emitted when the bomb is falling in a hole
235     */
236     void falling();
237 };
238 
239 #endif
240 
241