Merge branch 'vibrationrecovery' into harmattan
[ghostsoverboard] / seascene.h
1 /**************************************************************************
2         Ghosts Overboard - a game for 'Meego 1.2 Harmattan'
3
4         Copyright (C) 2011  Heli Hyvättinen
5
6         This file is part of Ghosts Overboard
7
8         Ghosts Overboard is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 2 of the License, or
11         (at your option) any later version.
12
13         This program is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 **************************************************************************/
22
23
24 #ifndef SEASCENE_H
25 #define SEASCENE_H
26
27 #include <QGraphicsScene>
28 #include<QGraphicsItemGroup>
29 #include "screenlitkeeper.h"
30 #include "level.h"
31 #include "levelset.h"
32 #include <QAction>
33 #include <QTimer>
34 #include <QTime>
35 #include <policy/resource-set.h>
36
37 class SeaScene : public QGraphicsScene
38 {
39     Q_OBJECT
40 public:
41     explicit SeaScene(QObject *parent = 0);
42
43 signals:
44
45     void allGhostsPicked();
46     void pauseOn();
47     void pauseOff();
48     void vibrationActivated(bool on);
49
50
51 public slots:
52
53     /*! Places all needed items for a level to (re)start.
54     Relies on the scene size to be explicitly set to a a value that will persist troughout play.
55     @param ghosts the number of ghosts to be placed on the map
56     @param rocks the number of rocks to be placed on the map
57     @param octopuses number of octopuses to be placed on the map
58     */
59     void setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed);
60
61     void setupMap(Level level);
62
63     void spreadGhosts(int ghosts);
64
65     void removeGhost(QGraphicsItem * pGhost);
66
67     void ghostsDropped(int ghosts);
68
69     void pause (bool paused);
70
71     void vibrationActivate(bool);
72
73     void handleScreenTapped();
74
75     void about();
76
77     void restartLevel();
78
79     void nextLevel();
80
81     void restartGame();
82
83     void forcePause();
84
85     void softContinue();
86
87     void setItemPointersNull();
88
89     void turnPauseOn();
90
91     void resourcesAvailable();
92
93     void resourcesLost();
94
95
96
97
98
99 protected:
100
101     /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
102         The position is the upper left corner of a free 40x40 pixels slot.
103     */
104
105     QPointF* findRandomFreeSlot();
106
107     void createMenuItems();
108     void prepareForMenu(QGraphicsItem * pItem);
109     void createAboutBoxItems();
110     void createVictoryItems();
111     void createLevelCompletedItems();
112     void createSelectLevelsetFromListItems();
113
114     const QString ghostImageFilename_;
115     const QString rockImageFilename_;
116     const QString octopusImageFilename_;
117     const QStringList shipImageFilenames_;
118
119     QList<QPointF> freeTiles_;
120
121     int ghostsLeft_;
122
123     QList<QGraphicsItem*> movingItems_;
124
125     bool paused_;
126
127     ScreenLitKeeper screenLitKeeper_;
128
129
130     int menuItemCount_;
131
132     QGraphicsTextItem * pPausetextItem_;
133
134     QGraphicsTextItem * pRestartLevelItem_;
135     QGraphicsTextItem * pRestartGameItem_;
136     QGraphicsTextItem * pSettingsItem_;
137     QGraphicsTextItem * pAboutItem_;
138     QGraphicsTextItem * pQuitItem_;
139     QGraphicsTextItem * pChooseLevelsetItem_;
140
141     QGraphicsTextItem * pVictoryScoreItem_;
142     QGraphicsTextItem * pAboutBoxItem_;
143     QGraphicsTextItem * pVictoryCongratulationsItem_;
144
145     QGraphicsTextItem * pLevelCompletedItem_;
146
147     QGraphicsTextItem * pSelectLevelsetFromListItem_;
148
149     QList<QGraphicsItem *>  levelsetItems_;
150
151     QList<Levelset> availableLevelsets_;
152
153     Levelset levelset_;
154
155     int currentLevel_;
156
157
158     QAction* pVibrateAction_;
159
160     QAction* pPauseAction_;
161
162     bool pauseForced_;
163
164     QTimer autopauseTimer;
165
166
167     QTime scoreCounter_;
168     int totalScore_;
169     int levelScore_;
170
171     ResourcePolicy::ResourceSet * pResourceSet_;
172     bool vibrationAllowed_;
173
174 };
175
176 #endif // SEASCENE_H