author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/games/parashoot/man.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'noncore/games/parashoot/man.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/parashoot/man.cpp | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/noncore/games/parashoot/man.cpp b/noncore/games/parashoot/man.cpp new file mode 100644 index 0000000..8435572 --- a/dev/null +++ b/noncore/games/parashoot/man.cpp | |||
@@ -0,0 +1,174 @@ | |||
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 "codes.h" | ||
22 | #include "man.h" | ||
23 | #include "base.h" | ||
24 | |||
25 | #include <qpe/resource.h> | ||
26 | |||
27 | #include <qregexp.h> | ||
28 | |||
29 | int mancount; | ||
30 | |||
31 | Man::Man(QCanvas* canvas) : | ||
32 | QCanvasSprite(0, canvas), | ||
33 | splat("lose") | ||
34 | { | ||
35 | manarray = new QCanvasPixmapArray(); | ||
36 | QString m0 = Resource::findPixmap("parashoot/man0001"); | ||
37 | m0.replace(QRegExp("0001"),"%1"); | ||
38 | manarray->readPixmaps(m0, 7); | ||
39 | setSequence(manarray); | ||
40 | setAnimated(true); | ||
41 | mancount++; | ||
42 | dead = false; | ||
43 | start(); | ||
44 | } | ||
45 | |||
46 | Man::Man(QCanvas* canvas, int x, int y) : | ||
47 | QCanvasSprite(0, canvas), | ||
48 | splat("bang") | ||
49 | { | ||
50 | manarray = new QCanvasPixmapArray(); | ||
51 | QString m0 = Resource::findPixmap("parashoot/man0001"); | ||
52 | m0.replace(QString("0001"),"%1"); | ||
53 | manarray->readPixmaps(m0, 7); | ||
54 | setSequence(manarray); | ||
55 | move(x, y); | ||
56 | setFrame(5); | ||
57 | setZ(300); | ||
58 | show(); | ||
59 | |||
60 | static bool first_time = TRUE; | ||
61 | if (first_time) { | ||
62 | first_time = FALSE; | ||
63 | QTime midnight(0, 0, 0); | ||
64 | srand(midnight.secsTo(QTime::currentTime()) ); | ||
65 | } | ||
66 | int yfallspeed = 0; | ||
67 | yfallspeed = (rand() % 3) + 1; | ||
68 | setVelocity(0, yfallspeed); | ||
69 | |||
70 | mancount++; | ||
71 | dead = false; | ||
72 | } | ||
73 | int f = 0; | ||
74 | |||
75 | void Man::advance(int phase) | ||
76 | { | ||
77 | QCanvasSprite::advance(phase); | ||
78 | if (phase == 0) { | ||
79 | checkCollision(); | ||
80 | if (dead) { | ||
81 | if (count < 10) { | ||
82 | setFrame(6); | ||
83 | setVelocity(0,0); | ||
84 | count++; | ||
85 | } else { | ||
86 | delete this; | ||
87 | return; | ||
88 | } | ||
89 | } | ||
90 | if (y() > canvas()->height()-43) { | ||
91 | setFrame(f%5); | ||
92 | f++; | ||
93 | move(x(), canvas()->height()-26); | ||
94 | setVelocity(-2, 0); | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void Man::setInitialCoords() | ||
100 | { | ||
101 | static bool first_time = TRUE; | ||
102 | if (first_time) { | ||
103 | first_time = FALSE; | ||
104 | QTime midnight(0, 0, 0); | ||
105 | srand(midnight.secsTo(QTime::currentTime()) ); | ||
106 | } | ||
107 | dx = rand() % (canvas()->width()-16); | ||
108 | dy = -43; //height of a man off the screen | ||
109 | } | ||
110 | |||
111 | //check if man has reached the base | ||
112 | void Man::checkCollision() | ||
113 | { | ||
114 | if ( (x() < 23) && (y() == canvas()->height()-26)) { | ||
115 | QCanvasItem* item; | ||
116 | QCanvasItemList l=collisions(FALSE); | ||
117 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | ||
118 | item = *it; | ||
119 | if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) { | ||
120 | Base* base = (Base*) item; | ||
121 | base->damageBase(); | ||
122 | start(); | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | |||
128 | void Man::start() | ||
129 | { | ||
130 | setInitialCoords(); | ||
131 | move(dx, dy); | ||
132 | setFrame(5); | ||
133 | setZ(300); | ||
134 | show(); | ||
135 | |||
136 | static bool first_time = TRUE; | ||
137 | if (first_time) { | ||
138 | first_time = FALSE; | ||
139 | QTime midnight(0, 0, 0); | ||
140 | srand(midnight.secsTo(QTime::currentTime()) ); | ||
141 | } | ||
142 | int yfallspeed = 0; | ||
143 | yfallspeed = (rand() % 3) + 1; | ||
144 | setVelocity(0, yfallspeed); | ||
145 | } | ||
146 | |||
147 | void Man::done() | ||
148 | { | ||
149 | splat.play(); | ||
150 | count = 0; | ||
151 | dead = true; | ||
152 | setFrame(6); | ||
153 | } | ||
154 | |||
155 | int Man::getManCount() | ||
156 | { | ||
157 | return mancount; | ||
158 | } | ||
159 | |||
160 | void Man::setManCount(int count) | ||
161 | { | ||
162 | mancount = count; | ||
163 | } | ||
164 | |||
165 | |||
166 | int Man::rtti() const | ||
167 | { | ||
168 | return man_rtti; | ||
169 | } | ||
170 | |||
171 | Man::~Man() | ||
172 | { | ||
173 | mancount--; | ||
174 | } | ||