Diffstat (limited to 'noncore/games/parashoot/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/parashoot/interface.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/noncore/games/parashoot/interface.cpp b/noncore/games/parashoot/interface.cpp index db98720..a40426d 100644 --- a/noncore/games/parashoot/interface.cpp +++ b/noncore/games/parashoot/interface.cpp | |||
@@ -13,94 +13,97 @@ | |||
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "interface.h" | 21 | #include "interface.h" |
22 | #include "man.h" | 22 | #include "man.h" |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/qpeapplication.h> | ||
25 | 26 | ||
26 | #include <qlabel.h> | 27 | #include <qlabel.h> |
27 | #include <qmessagebox.h> | 28 | #include <qmessagebox.h> |
28 | #include <qapplication.h> | 29 | #include <qapplication.h> |
29 | #include <qstyle.h> | 30 | #include <qstyle.h> |
30 | #include <qpe/qpetoolbar.h> | 31 | #include <qpe/qpetoolbar.h> |
31 | #include <qtoolbutton.h> | 32 | #include <qtoolbutton.h> |
32 | 33 | ||
33 | ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : | 34 | ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : |
34 | QMainWindow(parent,name,f), | 35 | QMainWindow(parent,name,f), |
35 | canvas(232, 258), | 36 | canvas(232, 258), |
36 | fanfare("level_up"), | 37 | fanfare("level_up"), |
37 | score(0) | 38 | score(0) |
38 | { | 39 | { |
40 | QPEApplication::grabKeyboard(); | ||
41 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); | ||
39 | canvas.setAdvancePeriod(80); | 42 | canvas.setAdvancePeriod(80); |
40 | QPixmap bg = Resource::loadPixmap("parashoot/sky"); | 43 | QPixmap bg = Resource::loadPixmap("parashoot/sky"); |
41 | canvas.setBackgroundPixmap(bg); | 44 | canvas.setBackgroundPixmap(bg); |
42 | 45 | ||
43 | pb = new QCanvasView(&canvas, this); | 46 | pb = new QCanvasView(&canvas, this); |
44 | pb->setFocus(); | 47 | pb->setFocus(); |
45 | 48 | ||
46 | setToolBarsMovable( FALSE ); | 49 | setToolBarsMovable( FALSE ); |
47 | 50 | ||
48 | QToolBar* toolbar = new QToolBar(this); | 51 | QToolBar* toolbar = new QToolBar(this); |
49 | toolbar->setHorizontalStretchable( TRUE ); | 52 | toolbar->setHorizontalStretchable( TRUE ); |
50 | 53 | ||
51 | setCaption( tr("ParaShoot") ); | 54 | setCaption( tr("ParaShoot") ); |
52 | QPixmap newicon = Resource::loadPixmap("parashoot/manicon"); | 55 | QPixmap newicon = Resource::loadPixmap("parashoot/manicon"); |
53 | setIcon(newicon); | 56 | setIcon(newicon); |
54 | new QToolButton(newicon, tr("New Game"), 0, | 57 | new QToolButton(newicon, tr("New Game"), 0, |
55 | this, SLOT(newGame()), toolbar, "New Game"); | 58 | this, SLOT(newGame()), toolbar, "New Game"); |
56 | 59 | ||
57 | levelscore = new QLabel(toolbar); | 60 | levelscore = new QLabel(toolbar); |
58 | levelscore->setBackgroundMode( PaletteButton ); | 61 | levelscore->setBackgroundMode( PaletteButton ); |
59 | levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); | 62 | levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); |
60 | toolbar->setStretchableWidget( levelscore ); | 63 | toolbar->setStretchableWidget( levelscore ); |
61 | showScore(0,0); | 64 | showScore(0,0); |
62 | 65 | ||
63 | setCentralWidget(pb); | 66 | setCentralWidget(pb); |
64 | 67 | ||
65 | autoDropTimer = new QTimer(this); | 68 | autoDropTimer = new QTimer(this); |
66 | connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); | 69 | connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); |
67 | 70 | ||
68 | pauseTimer = new QTimer(this); | 71 | pauseTimer = new QTimer(this); |
69 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); | 72 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); |
70 | 73 | ||
71 | setFocusPolicy(StrongFocus); | 74 | setFocusPolicy(StrongFocus); |
72 | 75 | ||
73 | newGame(); | 76 | newGame(); |
74 | } | 77 | } |
75 | 78 | ||
76 | 79 | ||
77 | void ParaShoot::resizeEvent(QResizeEvent *) | 80 | void ParaShoot::resizeEvent(QResizeEvent *) |
78 | { | 81 | { |
79 | QSize s = centralWidget()->size(); | 82 | QSize s = centralWidget()->size(); |
80 | int fw = style().defaultFrameWidth(); | 83 | int fw = style().defaultFrameWidth(); |
81 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | 84 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); |
82 | } | 85 | } |
83 | 86 | ||
84 | 87 | ||
85 | void ParaShoot::showScore( int score, int level ) | 88 | void ParaShoot::showScore( int score, int level ) |
86 | { | 89 | { |
87 | levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); | 90 | levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); |
88 | } | 91 | } |
89 | 92 | ||
90 | 93 | ||
91 | void ParaShoot::newGame() | 94 | void ParaShoot::newGame() |
92 | { | 95 | { |
93 | clear(); | 96 | clear(); |
94 | if (pauseTimer->isActive()) | 97 | if (pauseTimer->isActive()) |
95 | pauseTimer->stop(); | 98 | pauseTimer->stop(); |
96 | clear(); | 99 | clear(); |
97 | Man::setManCount(0); | 100 | Man::setManCount(0); |
98 | score = 0; | 101 | score = 0; |
99 | Bullet::setShotCount(0); | 102 | Bullet::setShotCount(0); |
100 | Bullet::setNobullets(0); | 103 | Bullet::setNobullets(0); |
101 | nomen = 2; | 104 | nomen = 2; |
102 | Bullet::setLimit(nomen); | 105 | Bullet::setLimit(nomen); |
103 | level = 0; | 106 | level = 0; |
104 | updatespeed = 80; | 107 | updatespeed = 80; |
105 | showScore(0,0); | 108 | showScore(0,0); |
106 | gamestopped = false; | 109 | gamestopped = false; |
@@ -110,122 +113,122 @@ void ParaShoot::newGame() | |||
110 | cannon = new Cannon(&canvas); | 113 | cannon = new Cannon(&canvas); |
111 | connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); | 114 | connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); |
112 | autoDropTimer->start(100); | 115 | autoDropTimer->start(100); |
113 | } | 116 | } |
114 | 117 | ||
115 | 118 | ||
116 | void ParaShoot::clear() | 119 | void ParaShoot::clear() |
117 | { | 120 | { |
118 | autoDropTimer->stop(); | 121 | autoDropTimer->stop(); |
119 | // QCanvasItem* item; | 122 | // QCanvasItem* item; |
120 | QCanvasItemList l = canvas.allItems(); | 123 | QCanvasItemList l = canvas.allItems(); |
121 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 124 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
122 | delete *it; | 125 | delete *it; |
123 | } | 126 | } |
124 | } | 127 | } |
125 | 128 | ||
126 | void ParaShoot::gameOver() | 129 | void ParaShoot::gameOver() |
127 | { | 130 | { |
128 | QCanvasItem* item; | 131 | QCanvasItem* item; |
129 | QCanvasItemList l = canvas.allItems(); | 132 | QCanvasItemList l = canvas.allItems(); |
130 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 133 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
131 | item = *it; | 134 | item = *it; |
132 | if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) | 135 | if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) |
133 | item->setAnimated(false); | 136 | item->setAnimated(false); |
134 | } | 137 | } |
135 | autoDropTimer->stop(); | 138 | autoDropTimer->stop(); |
136 | Helicopter::silenceAll(); | 139 | Helicopter::silenceAll(); |
137 | 140 | ||
138 | int shots = Bullet::getShotCount(); | 141 | int shots = Bullet::getShotCount(); |
139 | 142 | ||
140 | int shotsFired = cannon->shotsFired(); | 143 | int shotsFired = cannon->shotsFired(); |
141 | if ( shotsFired == 0 ) | 144 | if ( shotsFired == 0 ) |
142 | shotsFired = 1; | 145 | shotsFired = 1; |
143 | QCanvasText* gameover = new QCanvasText( | 146 | QCanvasText* gameover = new QCanvasText( |
144 | tr( " GAME OVER!\n" | 147 | tr( " GAME OVER!\n" |
145 | " Your Score: %1\n" | 148 | " Your Score: %1\n" |
146 | " Parachuters Killed: %2\n" | 149 | " Parachuters Killed: %2\n" |
147 | " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), | 150 | " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), |
148 | &canvas); | 151 | &canvas); |
149 | gameover->setColor(red); | 152 | gameover->setColor(red); |
150 | gameover->setFont( QFont("times", 18, QFont::Bold) ); | 153 | gameover->setFont( QFont("times", 18, QFont::Bold) ); |
151 | gameover->move(canvas.width()/2 -110, canvas.height()/2 -50); | 154 | gameover->move(canvas.width()/2 -110, canvas.height()/2 -50); |
152 | gameover->setZ(500); | 155 | gameover->setZ(500); |
153 | gameover->show(); | 156 | gameover->show(); |
154 | gamestopped = true; | 157 | gamestopped = true; |
155 | waitover = false; | 158 | waitover = false; |
156 | pauseTimer->start(3000); | 159 | pauseTimer->start(3000); |
157 | } | 160 | } |
158 | 161 | ||
159 | void ParaShoot::wait() | 162 | void ParaShoot::wait() |
160 | { | 163 | { |
161 | waitover = true; | 164 | waitover = true; |
162 | pauseTimer->stop(); | 165 | pauseTimer->stop(); |
163 | } | 166 | } |
164 | 167 | ||
165 | void ParaShoot::play() | 168 | void ParaShoot::play() |
166 | { | 169 | { |
167 | if (Man::getManCount() < nomen ) { | 170 | if (Man::getManCount() < nomen ) { |
168 | new Man(&canvas); | 171 | new Man(&canvas); |
169 | } | 172 | } |
170 | if (Base::baseDestroyed()) { | 173 | if (Base::baseDestroyed()) { |
171 | gameOver(); | 174 | gameOver(); |
172 | return; | 175 | return; |
173 | } | 176 | } |
174 | } | 177 | } |
175 | 178 | ||
176 | void ParaShoot::increaseScore(int x) | 179 | void ParaShoot::increaseScore(int x) |
177 | { | 180 | { |
178 | score += x; | 181 | score += x; |
179 | if ( score / 150 != (score-x) / 150 ) | 182 | if ( score / 150 != (score-x) / 150 ) |
180 | levelUp(); | 183 | levelUp(); |
181 | showScore(level,score); | 184 | showScore(level,score); |
182 | } | 185 | } |
183 | 186 | ||
184 | void ParaShoot::levelUp() | 187 | void ParaShoot::levelUp() |
185 | { | 188 | { |
186 | level++; | 189 | level++; |
187 | int stage = level % 3; | 190 | int stage = level % 3; |
188 | switch(stage) { | 191 | switch(stage) { |
189 | case 0: | 192 | case 0: |
190 | nomen++; | 193 | nomen++; |
191 | Bullet::setLimit(nomen); | 194 | Bullet::setLimit(nomen); |
192 | fanfare.play(); | 195 | fanfare.play(); |
193 | break; | 196 | break; |
194 | case 1: | 197 | case 1: |
195 | new Helicopter(&canvas); | 198 | new Helicopter(&canvas); |
196 | break; | 199 | break; |
197 | case 2: | 200 | case 2: |
198 | moveFaster(); | 201 | moveFaster(); |
199 | fanfare.play(); | 202 | fanfare.play(); |
200 | break; | 203 | break; |
201 | default: return; | 204 | default: return; |
202 | } | 205 | } |
203 | } | 206 | } |
204 | 207 | ||
205 | void ParaShoot::moveFaster() | 208 | void ParaShoot::moveFaster() |
206 | { | 209 | { |
207 | if (updatespeed > 50) | 210 | if (updatespeed > 50) |
208 | updatespeed = updatespeed-5; | 211 | updatespeed = updatespeed-5; |
209 | else | 212 | else |
210 | updatespeed = updatespeed-3; | 213 | updatespeed = updatespeed-3; |
211 | canvas.setAdvancePeriod(updatespeed); | 214 | canvas.setAdvancePeriod(updatespeed); |
212 | } | 215 | } |
213 | 216 | ||
214 | void ParaShoot::keyPressEvent(QKeyEvent* event) | 217 | void ParaShoot::keyPressEvent(QKeyEvent* event) |
215 | { | 218 | { |
216 | if (gamestopped) { | 219 | if (gamestopped) { |
217 | if (waitover) | 220 | if (waitover) |
218 | newGame(); | 221 | newGame(); |
219 | else | 222 | else |
220 | return; | 223 | return; |
221 | } else { | 224 | } else { |
222 | switch(event->key()) { | 225 | switch(event->key()) { |
223 | case Key_Up: | 226 | case Key_Up: |
224 | case Key_F1: | 227 | case Key_F1: |
225 | case Key_F9: | 228 | case Key_F9: |
226 | case Key_Space: | 229 | case Key_Space: |
227 | cannon->shoot(); | 230 | cannon->shoot(); |
228 | break; | 231 | break; |
229 | case Key_Left: | 232 | case Key_Left: |
230 | cannon->pointCannon(Cannon::Left); | 233 | cannon->pointCannon(Cannon::Left); |
231 | lastcannonkey=Key_Left; | 234 | lastcannonkey=Key_Left; |