summaryrefslogtreecommitdiff
path: root/noncore/games/parashoot/interface.cpp
Unidiff
Diffstat (limited to 'noncore/games/parashoot/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/parashoot/interface.cpp33
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
@@ -22,6 +22,7 @@
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>
@@ -29,13 +30,15 @@
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
33ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : 34ParaShoot::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);
@@ -59,14 +62,14 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
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
@@ -91,7 +94,7 @@ void ParaShoot::showScore( int score, int level )
91void ParaShoot::newGame() 94void 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);
@@ -119,7 +122,7 @@ void ParaShoot::clear()
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
@@ -127,7 +130,7 @@ 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);
@@ -138,13 +141,13 @@ void ParaShoot::gameOver()
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) );
@@ -163,7 +166,7 @@ void ParaShoot::wait()
163} 166}
164 167
165void ParaShoot::play() 168void ParaShoot::play()
166{ 169{
167 if (Man::getManCount() < nomen ) { 170 if (Man::getManCount() < nomen ) {
168 new Man(&canvas); 171 new Man(&canvas);
169 } 172 }
@@ -177,13 +180,13 @@ 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
184void ParaShoot::levelUp() 187void 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:
@@ -193,11 +196,11 @@ void ParaShoot::levelUp()
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}
@@ -216,7 +219,7 @@ void ParaShoot::keyPressEvent(QKeyEvent* event)
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()) {