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 "bullet.h"
00023 #include "man.h"
00024 #include "helicopter.h"
00025
00026 #include <opie2/oresource.h>
00027
00028 #include <qpe/qmath.h>
00029
00030
00031 int limit;
00032 int shotcount;
00033 int nobullets;
00034
00035 Bullet::Bullet(QCanvas* canvas, double angle, int cannonx, int cannony) :
00036 QCanvasSprite(0, canvas),
00037 bang("collide01")
00038 {
00039 QCanvasPixmapArray* bulletarray = new QCanvasPixmapArray(Opie::Core::OResource::findPixmap("parashoot/bullet"));
00040 setSequence(bulletarray);
00041 if (nobullets < limit) {
00042 nobullets++;
00043 move(cannonx, cannony);
00044 dy = 0;
00045 dx = 0;
00046 show();
00047 setXY(angle);
00048 setVelocity(-dx, -dy);
00049 bang.play();
00050 } else
00051 return;
00052 }
00053
00054 void Bullet::setXY(double angle)
00055 {
00056 double ang = angle;
00057 if ( (y() < 0) || (x() < 0) || (y() > canvas()->height()) ||
00058 (x() > canvas()->width()) )
00059 delete this;
00060 else {
00061 double radians = 0;
00062 radians = ang * 3.14159265/180;
00063 dx = (qCos(radians)) *7;
00064 dy = (qSin(radians)) *7;
00065 }
00066 }
00067
00068 void Bullet::setLimit(int amount)
00069 {
00070 limit = amount;
00071 }
00072
00073 void Bullet::setNobullets(int amount)
00074 {
00075 nobullets = amount;
00076 }
00077
00078 void Bullet::checkCollision()
00079 {
00080 QCanvasItem* item;
00081 QCanvasItemList l=collisions(FALSE);
00082 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
00083 item = *it;
00084 if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) {
00085 Man* deadman = (Man*)item;
00086 if (deadman->frame() != 5) return;
00087 deadman->done();
00088 emit score(10);
00089 setShotCount(shotcount+1);
00090 setAnimated(false);
00091 nobullets--;
00092 delete this;
00093 return;
00094 }
00095 else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) {
00096 Helicopter* deadchopper = (Helicopter*) item;
00097 deadchopper->done();
00098 emit score(50);
00099 setAnimated(false);
00100 nobullets--;
00101 delete this;
00102 return;
00103 }
00104 }
00105
00106 if ( (y() < 0) || (x() < 0) ||
00107 (y() > canvas()->height()) ||
00108 ( x() > canvas()->width())) {
00109 setAnimated(false);
00110 nobullets--;
00111 delete this;
00112 return;
00113 }
00114 }
00115
00116 void Bullet::advance(int phase)
00117 {
00118 QCanvasSprite::advance(phase);
00119
00120 if (phase == 0)
00121 checkCollision();
00122
00123 }
00124
00125 int Bullet::getShotCount()
00126 {
00127 return shotcount;
00128 }
00129
00130 void Bullet::setShotCount(int amount)
00131 {
00132 shotcount = amount;
00133 }
00134
00135 Bullet::~Bullet()
00136 {
00137
00138 }
00139
00140 int Bullet::rtti() const
00141 {
00142 return bullet_rtti;
00143 }