summaryrefslogtreecommitdiff
path: root/noncore/games/parashoot/cannon.cpp
Unidiff
Diffstat (limited to 'noncore/games/parashoot/cannon.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/parashoot/cannon.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/noncore/games/parashoot/cannon.cpp b/noncore/games/parashoot/cannon.cpp
new file mode 100644
index 0000000..3c0a5fe
--- a/dev/null
+++ b/noncore/games/parashoot/cannon.cpp
@@ -0,0 +1,140 @@
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 <qpe/resource.h>
22
23#include <qregexp.h>
24
25#include "codes.h"
26#include "cannon.h"
27
28Cannon::Cannon(QCanvas* canvas) :
29 QCanvasSprite(0, canvas)
30{
31shotsfired=0;
32 index = 8;
33 cannonx = 0;
34 cannony = 0;
35 cannonarray = new QCanvasPixmapArray();
36 QString c0 = Resource::findPixmap("parashoot/can0001");
37 c0.replace(QRegExp("0001"),"%1");
38 cannonarray->readPixmaps(c0,17);
39 setSequence(cannonarray);
40 setFrame(index);
41 move(canvas->width()/2-20, canvas->height()-32);
42 // co ords for barrel of cannon when upright
43 barrelypos = canvas->height()-32;
44 barrelxpos = canvas->width()/2;
45 movedir = NoDir;
46 moveDelay = 0;
47 setAnimated(TRUE);
48 show();
49}
50
51void Cannon::advance(int stage)
52{
53 if ( stage == 1 && moveDelay-- == 0 ) {
54 if (movedir == Left) {
55 if (index > 0) {
56 setFrame(index-1);
57 index--;
58 }
59 }
60 if (movedir == Right) {
61 if (index < 16) {
62 setFrame(index+1);
63 index++;
64 }
65 }
66 moveDelay = 0;
67 }
68}
69
70void Cannon::pointCannon(Direction dir)
71{
72 movedir = dir;
73 moveDelay = 0;
74 advance(1);
75 moveDelay = 1;
76}
77
78void Cannon::setCoords()
79{
80 switch(index) {
81 case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break;
82 case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break;
83 case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break;
84 case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break;
85 case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break;
86 case 5: cannonx = barrelxpos-19; cannony = barrelypos; break;
87 case 6: cannonx = barrelxpos-15; cannony = barrelypos; break;
88 case 7: cannonx = barrelxpos-10; cannony = barrelypos; break;
89 case 8: cannonx = barrelxpos; cannony = barrelypos; break;
90 case 9: cannonx = barrelxpos+2; cannony = barrelypos; break;
91 case 10: cannonx = barrelxpos+6; cannony = barrelypos; break;
92 case 11: cannonx = barrelxpos+8; cannony = barrelypos; break;
93 case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break;
94 case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break;
95 case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break;
96 case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break;
97 case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break;
98 }
99}
100
101double Cannon::shootAngle()
102{
103 switch(index) {
104 case 0: return 30.0;
105 case 1: return 37.5;
106 case 2: return 45.0;
107 case 3: return 52.5;
108 case 4: return 60.0;
109 case 5: return 67.5;
110 case 6: return 75.0;
111 case 7: return 82.5;
112 case 8: return 90.0;
113 case 9: return 97.5;
114 case 10: return 105.0;
115 case 11: return 112.5;
116 case 12: return 120.0;
117 case 13: return 127.5;
118 case 14: return 135.0;
119 case 15: return 142.5;
120 case 16: return 150.0;
121 }
122 return 0;
123}
124
125void Cannon::shoot()
126{
127 setCoords();
128 Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony);
129 connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int)));
130 shotsfired++;
131}
132
133Cannon::~Cannon()
134{
135}
136
137int Cannon::rtti() const
138{
139 return cannon_rtti;
140}