Diffstat (limited to 'noncore/games/parashoot/helicopter.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/games/parashoot/helicopter.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/noncore/games/parashoot/helicopter.cpp b/noncore/games/parashoot/helicopter.cpp new file mode 100644 index 0000000..0923124 --- a/dev/null +++ b/noncore/games/parashoot/helicopter.cpp | |||
@@ -0,0 +1,114 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "helicopter.h" | ||
22 | #include "man.h" | ||
23 | #include "codes.h" | ||
24 | |||
25 | #include <qpe/resource.h> | ||
26 | |||
27 | #include <qregexp.h> | ||
28 | |||
29 | static QList<Helicopter> all; | ||
30 | |||
31 | Helicopter::Helicopter(QCanvas* canvas) : | ||
32 | QCanvasSprite(0, canvas), | ||
33 | chikachika("aland01") | ||
34 | { | ||
35 | all.append(this); | ||
36 | hits = 0; | ||
37 | QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray(); | ||
38 | QString h0 = Resource::findPixmap("parashoot/helicopter0001"); | ||
39 | h0.replace(QRegExp("0001"),"%1"); | ||
40 | helicopterarray->readPixmaps(h0,3 ); | ||
41 | setSequence(helicopterarray); | ||
42 | setAnimated(true); | ||
43 | move(canvas->width(), 5); | ||
44 | setVelocity(-2, 0); | ||
45 | chikachika.playLoop(); | ||
46 | show(); | ||
47 | } | ||
48 | |||
49 | Helicopter::~Helicopter() | ||
50 | { | ||
51 | all.remove(this); | ||
52 | } | ||
53 | |||
54 | int fr = 0; | ||
55 | |||
56 | void Helicopter::advance(int phase) | ||
57 | { | ||
58 | QCanvasSprite::advance(phase); | ||
59 | if (phase == 0) { | ||
60 | setFrame(fr%3); | ||
61 | fr++; | ||
62 | checkCollision(); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | void Helicopter::checkCollision() | ||
67 | { | ||
68 | if (x() == 6) { | ||
69 | setAnimated(false); //setVelocity(0, 0); | ||
70 | dropman(); | ||
71 | } | ||
72 | if (x() < 0) | ||
73 | done(); | ||
74 | } | ||
75 | |||
76 | void Helicopter::dropman() | ||
77 | { | ||
78 | (void)new Man(canvas(), 15, 25); | ||
79 | (void)new Man(canvas(), 35, 25); | ||
80 | takeOff(); | ||
81 | } | ||
82 | |||
83 | void Helicopter::done() | ||
84 | { | ||
85 | hits++; | ||
86 | if (hits >= 2) { | ||
87 | setAnimated(false); | ||
88 | delete this; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | void Helicopter::takeOff() | ||
93 | { | ||
94 | setVelocity(-1, 0); | ||
95 | } | ||
96 | |||
97 | int Helicopter::rtti() const | ||
98 | { | ||
99 | return helicopter_rtti; | ||
100 | } | ||
101 | |||
102 | void Helicopter::silenceAll() | ||
103 | { | ||
104 | for (Helicopter* h = all.first(); h; h = all.next()) | ||
105 | h->chikachika.stop(); | ||
106 | } | ||
107 | |||
108 | void Helicopter::deleteAll() | ||
109 | { | ||
110 | Helicopter* h; | ||
111 | while ((h = all.first())) | ||
112 | delete h; | ||
113 | } | ||
114 | |||