author | zecke <zecke> | 2004-02-06 14:32:10 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-06 14:32:10 (UTC) |
commit | b033733924e5d3454bb0a810c6a70d4ff0531d2b (patch) (side-by-side diff) | |
tree | cafe130296468840db062af4a3335572804ee1f3 | |
parent | f60cbb888e72b3eaf49af6f72fa183e6d44ae389 (diff) | |
download | opie-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
-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,71 +1,77 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "codes.h" #include "base.h" #include "man.h" -#include <qpe/resource.h> +#include <qtopia/resource.h> #include <qregexp.h> int damage; Base::Base(QCanvas* canvas) : QCanvasSprite(0, canvas), kaboom("landmine"), ohdear("crmble01") { basearray = new QCanvasPixmapArray(); QString b0 = Resource::findPixmap("parashoot/b0001"); b0.replace(QRegExp("0001"),"%1"); basearray->readPixmaps(b0, 4); setSequence(basearray); setFrame(0); move(2, canvas->height()-50); setZ(10); show(); damage = 0; } void Base::damageBase() { damage++; switch(damage) { case 1: setFrame(1); ohdear.play(); break; case 2: setFrame(2); ohdear.play(); break; case 3: setFrame(3); kaboom.play(); break; } show(); } bool Base::baseDestroyed() { return (damage >= 3); } Base::~Base() { } 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,38 +1,40 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#include <qpe/sound.h> +#include <qtopia/sound.h> #include <qcanvas.h> class Base : public QCanvasSprite { public: Base(QCanvas*); ~Base(); void damageBase(); int rtti() const; static bool baseDestroyed(); + void reposition(void); + private: QCanvasPixmapArray* basearray; Sound kaboom, ohdear; }; 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,140 +1,150 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#include <qpe/resource.h> +#include <qtopia/resource.h> #include <qregexp.h> #include "codes.h" #include "cannon.h" Cannon::Cannon(QCanvas* canvas) : QCanvasSprite(0, canvas) { shotsfired=0; index = 8; cannonx = 0; cannony = 0; cannonarray = new QCanvasPixmapArray(); QString c0 = Resource::findPixmap("parashoot/can0001"); c0.replace(QRegExp("0001"),"%1"); cannonarray->readPixmaps(c0,17); 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; setAnimated(TRUE); show(); } void Cannon::advance(int stage) { if ( stage == 1 && moveDelay-- == 0 ) { if (movedir == Left) { if (index > 0) { setFrame(index-1); index--; } } if (movedir == Right) { if (index < 16) { setFrame(index+1); index++; } } moveDelay = 0; } } void Cannon::pointCannon(Direction dir) { movedir = dir; moveDelay = 0; advance(1); moveDelay = 1; } void Cannon::setCoords() { switch(index) { case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break; case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break; case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break; case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break; case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break; case 5: cannonx = barrelxpos-19; cannony = barrelypos; break; case 6: cannonx = barrelxpos-15; cannony = barrelypos; break; case 7: cannonx = barrelxpos-10; cannony = barrelypos; break; case 8: cannonx = barrelxpos; cannony = barrelypos; break; case 9: cannonx = barrelxpos+2; cannony = barrelypos; break; case 10: cannonx = barrelxpos+6; cannony = barrelypos; break; case 11: cannonx = barrelxpos+8; cannony = barrelypos; break; case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break; case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break; case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break; case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break; case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break; } } double Cannon::shootAngle() { switch(index) { case 0: return 30.0; case 1: return 37.5; case 2: return 45.0; case 3: return 52.5; case 4: return 60.0; case 5: return 67.5; case 6: return 75.0; case 7: return 82.5; case 8: return 90.0; case 9: return 97.5; case 10: return 105.0; case 11: return 112.5; case 12: return 120.0; case 13: return 127.5; case 14: return 135.0; case 15: return 142.5; case 16: return 150.0; } return 0; } void Cannon::shoot() { setCoords(); Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony); connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int))); shotsfired++; } Cannon::~Cannon() { } 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,58 +1,60 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qcanvas.h> #include "bullet.h" class Cannon : public QObject, public QCanvasSprite { Q_OBJECT public: Cannon(QCanvas*); //create cannon ~Cannon(); //destroy cannon enum Direction{ Left, Right, NoDir }; void pointCannon(Direction dir); void setCoords(); double shootAngle(); void shoot(); int rtti() const; int shotsFired() { return shotsfired; }; + void reposition(void); + protected: void advance(int stage); signals: void score(int); private: QCanvasPixmapArray* cannonarray; int index; int cannonx; int cannony; int barrelxpos; int barrelypos; int moveDelay; Direction movedir; int shotsfired; }; 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,114 +1,120 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "helicopter.h" #include "man.h" #include "codes.h" -#include <qpe/resource.h> +#include <qtopia/resource.h> #include <qregexp.h> static QList<Helicopter> all; Helicopter::Helicopter(QCanvas* canvas) : QCanvasSprite(0, canvas), chikachika("aland01") { all.append(this); hits = 0; QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray(); QString h0 = Resource::findPixmap("parashoot/helicopter0001"); h0.replace(QRegExp("0001"),"%1"); - helicopterarray->readPixmaps(h0,3 ); + helicopterarray->readPixmaps(h0,4 ); + setSequence(helicopterarray); setAnimated(true); move(canvas->width(), 5); setVelocity(-2, 0); chikachika.playLoop(); show(); } Helicopter::~Helicopter() { all.remove(this); } int fr = 0; void Helicopter::advance(int phase) { QCanvasSprite::advance(phase); if (phase == 0) { + if (frame() == 3) { + delete this; + return; + } + + if (hits >= 2) { + setFrame(3); + } else { setFrame(fr%3); fr++; checkCollision(); } } +} void Helicopter::checkCollision() { if (x() == 6) { setAnimated(false); //setVelocity(0, 0); dropman(); } if (x() < 0) done(); } void Helicopter::dropman() { (void)new Man(canvas(), 15, 25); (void)new Man(canvas(), 35, 25); takeOff(); } void Helicopter::done() { hits++; - if (hits >= 2) { - setAnimated(false); - delete this; - } } void Helicopter::takeOff() { setVelocity(-1, 0); } int Helicopter::rtti() const { return helicopter_rtti; } void Helicopter::silenceAll() { for (Helicopter* h = all.first(); h; h = all.next()) h->chikachika.stop(); } void Helicopter::deleteAll() { Helicopter* h; while ((h = all.first())) delete h; } 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,45 +1,45 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#include <qpe/sound.h> +#include <qtopia/sound.h> #include <qcanvas.h> class Helicopter : public QCanvasSprite { public: Helicopter(QCanvas*); ~Helicopter(); void advance(int phase); void checkCollision(); void dropman(); void takeOff(); void done(); static void silenceAll(); static void deleteAll(); int rtti() const; private: int hits; Sound chikachika; }; 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,250 +1,282 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "interface.h" #include "man.h" -#include <qpe/resource.h> -#include <qpe/qpeapplication.h> +#include <qtopia/qpeapplication.h> +#include <qtopia/resource.h> #include <qlabel.h> #include <qmessagebox.h> #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), + cannon(NULL), + base(NULL), + gamestopped( true ), + waitover( false ), fanfare("level_up"), score(0) { 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); pb->setFocus(); setToolBarsMovable( FALSE ); QToolBar* toolbar = new QToolBar(this); toolbar->setHorizontalStretchable( TRUE ); 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"); levelscore = new QLabel(toolbar); levelscore->setBackgroundMode( PaletteButton ); levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); toolbar->setStretchableWidget( levelscore ); showScore(0,0); setCentralWidget(pb); autoDropTimer = new QTimer(this); connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); pauseTimer = new QTimer(this); connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); setFocusPolicy(StrongFocus); - - newGame(); } void ParaShoot::resizeEvent(QResizeEvent *) { QSize s = centralWidget()->size(); 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 ) { levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); } void ParaShoot::newGame() { clear(); if (pauseTimer->isActive()) pauseTimer->stop(); clear(); Man::setManCount(0); score = 0; Bullet::setShotCount(0); Bullet::setNobullets(0); nomen = 2; Bullet::setLimit(nomen); level = 0; updatespeed = 80; showScore(0,0); gamestopped = false; Helicopter::deleteAll(); waitover = true; base = new Base(&canvas); cannon = new Cannon(&canvas); connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); autoDropTimer->start(100); } void ParaShoot::clear() { autoDropTimer->stop(); // QCanvasItem* item; QCanvasItemList l = canvas.allItems(); for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { delete *it; } } void ParaShoot::gameOver() { QCanvasItem* item; QCanvasItemList l = canvas.allItems(); for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { item = *it; if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) item->setAnimated(false); } autoDropTimer->stop(); Helicopter::silenceAll(); int shots = Bullet::getShotCount(); int shotsFired = cannon->shotsFired(); if ( shotsFired == 0 ) shotsFired = 1; QCanvasText* gameover = new QCanvasText( tr( " GAME OVER!\n" " Your Score: %1\n" " Parachuters Killed: %2\n" " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), &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(); gamestopped = true; waitover = false; pauseTimer->start(3000); } void ParaShoot::wait() { waitover = true; pauseTimer->stop(); } void ParaShoot::play() { if (Man::getManCount() < nomen ) { new Man(&canvas); } if (Base::baseDestroyed()) { gameOver(); return; } } void ParaShoot::increaseScore(int x) { score += x; if ( score / 150 != (score-x) / 150 ) levelUp(); showScore(level,score); } void ParaShoot::levelUp() { level++; int stage = level % 3; switch(stage) { case 0: nomen++; Bullet::setLimit(nomen); fanfare.play(); break; case 1: new Helicopter(&canvas); break; case 2: moveFaster(); fanfare.play(); break; default: return; } } void ParaShoot::moveFaster() { if (updatespeed > 50) updatespeed = updatespeed-5; else updatespeed = updatespeed-3; canvas.setAdvancePeriod(updatespeed); } void ParaShoot::keyPressEvent(QKeyEvent* event) { if (gamestopped) { if (waitover) newGame(); else return; } else { switch(event->key()) { case Key_Up: case Key_F1: case Key_F9: case Key_Space: + if ( cannon ) cannon->shoot(); break; - case Key_Left: + case Key_Left:{ + if (cannon ) cannon->pointCannon(Cannon::Left); lastcannonkey=Key_Left; break; - case Key_Right: + } + case Key_Right:{ + if ( cannon ) cannon->pointCannon(Cannon::Right); lastcannonkey=Key_Right; break; + } default: return; } } } 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,80 +1,82 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "cannon.h" #include "base.h" #include "helicopter.h" -#include <qpe/sound.h> +#include <qtopia/sound.h> #include <qmainwindow.h> #include <qtimer.h> #include <qlabel.h> class QCanvas; class Helicopter; //enum Direction{ // 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(); int mancount; void levelUp(); void moveFaster(); protected: virtual void keyPressEvent(QKeyEvent*); virtual void keyReleaseEvent(QKeyEvent*); virtual void resizeEvent(QResizeEvent *e); + virtual void focusOutEvent(QFocusEvent *); + virtual void focusInEvent(QFocusEvent *); private slots: void increaseScore(int); void newGame(); void play(); void wait(); private: void showScore( int score, int level ); QCanvasView* pb; QCanvas canvas; Cannon* cannon; Base* base; - QCanvasText* gameover; QLabel* levelscore; int nomen; int level; int oldscore; int updatespeed; QTimer* autoDropTimer; QTimer* pauseTimer; bool gamestopped; bool waitover; Sound fanfare; 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,174 +1,191 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "codes.h" #include "man.h" #include "base.h" -#include <qpe/resource.h> +#include <qtopia/resource.h> #include <qregexp.h> 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); setSequence(manarray); setAnimated(true); mancount++; dead = false; start(); } Man::Man(QCanvas* canvas, int x, int y) : QCanvasSprite(0, canvas), - splat("bang") + splat("bang") // No tr { manarray = new QCanvasPixmapArray(); QString m0 = Resource::findPixmap("parashoot/man0001"); m0.replace(QString("0001"),"%1"); manarray->readPixmaps(m0, 7); setSequence(manarray); move(x, y); setFrame(5); setZ(300); show(); static bool first_time = TRUE; if (first_time) { first_time = FALSE; QTime midnight(0, 0, 0); srand(midnight.secsTo(QTime::currentTime()) ); } int yfallspeed = 0; yfallspeed = (rand() % 3) + 1; setVelocity(0, yfallspeed); mancount++; dead = false; } int f = 0; void Man::advance(int phase) { QCanvasSprite::advance(phase); if (phase == 0) { checkCollision(); if (dead) { if (count < 10) { setFrame(6); setVelocity(0,0); count++; } else { delete this; return; } } if (y() > canvas()->height()-43) { setFrame(f%5); f++; 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() { static bool first_time = TRUE; if (first_time) { first_time = FALSE; QTime midnight(0, 0, 0); srand(midnight.secsTo(QTime::currentTime()) ); } dx = rand() % (canvas()->width()-16); dy = -43; //height of a man off the screen } //check if man has reached the base void Man::checkCollision() { if ( (x() < 23) && (y() == canvas()->height()-26)) { QCanvasItem* item; QCanvasItemList l=collisions(FALSE); for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { item = *it; if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) { Base* base = (Base*) item; base->damageBase(); start(); } } } + + // + // 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; + } } void Man::start() { setInitialCoords(); move(dx, dy); setFrame(5); setZ(300); show(); static bool first_time = TRUE; if (first_time) { first_time = FALSE; QTime midnight(0, 0, 0); srand(midnight.secsTo(QTime::currentTime()) ); } int yfallspeed = 0; yfallspeed = (rand() % 3) + 1; setVelocity(0, yfallspeed); } void Man::done() { splat.play(); count = 0; dead = true; setFrame(6); } int Man::getManCount() { return mancount; } void Man::setManCount(int count) { mancount = count; } int Man::rtti() const { return man_rtti; } Man::~Man() { mancount--; } |