summaryrefslogtreecommitdiff
path: root/noncore/games/parashoot
Unidiff
Diffstat (limited to 'noncore/games/parashoot') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/parashoot/interface.cpp33
-rw-r--r--noncore/games/parashoot/interface.h1
-rw-r--r--noncore/games/parashoot/main.cpp13
-rw-r--r--noncore/games/parashoot/opie-parashoot.control2
-rw-r--r--noncore/games/parashoot/parashoot.pro6
5 files changed, 25 insertions, 30 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
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);
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
77void ParaShoot::resizeEvent(QResizeEvent *) 80void 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
85void ParaShoot::showScore( int score, int level ) 88void 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
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);
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
116void ParaShoot::clear() 119void 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
126void ParaShoot::gameOver() 129void 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
159void ParaShoot::wait() 162void ParaShoot::wait()
160{ 163{
161 waitover = true; 164 waitover = true;
162 pauseTimer->stop(); 165 pauseTimer->stop();
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 }
170 if (Base::baseDestroyed()) { 173 if (Base::baseDestroyed()) {
171 gameOver(); 174 gameOver();
172 return; 175 return;
173 } 176 }
174} 177}
175 178
176void ParaShoot::increaseScore(int x) 179void 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:
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
205void ParaShoot::moveFaster() 208void 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
214void ParaShoot::keyPressEvent(QKeyEvent* event) 217void 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;
diff --git a/noncore/games/parashoot/interface.h b/noncore/games/parashoot/interface.h
index 3f36d0b..5abbe0b 100644
--- a/noncore/games/parashoot/interface.h
+++ b/noncore/games/parashoot/interface.h
@@ -29,24 +29,25 @@
29#include <qlabel.h> 29#include <qlabel.h>
30 30
31class QCanvas; 31class QCanvas;
32class Helicopter; 32class Helicopter;
33 33
34//enum Direction{ 34//enum Direction{
35// left, right, up, down }; 35// left, right, up, down };
36 36
37class ParaShoot : public QMainWindow { 37class ParaShoot : public QMainWindow {
38 Q_OBJECT 38 Q_OBJECT
39 39
40public: 40public:
41 static QString appName() { return QString::fromLatin1("parashoot"); }
41 ParaShoot(QWidget* parent=0, const char* name=0, WFlags f=0); 42 ParaShoot(QWidget* parent=0, const char* name=0, WFlags f=0);
42 43
43 void clear(); 44 void clear();
44 void gameOver(); 45 void gameOver();
45 int mancount; 46 int mancount;
46 void levelUp(); 47 void levelUp();
47 void moveFaster(); 48 void moveFaster();
48 49
49protected: 50protected:
50 virtual void keyPressEvent(QKeyEvent*); 51 virtual void keyPressEvent(QKeyEvent*);
51 virtual void keyReleaseEvent(QKeyEvent*); 52 virtual void keyReleaseEvent(QKeyEvent*);
52 virtual void resizeEvent(QResizeEvent *e); 53 virtual void resizeEvent(QResizeEvent *e);
diff --git a/noncore/games/parashoot/main.cpp b/noncore/games/parashoot/main.cpp
index 60eea18..ee36d26 100644
--- a/noncore/games/parashoot/main.cpp
+++ b/noncore/games/parashoot/main.cpp
@@ -12,25 +12,16 @@
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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 22
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24#include <opie/oapplicationfactory.h>
24 25
25int main(int argc, char **argv) 26OPIE_EXPORT_APP( OApplicationFactory<ParaShoot> )
26{
27 QPEApplication app(argc,argv);
28 27
29 QPEApplication::grabKeyboard();
30
31 ParaShoot m;
32 QPEApplication::setInputMethodHint( &m, QPEApplication::AlwaysOff );
33 app.showMainWidget(&m);
34
35 return app.exec();
36}
diff --git a/noncore/games/parashoot/opie-parashoot.control b/noncore/games/parashoot/opie-parashoot.control
index 758d24d..139dd3c 100644
--- a/noncore/games/parashoot/opie-parashoot.control
+++ b/noncore/games/parashoot/opie-parashoot.control
@@ -1,10 +1,10 @@
1Package: opie-parashoot 1Package: opie-parashoot
2Files: bin/parashoot apps/Games/parashoot.desktop pics/parashoot 2Files: plugins/application/libparashoot.so* bin/parashoot apps/Games/parashoot.desktop pics/parashoot
3Priority: optional 3Priority: optional
4Section: opie/games 4Section: opie/games
5Maintainer: Martin Imobersteg <imm@gmx.ch> 5Maintainer: Martin Imobersteg <imm@gmx.ch>
6Architecture: arm 6Architecture: arm
7Depends: task-opie-minimal 7Depends: task-opie-minimal
8Description: Game: shoot the parachutists 8Description: Game: shoot the parachutists
9 A game for the Opie environment. 9 A game for the Opie environment.
10Version: $QPE_VERSION$EXTRAVERSION 10Version: $QPE_VERSION$EXTRAVERSION
diff --git a/noncore/games/parashoot/parashoot.pro b/noncore/games/parashoot/parashoot.pro
index c2746f9..f5d103a 100644
--- a/noncore/games/parashoot/parashoot.pro
+++ b/noncore/games/parashoot/parashoot.pro
@@ -1,11 +1,11 @@
1 TEMPLATE= app 1 CONFIG += qt warn_on release quick-app
2 CONFIG += qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin
4 HEADERS = interface.h man.h cannon.h base.h bullet.h helicopter.h 2 HEADERS = interface.h man.h cannon.h base.h bullet.h helicopter.h
5 SOURCES = main.cpp interface.cpp man.cpp cannon.cpp base.cpp bullet.cpp helicopter.cpp 3 SOURCES = main.cpp interface.cpp man.cpp cannon.cpp base.cpp bullet.cpp helicopter.cpp
6 TARGET = parashoot 4 TARGET = parashoot
7INCLUDEPATH += $(OPIEDIR)/include 5INCLUDEPATH += $(OPIEDIR)/include
8 DEPENDPATH+= $(OPIEDIR)/include 6 DEPENDPATH+= $(OPIEDIR)/include
9LIBS += -lqpe 7LIBS += -lqpe
10 8
9
10
11include ( $(OPIEDIR)/include.pro ) 11include ( $(OPIEDIR)/include.pro )