summaryrefslogtreecommitdiff
path: root/noncore/games/parashoot/bullet.cpp
Unidiff
Diffstat (limited to 'noncore/games/parashoot/bullet.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/parashoot/bullet.cpp142
1 files changed, 142 insertions, 0 deletions
diff --git a/noncore/games/parashoot/bullet.cpp b/noncore/games/parashoot/bullet.cpp
new file mode 100644
index 0000000..584f564
--- a/dev/null
+++ b/noncore/games/parashoot/bullet.cpp
@@ -0,0 +1,142 @@
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 "bullet.h"
23#include "man.h"
24#include "helicopter.h"
25
26#include <qpe/resource.h>
27#include <qpe/qmath.h>
28
29
30int limit;
31int shotcount;
32int nobullets;
33
34Bullet::Bullet(QCanvas* canvas, double angle, int cannonx, int cannony) :
35 QCanvasSprite(0, canvas),
36 bang("collide01")
37{
38 QCanvasPixmapArray* bulletarray = new QCanvasPixmapArray(Resource::findPixmap("parashoot/bullet"));
39 setSequence(bulletarray);
40 if (nobullets < limit) {
41 nobullets++;
42 move(cannonx, cannony);
43 dy = 0;
44 dx = 0;
45 show();
46 setXY(angle);
47 setVelocity(-dx, -dy);
48 bang.play();
49 } else
50 return;
51}
52
53void Bullet::setXY(double angle)
54{
55 double ang = angle;
56 if ( (y() < 0) || (x() < 0) || (y() > canvas()->height()) ||
57 (x() > canvas()->width()) )
58 delete this;
59 else {
60 double radians = 0;
61 radians = ang * 3.14159265/180;
62 dx = (qCos(radians)) *7;
63 dy = (qSin(radians)) *7;
64 }
65}
66
67void Bullet::setLimit(int amount)
68{
69 limit = amount;
70}
71
72void Bullet::setNobullets(int amount)
73{
74 nobullets = amount;
75}
76
77void Bullet::checkCollision()
78{
79 QCanvasItem* item;
80 QCanvasItemList l=collisions(FALSE);
81 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
82 item = *it;
83 if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) {
84 Man* deadman = (Man*)item;
85 if (deadman->frame() != 5) return;
86 deadman->done();
87 emit score(10);
88 setShotCount(shotcount+1);
89 setAnimated(false);
90 nobullets--;
91 delete this;
92 return;
93 }
94 else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) {
95 Helicopter* deadchopper = (Helicopter*) item;
96 deadchopper->done();
97 emit score(50);
98 setAnimated(false);
99 nobullets--;
100 delete this;
101 return;
102 }
103 }
104 //check shot is not out of bounds
105 if ( (y() < 0) || (x() < 0) ||
106 (y() > canvas()->height()) ||
107 ( x() > canvas()->width())) {
108 setAnimated(false);
109 nobullets--;
110 delete this;
111 return;
112 }
113}
114
115void Bullet::advance(int phase)
116{
117 QCanvasSprite::advance(phase);
118
119 if (phase == 0)
120 checkCollision();
121
122}
123
124int Bullet::getShotCount()
125{
126 return shotcount;
127}
128
129void Bullet::setShotCount(int amount)
130{
131 shotcount = amount;
132}
133
134Bullet::~Bullet()
135{
136
137}
138
139int Bullet::rtti() const
140{
141 return bullet_rtti;
142}