summaryrefslogtreecommitdiff
path: root/noncore/games/parashoot/man.cpp
Unidiff
Diffstat (limited to 'noncore/games/parashoot/man.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/parashoot/man.cpp39
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,10 +1,10 @@
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**
@@ -15,40 +15,40 @@
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
29int mancount; 29int mancount;
30 30
31Man::Man(QCanvas* canvas) : 31Man::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
46Man::Man(QCanvas* canvas, int x, int y) : 46Man::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);
@@ -59,13 +59,13 @@ Man::Man(QCanvas* canvas, int x, int y) :
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;
@@ -89,15 +89,22 @@ void Man::advance(int phase)
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
99void Man::setInitialCoords() 106void 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;
@@ -107,25 +114,35 @@ void Man::setInitialCoords()
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
112void Man::checkCollision() 119void 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
128void Man::start() 145void Man::start()
129{ 146{
130 setInitialCoords(); 147 setInitialCoords();
131 move(dx, dy); 148 move(dx, dy);