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

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 BOARD_H
0008 #define BOARD_H
0009 
0010 // Qt
0011 #include <QGraphicsScene>
0012 #include <QList>
0013 #include <QQueue>
0014 #include <QSize>
0015 
0016 // KDEGames
0017 #include <KGameRenderer>
0018 
0019 class Plane;
0020 class Building;
0021 class Bomb;
0022 
0023 /**
0024  * This class used to represent the game board. This makes sure all the game objects
0025  * get moved and redrawn every second. It also checks for any collisions
0026  */
0027 class BomberBoard : public QGraphicsScene
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     /**
0033      * The constructor used to create the board.
0034      * \param renderer The renderer used to render game objects
0035      * \param view The graphics view object which this board is bound to
0036      * \param parent The widget which the board is inserted into
0037      */
0038     explicit BomberBoard(KGameRenderer * renderer, QGraphicsView * view, QObject * parent = nullptr);
0039 
0040     ~BomberBoard() override;
0041 
0042     /**
0043      * This is called when the game board is resized
0044      * \param size The new tile size used on the game board
0045      */
0046     void resize(QSize & size);
0047 
0048     /**
0049      * This will redraw the game board
0050      */
0051     void redraw();
0052 
0053     /**
0054      * This is called to start a new level
0055      * \param level The level number been started
0056      */
0057     void newLevel(unsigned int level);
0058 
0059     /**
0060      * This is called to pause the game.
0061      * \param val True if paused, otherwise false
0062      */
0063     void setPaused(bool val);
0064 
0065     /**
0066      * This will convert the tile location to actual cords on the board
0067      * \param pos The cords relative to the tile
0068      * \return The cords relative to the widget
0069      */
0070     QPoint mapPosition(const QPointF & pos) const;
0071 
0072     /**
0073      * This will convert the widget location to tile locations
0074      * \param pos The cords relative to the widget
0075      * \return The cords relative to the tile
0076      */
0077     QPointF unmapPosition(const QPoint & pos) const;
0078 
0079     /**
0080      * Used to set the plane state to flying and move it to the start position
0081      */
0082     void resetPlane();
0083 
0084     /**
0085      * This will attempt to drop a bomb if their is not already a bomb dropping
0086      */
0087     void dropBomb();
0088 
0089 Q_SIGNALS:
0090     /**
0091      * This is emitted when a plane crashes into a building
0092      */
0093     void onPlaneCrash();
0094 
0095     void playBombSound();
0096     void playCrashSound();
0097 
0098     /**
0099      * This signal is emitted when a bomb hits a building and before it's exploding
0100      * animation starts
0101      */
0102     void onBombHit();
0103 
0104     /**
0105      * This is emitted when the level has been cleared of all buildings
0106      */
0107     void levelCleared();
0108 
0109 public Q_SLOTS:
0110     /**
0111      * This is called when the settings change to save the settings
0112      */
0113     void settingsChanged();
0114 
0115 private Q_SLOTS:
0116     /**
0117      * This is called once a second to update and draw all the game objects
0118      */
0119     void tick();
0120 
0121     /**
0122      * This is called when a plane has finished exploding
0123      */
0124     void planeExploded();
0125 
0126     /**
0127      * This is called when a bomb has finished exploding
0128      */
0129     void bombExploded();
0130 
0131 private:
0132     /**
0133      * This is called when a bomb hits a building
0134      * \param bomb The bomb that hit
0135      * \param moveBombToX The x position to move the explosion too
0136      * \param moveBombToY The y position to move the explosion too
0137      */
0138     void bombHit(Bomb * bomb, qreal moveBombToX, qreal moveBombToY);
0139 
0140     /**
0141      * This is used to remove all the current game objects, usually called before
0142      * stating a new level
0143      */
0144     void clear();
0145 
0146     /**
0147      * This is used to check for any collisions of the plane or bombs
0148      */
0149     void checkCollisions();
0150 
0151     /**
0152      * This is called when a plane crashes into a building
0153      */
0154     void crashed();
0155 
0156     /**
0157      * This is the renderer used to render game objects
0158      */
0159     KGameRenderer * m_renderer;
0160 
0161     /**
0162      * This is the size of a tiling block
0163      */
0164     QSize m_tileSize;
0165     QTimer * m_clock;
0166 
0167     /**
0168      * If their is a bomb currently dropping then it is pointed to by this
0169      */
0170     Bomb * m_bomb;
0171 
0172     /**
0173      * This points to the plane object used in the level
0174      */
0175     Plane * m_plane;
0176 
0177     /**
0178      * This contains all the buildings in the current level
0179      */
0180     QList<Building *> m_buildings;
0181 
0182     /**
0183      * This contains all the bombs that are currently exploding
0184      */
0185     QQueue<Bomb *> m_explodingBombs;
0186 
0187     /**
0188      * This is the number of blocks that make up the buildings
0189      */
0190     unsigned int m_buildingBlocks;
0191 
0192     /**
0193      * This is the graphics view object which this board is bound.
0194      */
0195     QGraphicsView * m_view;
0196 };
0197 
0198 #endif