File indexing completed on 2023-10-01 08:02:05
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> 0003 SPDX-FileCopyrightText: 2007-2008 Alexandre Galinier <alex.galinier@hotmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef GAMESCENE_H 0009 #define GAMESCENE_H 0010 0011 #include "elementitem.h" 0012 #include "game.h" 0013 #include "ghostitem.h" 0014 #include "kapmanitem.h" 0015 #include "mazeitem.h" 0016 0017 #include <QGraphicsScene> 0018 #include <QList> 0019 #include <QSvgRenderer> 0020 0021 class KgTheme; 0022 0023 /** 0024 * @brief This class contains all the Game elements to be drawn on the screen by the GameView instance. 0025 */ 0026 class GameScene : public QGraphicsScene 0027 { 0028 Q_OBJECT 0029 0030 private: 0031 /** The Game instance */ 0032 Game *m_game; 0033 0034 /** The KapmanItem to be drawn */ 0035 KapmanItem *m_kapmanItem; 0036 0037 /** The MazeItem to be drawn */ 0038 MazeItem *m_mazeItem; 0039 0040 /** The GhostItem of each Ghost to be drawn */ 0041 QList<GhostItem *> m_ghostItems; 0042 0043 /** The ElementItem to be drawn (each Pill and Energizers) */ 0044 ElementItem ***m_elementItems; 0045 0046 /** The Bonus ElementItem */ 0047 ElementItem *m_bonusItem; 0048 0049 /** A list with labels to display when a ghost or a bonus is eaten */ 0050 QList<QGraphicsTextItem *> m_wonPointsLabels; 0051 0052 /** The labels to be displayed during the game */ 0053 QGraphicsTextItem *m_introLabel; 0054 QGraphicsTextItem *m_introLabel2; 0055 QGraphicsTextItem *m_newLevelLabel; 0056 QGraphicsTextItem *m_pauseLabel; 0057 0058 /** The SVG renderer */ 0059 QSvgRenderer *m_renderer; 0060 0061 public: 0062 /** 0063 * Creates a new GameScene instance. 0064 * @param p_game the Game instance whose elements must be contained in the GameScene in order to be drawn 0065 */ 0066 GameScene(Game *p_game, const KgTheme *theme); 0067 0068 /** 0069 * Deletes the Game instance. 0070 */ 0071 ~GameScene() override; 0072 0073 /** 0074 * @return the Game instance 0075 */ 0076 Game *getGame() const; 0077 0078 /** 0079 * Loads the game theme. 0080 */ 0081 void loadTheme(const KgTheme *theme); 0082 0083 private Q_SLOTS: 0084 0085 /** 0086 * Updates the elements to be drawn on Game introduction. 0087 * @param p_newLevel true a new level has begun, false otherwise 0088 */ 0089 void intro(const bool p_newLevel); 0090 0091 /** 0092 * Updates the elements to be drawn when the Game starts. 0093 */ 0094 void start(); 0095 0096 /** 0097 * Updates the elements to be drawn considering the Game state (paused or running). 0098 * @param p_pause if true the Game has been paused, if false the Game has been resumed 0099 * @param p_fromUser if true the Game has been paused due to an action from the user 0100 */ 0101 void setPaused(const bool p_pause, const bool p_fromUser); 0102 0103 /** 0104 * Removes the Element at the given coordinates from the GameScene. 0105 * @param p_wonPoints value of the won Points, used when a ghost or a Bonus is eaten 0106 * @param p_x x-coordinate of the Element 0107 * @param p_y y-coordinate of the Element 0108 */ 0109 void hideElement(const qreal p_x, const qreal p_y); 0110 0111 /** 0112 * Displays the Bonus. 0113 */ 0114 void displayBonus(); 0115 0116 /** 0117 * Remove the Bonus from the GameScene. 0118 */ 0119 void hideBonus(); 0120 0121 /** 0122 * Display won Points on the scene when a Bonus or a Ghosts is eaten 0123 * @param p_wonPoints the value to display 0124 * @param p_xPos the position of the eaten element on X axis 0125 * @param p_yPos the position of the eaten element on Y axis 0126 */ 0127 void displayPoints(long p_wonPoints, qreal p_xPos, qreal p_yPos); 0128 0129 /** 0130 * Hide the first label in the list of won points labels 0131 */ 0132 void hidePoints(); 0133 0134 /** 0135 * Update theme id elements. 0136 */ 0137 void updateSvgIds(); 0138 0139 /** 0140 * Update theme properties. 0141 */ 0142 void updateThemeProperties(const KgTheme *theme); 0143 }; 0144 0145 #endif