1/*
2 * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
3 * Copyright 2007-2008 Alexandre Galinier <alex.galinier@hotmail.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef GAMESCENE_H
20#define GAMESCENE_H
21
22#include "game.h"
23#include "elementitem.h"
24#include "mazeitem.h"
25#include "ghostitem.h"
26#include "kapmanitem.h"
27
28#include <QGraphicsScene>
29#include <QList>
30#include <QSvgRenderer>
31
32#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
33#include <libkdegamesprivate/kgametheme.h>
34
35/**
36 * @brief This class contains all the Game elements to be drawn on the screen by the GameView instance.
37 */
38class GameScene : public QGraphicsScene {
39
40 Q_OBJECT
41
42 private:
43
44 /** The Game instance */
45 Game* m_game;
46
47 /** The KapmanItem to be drawn */
48 KapmanItem* m_kapmanItem;
49
50 /** The MazeItem to be drawn */
51 MazeItem* m_mazeItem;
52
53 /** The GhostItem of each Ghost to be drawn */
54 QList<GhostItem*> m_ghostItems;
55
56 /** The ElementItem to be drawn (each Pill and Energizers) */
57 ElementItem*** m_elementItems;
58
59 /** The Bonus ElementItem */
60 ElementItem* m_bonusItem;
61
62 /** A list with labels to display when a ghost or a bonus is eaten */
63 QList<QGraphicsTextItem*> m_wonPointsLabels;
64
65 /** The labels to be displayed during the game */
66 QGraphicsTextItem* m_introLabel;
67 QGraphicsTextItem* m_introLabel2;
68 QGraphicsTextItem* m_newLevelLabel;
69 QGraphicsTextItem* m_pauseLabel;
70
71 /** The SVG renderer */
72 QSvgRenderer* m_renderer;
73
74 /** The Game theme */
75 KGameTheme* m_theme;
76
77 public:
78
79 /**
80 * Creates a new GameScene instance.
81 * @param p_game the Game instance whose elements must be contained in the GameScene in order to be drawn
82 */
83 GameScene(Game* p_game);
84
85 /**
86 * Deletes the Game instance.
87 */
88 ~GameScene();
89
90 /**
91 * @return the Game instance
92 */
93 Game* getGame() const;
94
95 /**
96 * Loads the game theme.
97 */
98 void loadTheme();
99
100 private slots:
101
102 /**
103 * Updates the elements to be drawn on Game introduction.
104 * @param p_newLevel true a new level has begun, false otherwise
105 */
106 void intro(const bool p_newLevel);
107
108 /**
109 * Updates the elements to be drawn when the Game starts.
110 */
111 void start();
112
113 /**
114 * Updates the elements to be drawn considering the Game state (paused or running).
115 * @param p_pause if true the Game has been paused, if false the Game has been resumed
116 * @param p_fromUser if true the Game has been paused due to an action from the user
117 */
118 void setPaused(const bool p_pause, const bool p_fromUser);
119
120 /**
121 * Removes the Element at the given coordinates from the GameScene.
122 * @param p_wonPoints value of the won Points, used when a ghost or a Bonus is eaten
123 * @param p_x x-coordinate of the Element
124 * @param p_y y-coordinate of the Element
125 */
126 void hideElement(const qreal p_x, const qreal p_y);
127
128 /**
129 * Displays the Bonus.
130 */
131 void displayBonus();
132
133 /**
134 * Remove the Bonus from the GameScene.
135 */
136 void hideBonus();
137
138 /**
139 * Display won Points on the scene when a Bonus or a Ghosts is eaten
140 * @param p_wonPoints the value to display
141 * @param p_xPos the position of the eaten element on X axis
142 * @param p_yPos the position of the eaten element on Y axis
143 */
144 void displayPoints(long p_wonPoints, qreal p_xPos, qreal p_yPos);
145
146 /**
147 * Hide the first label in the list of won points labels
148 */
149 void hidePoints();
150
151 /**
152 * Update theme id elements.
153 */
154 void updateSvgIds();
155
156 /**
157 * Update theme properties.
158 */
159 void updateThemeProperties();
160};
161
162#endif
163
164