File: gamescene.h

package info (click to toggle)
kapman 4:20.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,588 kB
  • sloc: cpp: 2,793; xml: 208; makefile: 8; sh: 2
file content (164 lines) | stat: -rw-r--r-- 4,326 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
 * Copyright 2007-2008 Alexandre Galinier <alex.galinier@hotmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GAMESCENE_H
#define GAMESCENE_H

#include "game.h"
#include "elementitem.h"
#include "mazeitem.h"
#include "ghostitem.h"
#include "kapmanitem.h"

#include <QGraphicsScene>
#include <QList>
#include <QSvgRenderer>

#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
#include <libkdegamesprivate/kgametheme.h>

/**
 * @brief This class contains all the Game elements to be drawn on the screen by the GameView instance.
 */
class GameScene : public QGraphicsScene
{

    Q_OBJECT

private:

    /** The Game instance */
    Game *m_game;

    /** The KapmanItem to be drawn */
    KapmanItem *m_kapmanItem;

    /** The MazeItem to be drawn */
    MazeItem *m_mazeItem;

    /** The GhostItem of each Ghost to be drawn */
    QList<GhostItem *> m_ghostItems;

    /** The ElementItem to be drawn (each Pill and Energizers) */
    ElementItem ** *m_elementItems;

    /** The Bonus ElementItem */
    ElementItem *m_bonusItem;

    /** A list with labels to display when a ghost or a bonus is eaten */
    QList<QGraphicsTextItem *> m_wonPointsLabels;

    /** The labels to be displayed during the game */
    QGraphicsTextItem *m_introLabel;
    QGraphicsTextItem *m_introLabel2;
    QGraphicsTextItem *m_newLevelLabel;
    QGraphicsTextItem *m_pauseLabel;

    /** The SVG renderer */
    QSvgRenderer *m_renderer;

    /** The Game theme */
    KGameTheme *m_theme;

public:

    /**
     * Creates a new GameScene instance.
     * @param p_game the Game instance whose elements must be contained in the GameScene in order to be drawn
     */
    explicit GameScene(Game *p_game);

    /**
     * Deletes the Game instance.
     */
    ~GameScene() override;

    /**
     * @return the Game instance
     */
    Game *getGame() const;

    /**
     * Loads the game theme.
     */
    void loadTheme();

private Q_SLOTS:

    /**
     * Updates the elements to be drawn on Game introduction.
     * @param p_newLevel true a new level has begun, false otherwise
     */
    void intro(const bool p_newLevel);

    /**
     * Updates the elements to be drawn when the Game starts.
     */
    void start();

    /**
     * Updates the elements to be drawn considering the Game state (paused or running).
     * @param p_pause if true the Game has been paused, if false the Game has been resumed
     * @param p_fromUser if true the Game has been paused due to an action from the user
     */
    void setPaused(const bool p_pause, const bool p_fromUser);

    /**
     * Removes the Element at the given coordinates from the GameScene.
     * @param p_wonPoints value of the won Points, used when a ghost or a Bonus is eaten
     * @param p_x x-coordinate of the Element
     * @param p_y y-coordinate of the Element
     */
    void hideElement(const qreal p_x, const qreal p_y);

    /**
     * Displays the Bonus.
     */
    void displayBonus();

    /**
     * Remove the Bonus from the GameScene.
     */
    void hideBonus();

    /**
     * Display won Points on the scene when a Bonus or a Ghosts is eaten
     * @param p_wonPoints the value to display
     * @param p_xPos the position of the eaten element on X axis
     * @param p_yPos the position of the eaten element on Y axis
     */
    void displayPoints(long p_wonPoints, qreal p_xPos, qreal p_yPos);

    /**
     * Hide the first label in the list of won points labels
     */
    void hidePoints();

    /**
     * Update theme id elements.
     */
    void updateSvgIds();

    /**
     * Update theme properties.
     */
    void updateThemeProperties();
};

#endif