summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-06 14:32:10 (UTC)
committer zecke <zecke>2004-02-06 14:32:10 (UTC)
commitb033733924e5d3454bb0a810c6a70d4ff0531d2b (patch) (side-by-side diff)
treecafe130296468840db062af4a3335572804ee1f3
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 (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/parashoot/base.cpp12
-rw-r--r--noncore/games/parashoot/base.h8
-rw-r--r--noncore/games/parashoot/cannon.cpp24
-rw-r--r--noncore/games/parashoot/cannon.h6
-rw-r--r--noncore/games/parashoot/helicopter.cpp28
-rw-r--r--noncore/games/parashoot/helicopter.h6
-rw-r--r--noncore/games/parashoot/interface.cpp74
-rw-r--r--noncore/games/parashoot/interface.h22
-rw-r--r--noncore/games/parashoot/man.cpp39
9 files changed, 148 insertions, 71 deletions
diff --git a/noncore/games/parashoot/base.cpp b/noncore/games/parashoot/base.cpp
index c03802f..cdf1dfa 100644
--- a/noncore/games/parashoot/base.cpp
+++ b/noncore/games/parashoot/base.cpp
@@ -1,6 +1,6 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
@@ -22,5 +22,5 @@
#include "man.h"
-#include <qpe/resource.h>
+#include <qtopia/resource.h>
#include <qregexp.h>
@@ -70,2 +70,8 @@ int Base::rtti() const
return base_rtti;
}
+
+void
+Base::reposition(void)
+{
+ move(2, canvas()->height()-50);
+}
diff --git a/noncore/games/parashoot/base.h b/noncore/games/parashoot/base.h
index ee7f166..a4c69cc 100644
--- a/noncore/games/parashoot/base.h
+++ b/noncore/games/parashoot/base.h
@@ -1,6 +1,6 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
@@ -19,5 +19,5 @@
**********************************************************************/
-#include <qpe/sound.h>
+#include <qtopia/sound.h>
#include <qcanvas.h>
@@ -33,4 +33,6 @@ public:
static bool baseDestroyed();
+ void reposition(void);
+
private:
QCanvasPixmapArray* basearray;
diff --git a/noncore/games/parashoot/cannon.cpp b/noncore/games/parashoot/cannon.cpp
index 3c0a5fe..5671351 100644
--- a/noncore/games/parashoot/cannon.cpp
+++ b/noncore/games/parashoot/cannon.cpp
@@ -1,6 +1,6 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
@@ -19,5 +19,5 @@
**********************************************************************/
-#include <qpe/resource.h>
+#include <qtopia/resource.h>
#include <qregexp.h>
@@ -39,8 +39,7 @@ shotsfired=0;
setSequence(cannonarray);
setFrame(index);
- move(canvas->width()/2-20, canvas->height()-32);
- // co ords for barrel of cannon when upright
- barrelypos = canvas->height()-32;
- barrelxpos = canvas->width()/2;
+
+ reposition();
+
movedir = NoDir;
moveDelay = 0;
@@ -139,2 +138,13 @@ int Cannon::rtti() const
return cannon_rtti;
}
+
+void Cannon::reposition(void)
+{
+ move(canvas()->width()/2-20, canvas()->height()-32);
+ // co ords for barrel of cannon when upright
+ barrelypos = canvas()->height()-32;
+ barrelxpos = canvas()->width()/2;
+
+ setFrame(index);
+ setCoords();
+}
diff --git a/noncore/games/parashoot/cannon.h b/noncore/games/parashoot/cannon.h
index 44d0c65..51b1247 100644
--- a/noncore/games/parashoot/cannon.h
+++ b/noncore/games/parashoot/cannon.h
@@ -1,6 +1,6 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
@@ -40,4 +40,6 @@ public:
int shotsFired() { return shotsfired; };
+ void reposition(void);
+
protected:
void advance(int stage);
diff --git a/noncore/games/parashoot/helicopter.cpp b/noncore/games/parashoot/helicopter.cpp
index 0923124..036b21e 100644
--- a/noncore/games/parashoot/helicopter.cpp
+++ b/noncore/games/parashoot/helicopter.cpp
@@ -1,6 +1,6 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
@@ -23,5 +23,5 @@
#include "codes.h"
-#include <qpe/resource.h>
+#include <qtopia/resource.h>
#include <qregexp.h>
@@ -38,5 +38,6 @@ Helicopter::Helicopter(QCanvas* canvas) :
QString h0 = Resource::findPixmap("parashoot/helicopter0001");
h0.replace(QRegExp("0001"),"%1");
- helicopterarray->readPixmaps(h0,3 );
+ helicopterarray->readPixmaps(h0,4 );
+
setSequence(helicopterarray);
setAnimated(true);
@@ -58,7 +59,16 @@ void Helicopter::advance(int phase)
QCanvasSprite::advance(phase);
if (phase == 0) {
- setFrame(fr%3);
- fr++;
- checkCollision();
+ if (frame() == 3) {
+ delete this;
+ return;
+ }
+
+ if (hits >= 2) {
+ setFrame(3);
+ } else {
+ setFrame(fr%3);
+ fr++;
+ checkCollision();
+ }
}
}
@@ -84,8 +94,4 @@ void Helicopter::done()
{
hits++;
- if (hits >= 2) {
- setAnimated(false);
- delete this;
- }
}
diff --git a/noncore/games/parashoot/helicopter.h b/noncore/games/parashoot/helicopter.h
index 5cb92de..954c651 100644
--- a/noncore/games/parashoot/helicopter.h
+++ b/noncore/games/parashoot/helicopter.h
@@ -1,6 +1,6 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
@@ -19,5 +19,5 @@
**********************************************************************/
-#include <qpe/sound.h>
+#include <qtopia/sound.h>
#include <qcanvas.h>
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,6 +1,6 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
@@ -22,6 +22,6 @@
#include "man.h"
-#include <qpe/resource.h>
-#include <qpe/qpeapplication.h>
+#include <qtopia/qpeapplication.h>
+#include <qtopia/resource.h>
#include <qlabel.h>
@@ -29,10 +29,14 @@
#include <qapplication.h>
#include <qstyle.h>
-#include <qpe/qpetoolbar.h>
+#include <qtoolbar.h>
#include <qtoolbutton.h>
ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
QMainWindow(parent,name,f),
- canvas(232, 258),
+ canvas( 232, 258 ),
+ cannon(NULL),
+ base(NULL),
+ gamestopped( true ),
+ waitover( false ),
fanfare("level_up"),
score(0)
@@ -40,7 +44,7 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
QPEApplication::grabKeyboard();
QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff );
+
+ updatespeed = 80;
canvas.setAdvancePeriod(80);
- QPixmap bg = Resource::loadPixmap("parashoot/sky");
- canvas.setBackgroundPixmap(bg);
pb = new QCanvasView(&canvas, this);
@@ -53,7 +57,5 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
setCaption( tr("ParaShoot") );
- QPixmap newicon = Resource::loadPixmap("parashoot/manicon");
- setIcon(newicon);
- new QToolButton(newicon, tr("New Game"), 0,
+ new QToolButton( Resource::loadIconSet("new"), tr("New Game"), 0,
this, SLOT(newGame()), toolbar, "New Game");
@@ -73,6 +75,4 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
setFocusPolicy(StrongFocus);
-
- newGame();
}
@@ -83,6 +83,32 @@ void ParaShoot::resizeEvent(QResizeEvent *)
int fw = style().defaultFrameWidth();
canvas.resize( s.width() - fw - 2, s.height() - fw - 2);
+
+ QImage bgimage = Resource::loadImage("parashoot/sky");
+ QPixmap bgpixmap;
+
+ bgpixmap.convertFromImage(bgimage.smoothScale(canvas.width(),
+ canvas.height()), QPixmap::Auto);
+ canvas.setBackgroundPixmap(bgpixmap);
+
+ if (base) {
+ base->reposition();
+ }
+
+ if (cannon) {
+ cannon->reposition();
+ }
}
+void ParaShoot::focusOutEvent (QFocusEvent *)
+{
+ if (!gamestopped)
+ canvas.setAdvancePeriod(-1);
+}
+
+void ParaShoot::focusInEvent (QFocusEvent *)
+{
+ if (!gamestopped)
+ canvas.setAdvancePeriod(updatespeed);
+}
void ParaShoot::showScore( int score, int level )
@@ -151,6 +177,7 @@ void ParaShoot::gameOver()
&canvas);
gameover->setColor(red);
- gameover->setFont( QFont("times", 18, QFont::Bold) );
- gameover->move(canvas.width()/2 -110, canvas.height()/2 -50);
+ gameover->setFont( QFont("times", 16, QFont::Bold) );
+ gameover->move((canvas.width() - gameover->boundingRect().width()) / 2,
+ (canvas.height() - gameover->boundingRect().height()) / 2);
gameover->setZ(500);
gameover->show();
@@ -228,14 +255,19 @@ void ParaShoot::keyPressEvent(QKeyEvent* event)
case Key_F9:
case Key_Space:
- cannon->shoot();
+ if ( cannon )
+ cannon->shoot();
break;
- case Key_Left:
- cannon->pointCannon(Cannon::Left);
+ case Key_Left:{
+ if (cannon )
+ cannon->pointCannon(Cannon::Left);
lastcannonkey=Key_Left;
break;
- case Key_Right:
- cannon->pointCannon(Cannon::Right);
+ }
+ case Key_Right:{
+ if ( cannon )
+ cannon->pointCannon(Cannon::Right);
lastcannonkey=Key_Right;
break;
+ }
default:
return;
@@ -246,5 +278,5 @@ void ParaShoot::keyPressEvent(QKeyEvent* event)
void ParaShoot::keyReleaseEvent(QKeyEvent* event)
{
- if ( lastcannonkey == event->key() )
+ if ( cannon && lastcannonkey == event->key() )
cannon->pointCannon(Cannon::NoDir);
}
diff --git a/noncore/games/parashoot/interface.h b/noncore/games/parashoot/interface.h
index 5abbe0b..dd73f53 100644
--- a/noncore/games/parashoot/interface.h
+++ b/noncore/games/parashoot/interface.h
@@ -1,6 +1,6 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
@@ -23,5 +23,5 @@
#include "helicopter.h"
-#include <qpe/sound.h>
+#include <qtopia/sound.h>
#include <qmainwindow.h>
@@ -33,13 +33,14 @@ class Helicopter;
//enum Direction{
-// left, right, up, down };
+// left, right, up, down };
class ParaShoot : public QMainWindow {
Q_OBJECT
-
+
public:
- static QString appName() { return QString::fromLatin1("parashoot"); }
ParaShoot(QWidget* parent=0, const char* name=0, WFlags f=0);
-
+ static QString appName() {
+ return QString::fromLatin1("parashoot");
+ }
void clear();
void gameOver();
@@ -52,5 +53,7 @@ protected:
virtual void keyReleaseEvent(QKeyEvent*);
virtual void resizeEvent(QResizeEvent *e);
-
+ virtual void focusOutEvent(QFocusEvent *);
+ virtual void focusInEvent(QFocusEvent *);
+
private slots:
void increaseScore(int);
@@ -65,5 +68,4 @@ private:
Cannon* cannon;
Base* base;
- QCanvasText* gameover;
QLabel* levelscore;
int nomen;
@@ -78,3 +80,3 @@ private:
int score;
int lastcannonkey;
-};
+};
diff --git a/noncore/games/parashoot/man.cpp b/noncore/games/parashoot/man.cpp
index 8435572..94807c2 100644
--- a/noncore/games/parashoot/man.cpp
+++ b/noncore/games/parashoot/man.cpp
@@ -1,6 +1,6 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
@@ -19,9 +19,9 @@
**********************************************************************/
-#include "codes.h"
+#include "codes.h"
#include "man.h"
#include "base.h"
-#include <qpe/resource.h>
+#include <qtopia/resource.h>
#include <qregexp.h>
@@ -31,10 +31,10 @@ int mancount;
Man::Man(QCanvas* canvas) :
QCanvasSprite(0, canvas),
- splat("lose")
+ splat("lose") // No tr
{
manarray = new QCanvasPixmapArray();
QString m0 = Resource::findPixmap("parashoot/man0001");
m0.replace(QRegExp("0001"),"%1");
- manarray->readPixmaps(m0, 7);
+ manarray->readPixmaps(m0, 7);
setSequence(manarray);
setAnimated(true);
@@ -46,5 +46,5 @@ Man::Man(QCanvas* canvas) :
Man::Man(QCanvas* canvas, int x, int y) :
QCanvasSprite(0, canvas),
- splat("bang")
+ splat("bang") // No tr
{
manarray = new QCanvasPixmapArray();
@@ -63,5 +63,5 @@ Man::Man(QCanvas* canvas, int x, int y) :
QTime midnight(0, 0, 0);
srand(midnight.secsTo(QTime::currentTime()) );
- }
+ }
int yfallspeed = 0;
yfallspeed = (rand() % 3) + 1;
@@ -93,7 +93,14 @@ void Man::advance(int phase)
move(x(), canvas()->height()-26);
setVelocity(-2, 0);
- }
+ } else if (xVelocity() == -2) {
+ //
+ // There's been a resize event while this Man has
+ // been on the ground. Move the man back to the
+ // new ground location. This is not neat.
+ //
+ move(x(), canvas()->height()-26);
+ }
}
-}
+}
void Man::setInitialCoords()
@@ -111,5 +118,5 @@ void Man::setInitialCoords()
//check if man has reached the base
void Man::checkCollision()
-{
+{
if ( (x() < 23) && (y() == canvas()->height()-26)) {
QCanvasItem* item;
@@ -124,4 +131,14 @@ void Man::checkCollision()
}
}
+
+ //
+ // resize events may cause Man objects to appear
+ // outside the screen. Get rid of them if this
+ // is the case.
+ //
+ if ((x() < 0) || (x() > canvas()->width())) {
+ delete this;
+ return;
+ }
}