00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "codes.h"
00022 #include "man.h"
00023 #include "base.h"
00024
00025 #include <opie2/oresource.h>
00026
00027 int mancount;
00028
00029 Man::Man(QCanvas* canvas) :
00030 QCanvasSprite(0, canvas),
00031 splat("lose")
00032 {
00033 manarray = new QCanvasPixmapArray();
00034 QString m0 = Opie::Core::OResource::findPixmap("parashoot/man0001");
00035 m0.replace(QRegExp("0001"),"%1");
00036 manarray->readPixmaps(m0, 7);
00037 setSequence(manarray);
00038 setAnimated(true);
00039 mancount++;
00040 dead = false;
00041 start();
00042 }
00043
00044 Man::Man(QCanvas* canvas, int x, int y) :
00045 QCanvasSprite(0, canvas),
00046 splat("bang")
00047 {
00048 manarray = new QCanvasPixmapArray();
00049 QString m0 = Opie::Core::OResource::findPixmap("parashoot/man0001");
00050 m0.replace(QString("0001"),"%1");
00051 manarray->readPixmaps(m0, 7);
00052 setSequence(manarray);
00053 move(x, y);
00054 setFrame(5);
00055 setZ(300);
00056 show();
00057
00058 static bool first_time = TRUE;
00059 if (first_time) {
00060 first_time = FALSE;
00061 QTime midnight(0, 0, 0);
00062 srand(midnight.secsTo(QTime::currentTime()) );
00063 }
00064 int yfallspeed = 0;
00065 yfallspeed = (rand() % 3) + 1;
00066 setVelocity(0, yfallspeed);
00067
00068 mancount++;
00069 dead = false;
00070 }
00071 int f = 0;
00072
00073 void Man::advance(int phase)
00074 {
00075 QCanvasSprite::advance(phase);
00076 if (phase == 0) {
00077 checkCollision();
00078 if (dead) {
00079 if (count < 10) {
00080 setFrame(6);
00081 setVelocity(0,0);
00082 count++;
00083 } else {
00084 delete this;
00085 return;
00086 }
00087 }
00088 if (y() > canvas()->height()-43) {
00089 setFrame(f%5);
00090 f++;
00091 move(x(), canvas()->height()-26);
00092 setVelocity(-2, 0);
00093 } else if (xVelocity() == -2) {
00094
00095
00096
00097
00098
00099 move(x(), canvas()->height()-26);
00100 }
00101 }
00102 }
00103
00104 void Man::setInitialCoords()
00105 {
00106 static bool first_time = TRUE;
00107 if (first_time) {
00108 first_time = FALSE;
00109 QTime midnight(0, 0, 0);
00110 srand(midnight.secsTo(QTime::currentTime()) );
00111 }
00112 dx = rand() % (canvas()->width()-16);
00113 dy = -43;
00114 }
00115
00116
00117 void Man::checkCollision()
00118 {
00119 if ( (x() < 23) && (y() == canvas()->height()-26)) {
00120 QCanvasItem* item;
00121 QCanvasItemList l=collisions(FALSE);
00122 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
00123 item = *it;
00124 if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) {
00125 Base* base = (Base*) item;
00126 base->damageBase();
00127 start();
00128 }
00129 }
00130 }
00131
00132
00133
00134
00135
00136
00137 if ((x() < 0) || (x() > canvas()->width())) {
00138 delete this;
00139 return;
00140 }
00141 }
00142
00143 void Man::start()
00144 {
00145 setInitialCoords();
00146 move(dx, dy);
00147 setFrame(5);
00148 setZ(300);
00149 show();
00150
00151 static bool first_time = TRUE;
00152 if (first_time) {
00153 first_time = FALSE;
00154 QTime midnight(0, 0, 0);
00155 srand(midnight.secsTo(QTime::currentTime()) );
00156 }
00157 int yfallspeed = 0;
00158 yfallspeed = (rand() % 3) + 1;
00159 setVelocity(0, yfallspeed);
00160 }
00161
00162 void Man::done()
00163 {
00164 splat.play();
00165 count = 0;
00166 dead = true;
00167 setFrame(6);
00168 }
00169
00170 int Man::getManCount()
00171 {
00172 return mancount;
00173 }
00174
00175 void Man::setManCount(int count)
00176 {
00177 mancount = count;
00178 }
00179
00180
00181 int Man::rtti() const
00182 {
00183 return man_rtti;
00184 }
00185
00186 Man::~Man()
00187 {
00188 mancount--;
00189 }