Diffstat (limited to 'noncore/games/parashoot/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/parashoot/interface.cpp | 74 |
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 @@ /********************************************************************** -** 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> @@ -35,3 +35,7 @@ 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"), @@ -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,12 +256,17 @@ void ParaShoot::keyPressEvent(QKeyEvent* event) 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: @@ -247,3 +279,3 @@ void ParaShoot::keyReleaseEvent(QKeyEvent* event) { - if ( lastcannonkey == event->key() ) + if ( cannon && lastcannonkey == event->key() ) cannon->pointCannon(Cannon::NoDir); |