summaryrefslogtreecommitdiff
path: root/noncore/games/parashoot/interface.cpp
authorzecke <zecke>2004-02-06 14:32:10 (UTC)
committer zecke <zecke>2004-02-06 14:32:10 (UTC)
commitb033733924e5d3454bb0a810c6a70d4ff0531d2b (patch) (unidiff)
treecafe130296468840db062af4a3335572804ee1f3 /noncore/games/parashoot/interface.cpp
parentf60cbb888e72b3eaf49af6f72fa183e6d44ae389 (diff)
downloadopie-b033733924e5d3454bb0a810c6a70d4ff0531d2b.zip
opie-b033733924e5d3454bb0a810c6a70d4ff0531d2b.tar.gz
opie-b033733924e5d3454bb0a810c6a70d4ff0531d2b.tar.bz2
Funny how much bugs one can introduce when importing Qtopia stuff.
Fixed a couple of possible sigsegv, uninitialized variables
Diffstat (limited to 'noncore/games/parashoot/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/parashoot/interface.cpp74
1 files changed, 53 insertions, 21 deletions
diff --git a/noncore/games/parashoot/interface.cpp b/noncore/games/parashoot/interface.cpp
index a40426d..948b92c 100644
--- a/noncore/games/parashoot/interface.cpp
+++ b/noncore/games/parashoot/interface.cpp
@@ -1,7 +1,7 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
@@ -21,27 +21,31 @@
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 <qtopia/qpeapplication.h>
25#include <qpe/qpeapplication.h> 25#include <qtopia/resource.h>
26 26
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qapplication.h> 29#include <qapplication.h>
30#include <qstyle.h> 30#include <qstyle.h>
31#include <qpe/qpetoolbar.h> 31#include <qtoolbar.h>
32#include <qtoolbutton.h> 32#include <qtoolbutton.h>
33 33
34ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : 34ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
35 QMainWindow(parent,name,f), 35 QMainWindow(parent,name,f),
36 canvas(232, 258), 36 canvas( 232, 258 ),
37 cannon(NULL),
38 base(NULL),
39 gamestopped( true ),
40 waitover( false ),
37 fanfare("level_up"), 41 fanfare("level_up"),
38 score(0) 42 score(0)
39{ 43{
40 QPEApplication::grabKeyboard(); 44 QPEApplication::grabKeyboard();
41 QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); 45 QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff );
46
47 updatespeed = 80;
42 canvas.setAdvancePeriod(80); 48 canvas.setAdvancePeriod(80);
43 QPixmap bg = Resource::loadPixmap("parashoot/sky");
44 canvas.setBackgroundPixmap(bg);
45 49
46 pb = new QCanvasView(&canvas, this); 50 pb = new QCanvasView(&canvas, this);
47 pb->setFocus(); 51 pb->setFocus();
@@ -52,9 +56,7 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
52 toolbar->setHorizontalStretchable( TRUE ); 56 toolbar->setHorizontalStretchable( TRUE );
53 57
54 setCaption( tr("ParaShoot") ); 58 setCaption( tr("ParaShoot") );
55 QPixmap newicon = Resource::loadPixmap("parashoot/manicon"); 59 new QToolButton( Resource::loadIconSet("new"), tr("New Game"), 0,
56 setIcon(newicon);
57 new QToolButton(newicon, tr("New Game"), 0,
58 this, SLOT(newGame()), toolbar, "New Game"); 60 this, SLOT(newGame()), toolbar, "New Game");
59 61
60 levelscore = new QLabel(toolbar); 62 levelscore = new QLabel(toolbar);
@@ -72,8 +74,6 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
72 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); 74 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) );
73 75
74 setFocusPolicy(StrongFocus); 76 setFocusPolicy(StrongFocus);
75
76 newGame();
77} 77}
78 78
79 79
@@ -82,8 +82,34 @@ void ParaShoot::resizeEvent(QResizeEvent *)
82 QSize s = centralWidget()->size(); 82 QSize s = centralWidget()->size();
83 int fw = style().defaultFrameWidth(); 83 int fw = style().defaultFrameWidth();
84 canvas.resize( s.width() - fw - 2, s.height() - fw - 2); 84 canvas.resize( s.width() - fw - 2, s.height() - fw - 2);
85
86 QImage bgimage = Resource::loadImage("parashoot/sky");
87 QPixmap bgpixmap;
88
89 bgpixmap.convertFromImage(bgimage.smoothScale(canvas.width(),
90 canvas.height()), QPixmap::Auto);
91 canvas.setBackgroundPixmap(bgpixmap);
92
93 if (base) {
94 base->reposition();
95 }
96
97 if (cannon) {
98 cannon->reposition();
99 }
85} 100}
86 101
102void ParaShoot::focusOutEvent (QFocusEvent *)
103{
104 if (!gamestopped)
105 canvas.setAdvancePeriod(-1);
106}
107
108void ParaShoot::focusInEvent (QFocusEvent *)
109{
110 if (!gamestopped)
111 canvas.setAdvancePeriod(updatespeed);
112}
87 113
88void ParaShoot::showScore( int score, int level ) 114void ParaShoot::showScore( int score, int level )
89{ 115{
@@ -150,8 +176,9 @@ void ParaShoot::gameOver()
150 " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), 176 " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ),
151 &canvas); 177 &canvas);
152 gameover->setColor(red); 178 gameover->setColor(red);
153 gameover->setFont( QFont("times", 18, QFont::Bold) ); 179 gameover->setFont( QFont("times", 16, QFont::Bold) );
154 gameover->move(canvas.width()/2 -110, canvas.height()/2 -50); 180 gameover->move((canvas.width() - gameover->boundingRect().width()) / 2,
181 (canvas.height() - gameover->boundingRect().height()) / 2);
155 gameover->setZ(500); 182 gameover->setZ(500);
156 gameover->show(); 183 gameover->show();
157 gamestopped = true; 184 gamestopped = true;
@@ -227,16 +254,21 @@ void ParaShoot::keyPressEvent(QKeyEvent* event)
227 case Key_F1: 254 case Key_F1:
228 case Key_F9: 255 case Key_F9:
229 case Key_Space: 256 case Key_Space:
230 cannon->shoot(); 257 if ( cannon )
258 cannon->shoot();
231 break; 259 break;
232 case Key_Left: 260 case Key_Left:{
233 cannon->pointCannon(Cannon::Left); 261 if (cannon )
262 cannon->pointCannon(Cannon::Left);
234 lastcannonkey=Key_Left; 263 lastcannonkey=Key_Left;
235 break; 264 break;
236 case Key_Right: 265 }
237 cannon->pointCannon(Cannon::Right); 266 case Key_Right:{
267 if ( cannon )
268 cannon->pointCannon(Cannon::Right);
238 lastcannonkey=Key_Right; 269 lastcannonkey=Key_Right;
239 break; 270 break;
271 }
240 default: 272 default:
241 return; 273 return;
242 } 274 }
@@ -245,6 +277,6 @@ void ParaShoot::keyPressEvent(QKeyEvent* event)
245 277
246void ParaShoot::keyReleaseEvent(QKeyEvent* event) 278void ParaShoot::keyReleaseEvent(QKeyEvent* event)
247{ 279{
248 if ( lastcannonkey == event->key() ) 280 if ( cannon && lastcannonkey == event->key() )
249 cannon->pointCannon(Cannon::NoDir); 281 cannon->pointCannon(Cannon::NoDir);
250} 282}