author | zecke <zecke> | 2004-02-06 14:32:10 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-06 14:32:10 (UTC) |
commit | b033733924e5d3454bb0a810c6a70d4ff0531d2b (patch) (unidiff) | |
tree | cafe130296468840db062af4a3335572804ee1f3 /noncore/games/parashoot/man.cpp | |
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
Diffstat (limited to 'noncore/games/parashoot/man.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/parashoot/man.cpp | 39 |
1 files changed, 28 insertions, 11 deletions
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,73 +1,73 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "codes.h" | 21 | #include "codes.h" |
22 | #include "man.h" | 22 | #include "man.h" |
23 | #include "base.h" | 23 | #include "base.h" |
24 | 24 | ||
25 | #include <qpe/resource.h> | 25 | #include <qtopia/resource.h> |
26 | 26 | ||
27 | #include <qregexp.h> | 27 | #include <qregexp.h> |
28 | 28 | ||
29 | int mancount; | 29 | int mancount; |
30 | 30 | ||
31 | Man::Man(QCanvas* canvas) : | 31 | Man::Man(QCanvas* canvas) : |
32 | QCanvasSprite(0, canvas), | 32 | QCanvasSprite(0, canvas), |
33 | splat("lose") | 33 | splat("lose") // No tr |
34 | { | 34 | { |
35 | manarray = new QCanvasPixmapArray(); | 35 | manarray = new QCanvasPixmapArray(); |
36 | QString m0 = Resource::findPixmap("parashoot/man0001"); | 36 | QString m0 = Resource::findPixmap("parashoot/man0001"); |
37 | m0.replace(QRegExp("0001"),"%1"); | 37 | m0.replace(QRegExp("0001"),"%1"); |
38 | manarray->readPixmaps(m0, 7); | 38 | manarray->readPixmaps(m0, 7); |
39 | setSequence(manarray); | 39 | setSequence(manarray); |
40 | setAnimated(true); | 40 | setAnimated(true); |
41 | mancount++; | 41 | mancount++; |
42 | dead = false; | 42 | dead = false; |
43 | start(); | 43 | start(); |
44 | } | 44 | } |
45 | 45 | ||
46 | Man::Man(QCanvas* canvas, int x, int y) : | 46 | Man::Man(QCanvas* canvas, int x, int y) : |
47 | QCanvasSprite(0, canvas), | 47 | QCanvasSprite(0, canvas), |
48 | splat("bang") | 48 | splat("bang") // No tr |
49 | { | 49 | { |
50 | manarray = new QCanvasPixmapArray(); | 50 | manarray = new QCanvasPixmapArray(); |
51 | QString m0 = Resource::findPixmap("parashoot/man0001"); | 51 | QString m0 = Resource::findPixmap("parashoot/man0001"); |
52 | m0.replace(QString("0001"),"%1"); | 52 | m0.replace(QString("0001"),"%1"); |
53 | manarray->readPixmaps(m0, 7); | 53 | manarray->readPixmaps(m0, 7); |
54 | setSequence(manarray); | 54 | setSequence(manarray); |
55 | move(x, y); | 55 | move(x, y); |
56 | setFrame(5); | 56 | setFrame(5); |
57 | setZ(300); | 57 | setZ(300); |
58 | show(); | 58 | show(); |
59 | 59 | ||
60 | static bool first_time = TRUE; | 60 | static bool first_time = TRUE; |
61 | if (first_time) { | 61 | if (first_time) { |
62 | first_time = FALSE; | 62 | first_time = FALSE; |
63 | QTime midnight(0, 0, 0); | 63 | QTime midnight(0, 0, 0); |
64 | srand(midnight.secsTo(QTime::currentTime()) ); | 64 | srand(midnight.secsTo(QTime::currentTime()) ); |
65 | } | 65 | } |
66 | int yfallspeed = 0; | 66 | int yfallspeed = 0; |
67 | yfallspeed = (rand() % 3) + 1; | 67 | yfallspeed = (rand() % 3) + 1; |
68 | setVelocity(0, yfallspeed); | 68 | setVelocity(0, yfallspeed); |
69 | 69 | ||
70 | mancount++; | 70 | mancount++; |
71 | dead = false; | 71 | dead = false; |
72 | } | 72 | } |
73 | int f = 0; | 73 | int f = 0; |
@@ -87,47 +87,64 @@ void Man::advance(int phase) | |||
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | if (y() > canvas()->height()-43) { | 90 | if (y() > canvas()->height()-43) { |
91 | setFrame(f%5); | 91 | setFrame(f%5); |
92 | f++; | 92 | f++; |
93 | move(x(), canvas()->height()-26); | 93 | move(x(), canvas()->height()-26); |
94 | setVelocity(-2, 0); | 94 | setVelocity(-2, 0); |
95 | } | 95 | } else if (xVelocity() == -2) { |
96 | // | ||
97 | // There's been a resize event while this Man has | ||
98 | // been on the ground. Move the man back to the | ||
99 | // new ground location. This is not neat. | ||
100 | // | ||
101 | move(x(), canvas()->height()-26); | ||
102 | } | ||
96 | } | 103 | } |
97 | } | 104 | } |
98 | 105 | ||
99 | void Man::setInitialCoords() | 106 | void Man::setInitialCoords() |
100 | { | 107 | { |
101 | static bool first_time = TRUE; | 108 | static bool first_time = TRUE; |
102 | if (first_time) { | 109 | if (first_time) { |
103 | first_time = FALSE; | 110 | first_time = FALSE; |
104 | QTime midnight(0, 0, 0); | 111 | QTime midnight(0, 0, 0); |
105 | srand(midnight.secsTo(QTime::currentTime()) ); | 112 | srand(midnight.secsTo(QTime::currentTime()) ); |
106 | } | 113 | } |
107 | dx = rand() % (canvas()->width()-16); | 114 | dx = rand() % (canvas()->width()-16); |
108 | dy = -43; //height of a man off the screen | 115 | dy = -43; //height of a man off the screen |
109 | } | 116 | } |
110 | 117 | ||
111 | //check if man has reached the base | 118 | //check if man has reached the base |
112 | void Man::checkCollision() | 119 | void Man::checkCollision() |
113 | { | 120 | { |
114 | if ( (x() < 23) && (y() == canvas()->height()-26)) { | 121 | if ( (x() < 23) && (y() == canvas()->height()-26)) { |
115 | QCanvasItem* item; | 122 | QCanvasItem* item; |
116 | QCanvasItemList l=collisions(FALSE); | 123 | QCanvasItemList l=collisions(FALSE); |
117 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 124 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
118 | item = *it; | 125 | item = *it; |
119 | if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) { | 126 | if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) { |
120 | Base* base = (Base*) item; | 127 | Base* base = (Base*) item; |
121 | base->damageBase(); | 128 | base->damageBase(); |
122 | start(); | 129 | start(); |
123 | } | 130 | } |
124 | } | 131 | } |
125 | } | 132 | } |
133 | |||
134 | // | ||
135 | // resize events may cause Man objects to appear | ||
136 | // outside the screen. Get rid of them if this | ||
137 | // is the case. | ||
138 | // | ||
139 | if ((x() < 0) || (x() > canvas()->width())) { | ||
140 | delete this; | ||
141 | return; | ||
142 | } | ||
126 | } | 143 | } |
127 | 144 | ||
128 | void Man::start() | 145 | void Man::start() |
129 | { | 146 | { |
130 | setInitialCoords(); | 147 | setInitialCoords(); |
131 | move(dx, dy); | 148 | move(dx, dy); |
132 | setFrame(5); | 149 | setFrame(5); |
133 | setZ(300); | 150 | setZ(300); |