-rw-r--r-- | noncore/games/parashoot/base.cpp | 12 | ||||
-rw-r--r-- | noncore/games/parashoot/base.h | 8 | ||||
-rw-r--r-- | noncore/games/parashoot/cannon.cpp | 24 | ||||
-rw-r--r-- | noncore/games/parashoot/cannon.h | 6 | ||||
-rw-r--r-- | noncore/games/parashoot/helicopter.cpp | 22 | ||||
-rw-r--r-- | noncore/games/parashoot/helicopter.h | 6 | ||||
-rw-r--r-- | noncore/games/parashoot/interface.cpp | 66 | ||||
-rw-r--r-- | noncore/games/parashoot/interface.h | 14 | ||||
-rw-r--r-- | noncore/games/parashoot/man.cpp | 27 |
9 files changed, 131 insertions, 54 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,5 +1,5 @@ /********************************************************************** -** 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. ** @@ -23,3 +23,3 @@ -#include <qpe/resource.h> +#include <qtopia/resource.h> @@ -71 +71,7 @@ int Base::rtti() const } + +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,5 +1,5 @@ /********************************************************************** -** 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. ** @@ -20,3 +20,3 @@ -#include <qpe/sound.h> +#include <qtopia/sound.h> @@ -34,2 +34,4 @@ public: + void reposition(void); + private: 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,5 +1,5 @@ /********************************************************************** -** 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. ** @@ -20,3 +20,3 @@ -#include <qpe/resource.h> +#include <qtopia/resource.h> @@ -40,6 +40,5 @@ shotsfired=0; 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; @@ -140 +139,12 @@ int Cannon::rtti() const } + +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,5 +1,5 @@ /********************************************************************** -** 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. ** @@ -41,2 +41,4 @@ int shotsFired() { return shotsfired; }; + void reposition(void); + protected: 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,5 +1,5 @@ /********************************************************************** -** 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. ** @@ -24,3 +24,3 @@ -#include <qpe/resource.h> +#include <qtopia/resource.h> @@ -39,3 +39,4 @@ Helicopter::Helicopter(QCanvas* canvas) : h0.replace(QRegExp("0001"),"%1"); - helicopterarray->readPixmaps(h0,3 ); + helicopterarray->readPixmaps(h0,4 ); + setSequence(helicopterarray); @@ -59,2 +60,10 @@ void Helicopter::advance(int phase) if (phase == 0) { + if (frame() == 3) { + delete this; + return; + } + + if (hits >= 2) { + setFrame(3); + } else { setFrame(fr%3); @@ -64,2 +73,3 @@ void Helicopter::advance(int phase) } +} @@ -85,6 +95,2 @@ 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,5 +1,5 @@ /********************************************************************** -** 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. ** @@ -20,3 +20,3 @@ -#include <qpe/sound.h> +#include <qtopia/sound.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,5 +1,5 @@ /********************************************************************** -** 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. ** @@ -23,4 +23,4 @@ -#include <qpe/resource.h> -#include <qpe/qpeapplication.h> +#include <qtopia/qpeapplication.h> +#include <qtopia/resource.h> @@ -30,3 +30,3 @@ #include <qstyle.h> -#include <qpe/qpetoolbar.h> +#include <qtoolbar.h> #include <qtoolbutton.h> @@ -36,2 +36,6 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : canvas(232, 258), + cannon(NULL), + base(NULL), + gamestopped( true ), + waitover( false ), fanfare("level_up"), @@ -41,5 +45,5 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); + + updatespeed = 80; canvas.setAdvancePeriod(80); - QPixmap bg = Resource::loadPixmap("parashoot/sky"); - canvas.setBackgroundPixmap(bg); @@ -54,5 +58,3 @@ 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"); @@ -74,4 +76,2 @@ ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : setFocusPolicy(StrongFocus); - - newGame(); } @@ -84,4 +84,30 @@ void ParaShoot::resizeEvent(QResizeEvent *) 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); +} @@ -152,4 +178,5 @@ void ParaShoot::gameOver() 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); @@ -229,5 +256,7 @@ void ParaShoot::keyPressEvent(QKeyEvent* event) case Key_Space: + if ( cannon ) cannon->shoot(); break; - case Key_Left: + case Key_Left:{ + if (cannon ) cannon->pointCannon(Cannon::Left); @@ -235,3 +264,5 @@ void ParaShoot::keyPressEvent(QKeyEvent* event) break; - case Key_Right: + } + case Key_Right:{ + if ( cannon ) cannon->pointCannon(Cannon::Right); @@ -239,2 +270,3 @@ void ParaShoot::keyPressEvent(QKeyEvent* event) break; + } default: @@ -247,3 +279,3 @@ 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,5 +1,5 @@ /********************************************************************** -** 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. ** @@ -24,3 +24,3 @@ -#include <qpe/sound.h> +#include <qtopia/sound.h> @@ -40,5 +40,6 @@ class ParaShoot : public QMainWindow { 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(); @@ -53,2 +54,4 @@ protected: virtual void resizeEvent(QResizeEvent *e); + virtual void focusOutEvent(QFocusEvent *); + virtual void focusInEvent(QFocusEvent *); @@ -66,3 +69,2 @@ private: Base* base; - QCanvasText* gameover; QLabel* levelscore; 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,5 +1,5 @@ /********************************************************************** -** 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. ** @@ -24,3 +24,3 @@ -#include <qpe/resource.h> +#include <qtopia/resource.h> @@ -32,3 +32,3 @@ Man::Man(QCanvas* canvas) : QCanvasSprite(0, canvas), - splat("lose") + splat("lose") // No tr { @@ -47,3 +47,3 @@ Man::Man(QCanvas* canvas, int x, int y) : QCanvasSprite(0, canvas), - splat("bang") + splat("bang") // No tr { @@ -94,2 +94,9 @@ void Man::advance(int phase) 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); } @@ -125,2 +132,12 @@ 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; + } } |