Updated web page
[ghostsoverboard] / seascene.h
1 /**************************************************************************
2         Ghosts Overboard - a game for Maemo 5
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 <QAction>
32 #include <QTimer>
33 #include <QSystemDeviceInfo>
34
35 using namespace QtMobility;
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     void minimizeRequested();
50     void fullscreenRequested();
51     void deviceJustLocked();
52
53 public slots:
54
55     /*! Places all needed items for a level to (re)start.
56     Relies on the scene size to be explicitly set to a a value that will persist troughout play.
57     @param ghosts the number of ghosts to be placed on the map
58     @param rocks the number of rocks to be placed on the map
59     @param octopuses number of octopuses to be placed on the map
60     */
61     void setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed);
62
63     void setupMap(Level level);
64
65     void spreadGhosts(int ghosts);
66
67     void removeGhost(QGraphicsItem * pGhost);
68
69     void ghostsDropped(int ghosts);
70
71     void pause (bool paused);
72
73     void vibrationActivate(bool);
74
75     void handleScreenTapped();
76
77     void about();
78
79     void restartLevel();
80
81     void nextLevel();
82
83     void restartGame();
84
85     void forcePause();
86
87     void softContinue();
88
89     void createAboutBoxItems();
90
91     void createVictoryItems();
92
93     void setItemPointersNull();
94
95     void turnPauseOn();
96
97     void handleDeviceLocked(bool isLocked);
98
99     void pollDeviceLocked();
100
101
102
103 protected:
104
105     /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
106         The position is the upper left corner of a free 40x40 pixels slot.
107     */
108
109     QPointF* findRandomFreeSlot();
110
111     void createMenuItems();
112     void prepareForMenu(QGraphicsItem * pItem);
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     int menuItemCount_;
130
131     QGraphicsTextItem * pPausetextItem_;
132
133     QGraphicsTextItem * pRestartLevelItem_;
134     QGraphicsTextItem * pRestartGameItem_;
135     QGraphicsTextItem * pSettingsItem_;
136     QGraphicsTextItem * pAboutItem_;
137     QGraphicsTextItem * pQuitItem_;
138     QGraphicsTextItem * pMinimizeItem_;
139
140     QGraphicsTextItem * pVictoryCongratulationsItem_;
141     QGraphicsTextItem * pAboutBoxItem_;
142
143     QList<Level> levelList_;
144
145     int currentLevel_;
146
147
148     QAction* pVibrateAction_;
149
150     QAction* pPauseAction_;
151
152     QTimer autopauseTimer;
153
154     QSystemDeviceInfo deviceInfo_;
155
156     bool alreadyLocked_;
157
158     QTimer deviceLockPollTimer_;
159
160 };
161
162 #endif // SEASCENE_H