Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

helicopter.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "helicopter.h"
00022 #include "man.h"
00023 #include "codes.h"
00024 
00025 #include <opie2/oresource.h>
00026 
00027 
00028 static QList<Helicopter> all;
00029 
00030 Helicopter::Helicopter(QCanvas* canvas) :
00031     QCanvasSprite(0, canvas),
00032     chikachika("aland01")
00033 {
00034     all.append(this);
00035     hits = 0;
00036     QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray();
00037     QString h0 = Opie::Core::OResource::findPixmap("parashoot/helicopter0001");
00038     h0.replace(QRegExp("0001"),"%1");
00039     helicopterarray->readPixmaps(h0,4 );
00040 
00041     setSequence(helicopterarray);
00042     setAnimated(true);
00043     move(canvas->width(), 5);
00044     setVelocity(-2, 0);
00045     chikachika.playLoop();
00046     show();
00047 }
00048 
00049 Helicopter::~Helicopter()
00050 {
00051     all.remove(this);
00052 }
00053 
00054 int fr = 0;
00055 
00056 void Helicopter::advance(int phase)
00057 {
00058    QCanvasSprite::advance(phase);
00059    if (phase == 0) {
00060         if (frame() == 3) {
00061             delete this;
00062             return;
00063         }
00064 
00065         if (hits >= 2) {
00066             setFrame(3);
00067         } else {
00068             setFrame(fr%3);
00069             fr++;
00070             checkCollision();
00071         }
00072    }
00073 }
00074 
00075 void Helicopter::checkCollision()
00076 {
00077     if (x() == 6) {
00078         setAnimated(false); //setVelocity(0, 0);
00079         dropman();
00080     }
00081     if (x() < 0)
00082         done();
00083 }
00084 
00085 void Helicopter::dropman()
00086 {
00087     (void)new Man(canvas(), 15, 25); 
00088     (void)new Man(canvas(), 35, 25);
00089     takeOff();
00090 }
00091 
00092 void Helicopter::done()
00093 {
00094     hits++;
00095 }
00096 
00097 void Helicopter::takeOff()
00098 {
00099     setVelocity(-1, 0);
00100 }
00101 
00102 int Helicopter::rtti() const
00103 {
00104     return helicopter_rtti;
00105 }
00106 
00107 void Helicopter::silenceAll()
00108 {
00109     for (Helicopter* h = all.first(); h; h = all.next())
00110         h->chikachika.stop();
00111 }
00112 
00113 void Helicopter::deleteAll()
00114 {
00115     Helicopter* h;
00116     while ((h = all.first()))
00117         delete h;
00118 }
00119 

Generated on Sat Nov 5 16:17:23 2005 for OPIE by  doxygen 1.4.2