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,5 +1,5 @@
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**
@@ -23,4 +23,4 @@
23 23
24#include <qpe/resource.h> 24#include <qtopia/qpeapplication.h>
25#include <qpe/qpeapplication.h> 25#include <qtopia/resource.h>
26 26
@@ -30,3 +30,3 @@
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>
@@ -35,3 +35,7 @@ ParaShoot::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"),
@@ -41,5 +45,5 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
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
@@ -54,5 +58,3 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
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");
@@ -74,4 +76,2 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
74 setFocusPolicy(StrongFocus); 76 setFocusPolicy(StrongFocus);
75
76 newGame();
77} 77}
@@ -84,4 +84,30 @@ void ParaShoot::resizeEvent(QResizeEvent *)
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
@@ -152,4 +178,5 @@ void ParaShoot::gameOver()
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);
@@ -229,12 +256,17 @@ void ParaShoot::keyPressEvent(QKeyEvent* event)
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:
@@ -247,3 +279,3 @@ void 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);