summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-06 14:32:10 (UTC)
committer zecke <zecke>2004-02-06 14:32:10 (UTC)
commitb033733924e5d3454bb0a810c6a70d4ff0531d2b (patch) (unidiff)
treecafe130296468840db062af4a3335572804ee1f3
parentf60cbb888e72b3eaf49af6f72fa183e6d44ae389 (diff)
downloadopie-b033733924e5d3454bb0a810c6a70d4ff0531d2b.zip
opie-b033733924e5d3454bb0a810c6a70d4ff0531d2b.tar.gz
opie-b033733924e5d3454bb0a810c6a70d4ff0531d2b.tar.bz2
Funny how much bugs one can introduce when importing Qtopia stuff.
Fixed a couple of possible sigsegv, uninitialized variables
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/parashoot/base.cpp12
-rw-r--r--noncore/games/parashoot/base.h8
-rw-r--r--noncore/games/parashoot/cannon.cpp24
-rw-r--r--noncore/games/parashoot/cannon.h6
-rw-r--r--noncore/games/parashoot/helicopter.cpp28
-rw-r--r--noncore/games/parashoot/helicopter.h6
-rw-r--r--noncore/games/parashoot/interface.cpp74
-rw-r--r--noncore/games/parashoot/interface.h22
-rw-r--r--noncore/games/parashoot/man.cpp39
9 files changed, 148 insertions, 71 deletions
diff --git a/noncore/games/parashoot/base.cpp b/noncore/games/parashoot/base.cpp
index c03802f..cdf1dfa 100644
--- a/noncore/games/parashoot/base.cpp
+++ b/noncore/games/parashoot/base.cpp
@@ -1,71 +1,77 @@
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**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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#include "codes.h" 20#include "codes.h"
21#include "base.h" 21#include "base.h"
22#include "man.h" 22#include "man.h"
23 23
24#include <qpe/resource.h> 24#include <qtopia/resource.h>
25 25
26#include <qregexp.h> 26#include <qregexp.h>
27 27
28int damage; 28int damage;
29 29
30Base::Base(QCanvas* canvas) : 30Base::Base(QCanvas* canvas) :
31 QCanvasSprite(0, canvas), 31 QCanvasSprite(0, canvas),
32 kaboom("landmine"), 32 kaboom("landmine"),
33 ohdear("crmble01") 33 ohdear("crmble01")
34{ 34{
35 basearray = new QCanvasPixmapArray(); 35 basearray = new QCanvasPixmapArray();
36 QString b0 = Resource::findPixmap("parashoot/b0001"); 36 QString b0 = Resource::findPixmap("parashoot/b0001");
37 b0.replace(QRegExp("0001"),"%1"); 37 b0.replace(QRegExp("0001"),"%1");
38 basearray->readPixmaps(b0, 4); 38 basearray->readPixmaps(b0, 4);
39 setSequence(basearray); 39 setSequence(basearray);
40 setFrame(0); 40 setFrame(0);
41 move(2, canvas->height()-50); 41 move(2, canvas->height()-50);
42 setZ(10); 42 setZ(10);
43 show(); 43 show();
44 damage = 0; 44 damage = 0;
45} 45}
46 46
47void Base::damageBase() 47void Base::damageBase()
48{ 48{
49 damage++; 49 damage++;
50 50
51 switch(damage) { 51 switch(damage) {
52 case 1: setFrame(1); ohdear.play(); break; 52 case 1: setFrame(1); ohdear.play(); break;
53 case 2: setFrame(2); ohdear.play(); break; 53 case 2: setFrame(2); ohdear.play(); break;
54 case 3: setFrame(3); kaboom.play(); break; 54 case 3: setFrame(3); kaboom.play(); break;
55 } 55 }
56 show(); 56 show();
57} 57}
58 58
59bool Base::baseDestroyed() 59bool Base::baseDestroyed()
60{ 60{
61 return (damage >= 3); 61 return (damage >= 3);
62} 62}
63 63
64Base::~Base() 64Base::~Base()
65{ 65{
66} 66}
67 67
68int Base::rtti() const 68int Base::rtti() const
69{ 69{
70 return base_rtti; 70 return base_rtti;
71} 71}
72
73void
74Base::reposition(void)
75{
76 move(2, canvas()->height()-50);
77}
diff --git a/noncore/games/parashoot/base.h b/noncore/games/parashoot/base.h
index ee7f166..a4c69cc 100644
--- a/noncore/games/parashoot/base.h
+++ b/noncore/games/parashoot/base.h
@@ -1,38 +1,40 @@
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**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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 <qpe/sound.h> 21#include <qtopia/sound.h>
22 22
23#include <qcanvas.h> 23#include <qcanvas.h>
24 24
25class Base : public QCanvasSprite 25class Base : public QCanvasSprite
26{ 26{
27 27
28public: 28public:
29 Base(QCanvas*); 29 Base(QCanvas*);
30 ~Base(); 30 ~Base();
31 void damageBase(); 31 void damageBase();
32 int rtti() const; 32 int rtti() const;
33 static bool baseDestroyed(); 33 static bool baseDestroyed();
34 34
35 void reposition(void);
36
35private: 37private:
36 QCanvasPixmapArray* basearray; 38 QCanvasPixmapArray* basearray;
37 Sound kaboom, ohdear; 39 Sound kaboom, ohdear;
38}; 40};
diff --git a/noncore/games/parashoot/cannon.cpp b/noncore/games/parashoot/cannon.cpp
index 3c0a5fe..5671351 100644
--- a/noncore/games/parashoot/cannon.cpp
+++ b/noncore/games/parashoot/cannon.cpp
@@ -1,140 +1,150 @@
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**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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 <qpe/resource.h> 21#include <qtopia/resource.h>
22 22
23#include <qregexp.h> 23#include <qregexp.h>
24 24
25#include "codes.h" 25#include "codes.h"
26#include "cannon.h" 26#include "cannon.h"
27 27
28Cannon::Cannon(QCanvas* canvas) : 28Cannon::Cannon(QCanvas* canvas) :
29 QCanvasSprite(0, canvas) 29 QCanvasSprite(0, canvas)
30{ 30{
31shotsfired=0; 31shotsfired=0;
32 index = 8; 32 index = 8;
33 cannonx = 0; 33 cannonx = 0;
34 cannony = 0; 34 cannony = 0;
35 cannonarray = new QCanvasPixmapArray(); 35 cannonarray = new QCanvasPixmapArray();
36 QString c0 = Resource::findPixmap("parashoot/can0001"); 36 QString c0 = Resource::findPixmap("parashoot/can0001");
37 c0.replace(QRegExp("0001"),"%1"); 37 c0.replace(QRegExp("0001"),"%1");
38 cannonarray->readPixmaps(c0,17); 38 cannonarray->readPixmaps(c0,17);
39 setSequence(cannonarray); 39 setSequence(cannonarray);
40 setFrame(index); 40 setFrame(index);
41 move(canvas->width()/2-20, canvas->height()-32); 41
42 // co ords for barrel of cannon when upright 42 reposition();
43 barrelypos = canvas->height()-32; 43
44 barrelxpos = canvas->width()/2;
45 movedir = NoDir; 44 movedir = NoDir;
46 moveDelay = 0; 45 moveDelay = 0;
47 setAnimated(TRUE); 46 setAnimated(TRUE);
48 show(); 47 show();
49} 48}
50 49
51void Cannon::advance(int stage) 50void Cannon::advance(int stage)
52{ 51{
53 if ( stage == 1 && moveDelay-- == 0 ) { 52 if ( stage == 1 && moveDelay-- == 0 ) {
54 if (movedir == Left) { 53 if (movedir == Left) {
55 if (index > 0) { 54 if (index > 0) {
56 setFrame(index-1); 55 setFrame(index-1);
57 index--; 56 index--;
58 } 57 }
59 } 58 }
60 if (movedir == Right) { 59 if (movedir == Right) {
61 if (index < 16) { 60 if (index < 16) {
62 setFrame(index+1); 61 setFrame(index+1);
63 index++; 62 index++;
64 } 63 }
65 } 64 }
66 moveDelay = 0; 65 moveDelay = 0;
67 } 66 }
68} 67}
69 68
70void Cannon::pointCannon(Direction dir) 69void Cannon::pointCannon(Direction dir)
71{ 70{
72 movedir = dir; 71 movedir = dir;
73 moveDelay = 0; 72 moveDelay = 0;
74 advance(1); 73 advance(1);
75 moveDelay = 1; 74 moveDelay = 1;
76} 75}
77 76
78void Cannon::setCoords() 77void Cannon::setCoords()
79{ 78{
80 switch(index) { 79 switch(index) {
81 case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break; 80 case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break;
82 case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break; 81 case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break;
83 case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break; 82 case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break;
84 case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break; 83 case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break;
85 case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break; 84 case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break;
86 case 5: cannonx = barrelxpos-19; cannony = barrelypos; break; 85 case 5: cannonx = barrelxpos-19; cannony = barrelypos; break;
87 case 6: cannonx = barrelxpos-15; cannony = barrelypos; break; 86 case 6: cannonx = barrelxpos-15; cannony = barrelypos; break;
88 case 7: cannonx = barrelxpos-10; cannony = barrelypos; break; 87 case 7: cannonx = barrelxpos-10; cannony = barrelypos; break;
89 case 8: cannonx = barrelxpos; cannony = barrelypos; break; 88 case 8: cannonx = barrelxpos; cannony = barrelypos; break;
90 case 9: cannonx = barrelxpos+2; cannony = barrelypos; break; 89 case 9: cannonx = barrelxpos+2; cannony = barrelypos; break;
91 case 10: cannonx = barrelxpos+6; cannony = barrelypos; break; 90 case 10: cannonx = barrelxpos+6; cannony = barrelypos; break;
92 case 11: cannonx = barrelxpos+8; cannony = barrelypos; break; 91 case 11: cannonx = barrelxpos+8; cannony = barrelypos; break;
93 case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break; 92 case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break;
94 case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break; 93 case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break;
95 case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break; 94 case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break;
96 case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break; 95 case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break;
97 case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break; 96 case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break;
98 } 97 }
99} 98}
100 99
101double Cannon::shootAngle() 100double Cannon::shootAngle()
102{ 101{
103 switch(index) { 102 switch(index) {
104 case 0: return 30.0; 103 case 0: return 30.0;
105 case 1: return 37.5; 104 case 1: return 37.5;
106 case 2: return 45.0; 105 case 2: return 45.0;
107 case 3: return 52.5; 106 case 3: return 52.5;
108 case 4: return 60.0; 107 case 4: return 60.0;
109 case 5: return 67.5; 108 case 5: return 67.5;
110 case 6: return 75.0; 109 case 6: return 75.0;
111 case 7: return 82.5; 110 case 7: return 82.5;
112 case 8: return 90.0; 111 case 8: return 90.0;
113 case 9: return 97.5; 112 case 9: return 97.5;
114 case 10: return 105.0; 113 case 10: return 105.0;
115 case 11: return 112.5; 114 case 11: return 112.5;
116 case 12: return 120.0; 115 case 12: return 120.0;
117 case 13: return 127.5; 116 case 13: return 127.5;
118 case 14: return 135.0; 117 case 14: return 135.0;
119 case 15: return 142.5; 118 case 15: return 142.5;
120 case 16: return 150.0; 119 case 16: return 150.0;
121 } 120 }
122 return 0; 121 return 0;
123} 122}
124 123
125void Cannon::shoot() 124void Cannon::shoot()
126{ 125{
127 setCoords(); 126 setCoords();
128 Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony); 127 Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony);
129 connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int))); 128 connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int)));
130 shotsfired++; 129 shotsfired++;
131} 130}
132 131
133Cannon::~Cannon() 132Cannon::~Cannon()
134{ 133{
135} 134}
136 135
137int Cannon::rtti() const 136int Cannon::rtti() const
138{ 137{
139 return cannon_rtti; 138 return cannon_rtti;
140} 139}
140
141void Cannon::reposition(void)
142{
143 move(canvas()->width()/2-20, canvas()->height()-32);
144 // co ords for barrel of cannon when upright
145 barrelypos = canvas()->height()-32;
146 barrelxpos = canvas()->width()/2;
147
148 setFrame(index);
149 setCoords();
150}
diff --git a/noncore/games/parashoot/cannon.h b/noncore/games/parashoot/cannon.h
index 44d0c65..51b1247 100644
--- a/noncore/games/parashoot/cannon.h
+++ b/noncore/games/parashoot/cannon.h
@@ -1,58 +1,60 @@
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**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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#include <qcanvas.h> 20#include <qcanvas.h>
21 21
22#include "bullet.h" 22#include "bullet.h"
23 23
24class Cannon : public QObject, public QCanvasSprite 24class Cannon : public QObject, public QCanvasSprite
25{ 25{
26 Q_OBJECT 26 Q_OBJECT
27 27
28public: 28public:
29 Cannon(QCanvas*); //create cannon 29 Cannon(QCanvas*); //create cannon
30 ~Cannon(); //destroy cannon 30 ~Cannon(); //destroy cannon
31 31
32 enum Direction{ Left, Right, NoDir }; 32 enum Direction{ Left, Right, NoDir };
33 33
34 void pointCannon(Direction dir); 34 void pointCannon(Direction dir);
35 void setCoords(); 35 void setCoords();
36 double shootAngle(); 36 double shootAngle();
37 void shoot(); 37 void shoot();
38 int rtti() const; 38 int rtti() const;
39 39
40int shotsFired() { return shotsfired; }; 40int shotsFired() { return shotsfired; };
41 41
42 void reposition(void);
43
42protected: 44protected:
43 void advance(int stage); 45 void advance(int stage);
44 46
45signals: 47signals:
46 void score(int); 48 void score(int);
47 49
48private: 50private:
49 QCanvasPixmapArray* cannonarray; 51 QCanvasPixmapArray* cannonarray;
50 int index; 52 int index;
51 int cannonx; 53 int cannonx;
52 int cannony; 54 int cannony;
53 int barrelxpos; 55 int barrelxpos;
54 int barrelypos; 56 int barrelypos;
55 int moveDelay; 57 int moveDelay;
56 Direction movedir; 58 Direction movedir;
57 int shotsfired; 59 int shotsfired;
58}; 60};
diff --git a/noncore/games/parashoot/helicopter.cpp b/noncore/games/parashoot/helicopter.cpp
index 0923124..036b21e 100644
--- a/noncore/games/parashoot/helicopter.cpp
+++ b/noncore/games/parashoot/helicopter.cpp
@@ -1,114 +1,120 @@
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**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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 "helicopter.h" 21#include "helicopter.h"
22#include "man.h" 22#include "man.h"
23#include "codes.h" 23#include "codes.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
29static QList<Helicopter> all; 29static QList<Helicopter> all;
30 30
31Helicopter::Helicopter(QCanvas* canvas) : 31Helicopter::Helicopter(QCanvas* canvas) :
32 QCanvasSprite(0, canvas), 32 QCanvasSprite(0, canvas),
33 chikachika("aland01") 33 chikachika("aland01")
34{ 34{
35 all.append(this); 35 all.append(this);
36 hits = 0; 36 hits = 0;
37 QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray(); 37 QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray();
38 QString h0 = Resource::findPixmap("parashoot/helicopter0001"); 38 QString h0 = Resource::findPixmap("parashoot/helicopter0001");
39 h0.replace(QRegExp("0001"),"%1"); 39 h0.replace(QRegExp("0001"),"%1");
40 helicopterarray->readPixmaps(h0,3 ); 40 helicopterarray->readPixmaps(h0,4 );
41
41 setSequence(helicopterarray); 42 setSequence(helicopterarray);
42 setAnimated(true); 43 setAnimated(true);
43 move(canvas->width(), 5); 44 move(canvas->width(), 5);
44 setVelocity(-2, 0); 45 setVelocity(-2, 0);
45 chikachika.playLoop(); 46 chikachika.playLoop();
46 show(); 47 show();
47} 48}
48 49
49Helicopter::~Helicopter() 50Helicopter::~Helicopter()
50{ 51{
51 all.remove(this); 52 all.remove(this);
52} 53}
53 54
54int fr = 0; 55int fr = 0;
55 56
56void Helicopter::advance(int phase) 57void Helicopter::advance(int phase)
57{ 58{
58 QCanvasSprite::advance(phase); 59 QCanvasSprite::advance(phase);
59 if (phase == 0) { 60 if (phase == 0) {
60 setFrame(fr%3); 61 if (frame() == 3) {
61 fr++; 62 delete this;
62 checkCollision(); 63 return;
64 }
65
66 if (hits >= 2) {
67 setFrame(3);
68 } else {
69 setFrame(fr%3);
70 fr++;
71 checkCollision();
72 }
63 } 73 }
64} 74}
65 75
66void Helicopter::checkCollision() 76void Helicopter::checkCollision()
67{ 77{
68 if (x() == 6) { 78 if (x() == 6) {
69 setAnimated(false); //setVelocity(0, 0); 79 setAnimated(false); //setVelocity(0, 0);
70 dropman(); 80 dropman();
71 } 81 }
72 if (x() < 0) 82 if (x() < 0)
73 done(); 83 done();
74} 84}
75 85
76void Helicopter::dropman() 86void Helicopter::dropman()
77{ 87{
78 (void)new Man(canvas(), 15, 25); 88 (void)new Man(canvas(), 15, 25);
79 (void)new Man(canvas(), 35, 25); 89 (void)new Man(canvas(), 35, 25);
80 takeOff(); 90 takeOff();
81} 91}
82 92
83void Helicopter::done() 93void Helicopter::done()
84{ 94{
85 hits++; 95 hits++;
86 if (hits >= 2) {
87 setAnimated(false);
88 delete this;
89 }
90} 96}
91 97
92void Helicopter::takeOff() 98void Helicopter::takeOff()
93{ 99{
94 setVelocity(-1, 0); 100 setVelocity(-1, 0);
95} 101}
96 102
97int Helicopter::rtti() const 103int Helicopter::rtti() const
98{ 104{
99 return helicopter_rtti; 105 return helicopter_rtti;
100} 106}
101 107
102void Helicopter::silenceAll() 108void Helicopter::silenceAll()
103{ 109{
104 for (Helicopter* h = all.first(); h; h = all.next()) 110 for (Helicopter* h = all.first(); h; h = all.next())
105 h->chikachika.stop(); 111 h->chikachika.stop();
106} 112}
107 113
108void Helicopter::deleteAll() 114void Helicopter::deleteAll()
109{ 115{
110 Helicopter* h; 116 Helicopter* h;
111 while ((h = all.first())) 117 while ((h = all.first()))
112 delete h; 118 delete h;
113} 119}
114 120
diff --git a/noncore/games/parashoot/helicopter.h b/noncore/games/parashoot/helicopter.h
index 5cb92de..954c651 100644
--- a/noncore/games/parashoot/helicopter.h
+++ b/noncore/games/parashoot/helicopter.h
@@ -1,45 +1,45 @@
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**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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 <qpe/sound.h> 21#include <qtopia/sound.h>
22 22
23#include <qcanvas.h> 23#include <qcanvas.h>
24 24
25class Helicopter : public QCanvasSprite 25class Helicopter : public QCanvasSprite
26{ 26{
27 27
28public: 28public:
29 Helicopter(QCanvas*); 29 Helicopter(QCanvas*);
30 ~Helicopter(); 30 ~Helicopter();
31 void advance(int phase); 31 void advance(int phase);
32 void checkCollision(); 32 void checkCollision();
33 void dropman(); 33 void dropman();
34 void takeOff(); 34 void takeOff();
35 void done(); 35 void done();
36 36
37 static void silenceAll(); 37 static void silenceAll();
38 static void deleteAll(); 38 static void deleteAll();
39 39
40 int rtti() const; 40 int rtti() const;
41 41
42private: 42private:
43 int hits; 43 int hits;
44 Sound chikachika; 44 Sound chikachika;
45}; 45};
diff --git a/noncore/games/parashoot/interface.cpp b/noncore/games/parashoot/interface.cpp
index a40426d..948b92c 100644
--- a/noncore/games/parashoot/interface.cpp
+++ b/noncore/games/parashoot/interface.cpp
@@ -1,250 +1,282 @@
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**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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 "interface.h" 21#include "interface.h"
22#include "man.h" 22#include "man.h"
23 23
24#include <qpe/resource.h> 24#include <qtopia/qpeapplication.h>
25#include <qpe/qpeapplication.h> 25#include <qtopia/resource.h>
26 26
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qapplication.h> 29#include <qapplication.h>
30#include <qstyle.h> 30#include <qstyle.h>
31#include <qpe/qpetoolbar.h> 31#include <qtoolbar.h>
32#include <qtoolbutton.h> 32#include <qtoolbutton.h>
33 33
34ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : 34ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
35 QMainWindow(parent,name,f), 35 QMainWindow(parent,name,f),
36 canvas(232, 258), 36 canvas( 232, 258 ),
37 cannon(NULL),
38 base(NULL),
39 gamestopped( true ),
40 waitover( false ),
37 fanfare("level_up"), 41 fanfare("level_up"),
38 score(0) 42 score(0)
39{ 43{
40 QPEApplication::grabKeyboard(); 44 QPEApplication::grabKeyboard();
41 QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); 45 QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff );
46
47 updatespeed = 80;
42 canvas.setAdvancePeriod(80); 48 canvas.setAdvancePeriod(80);
43 QPixmap bg = Resource::loadPixmap("parashoot/sky");
44 canvas.setBackgroundPixmap(bg);
45 49
46 pb = new QCanvasView(&canvas, this); 50 pb = new QCanvasView(&canvas, this);
47 pb->setFocus(); 51 pb->setFocus();
48 52
49 setToolBarsMovable( FALSE ); 53 setToolBarsMovable( FALSE );
50 54
51 QToolBar* toolbar = new QToolBar(this); 55 QToolBar* toolbar = new QToolBar(this);
52 toolbar->setHorizontalStretchable( TRUE ); 56 toolbar->setHorizontalStretchable( TRUE );
53 57
54 setCaption( tr("ParaShoot") ); 58 setCaption( tr("ParaShoot") );
55 QPixmap newicon = Resource::loadPixmap("parashoot/manicon"); 59 new QToolButton( Resource::loadIconSet("new"), tr("New Game"), 0,
56 setIcon(newicon);
57 new QToolButton(newicon, tr("New Game"), 0,
58 this, SLOT(newGame()), toolbar, "New Game"); 60 this, SLOT(newGame()), toolbar, "New Game");
59 61
60 levelscore = new QLabel(toolbar); 62 levelscore = new QLabel(toolbar);
61 levelscore->setBackgroundMode( PaletteButton ); 63 levelscore->setBackgroundMode( PaletteButton );
62 levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); 64 levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs );
63 toolbar->setStretchableWidget( levelscore ); 65 toolbar->setStretchableWidget( levelscore );
64 showScore(0,0); 66 showScore(0,0);
65 67
66 setCentralWidget(pb); 68 setCentralWidget(pb);
67 69
68 autoDropTimer = new QTimer(this); 70 autoDropTimer = new QTimer(this);
69 connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); 71 connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) );
70 72
71 pauseTimer = new QTimer(this); 73 pauseTimer = new QTimer(this);
72 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); 74 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) );
73 75
74 setFocusPolicy(StrongFocus); 76 setFocusPolicy(StrongFocus);
75
76 newGame();
77} 77}
78 78
79 79
80void ParaShoot::resizeEvent(QResizeEvent *) 80void ParaShoot::resizeEvent(QResizeEvent *)
81{ 81{
82 QSize s = centralWidget()->size(); 82 QSize s = centralWidget()->size();
83 int fw = style().defaultFrameWidth(); 83 int fw = style().defaultFrameWidth();
84 canvas.resize( s.width() - fw - 2, s.height() - fw - 2); 84 canvas.resize( s.width() - fw - 2, s.height() - fw - 2);
85
86 QImage bgimage = Resource::loadImage("parashoot/sky");
87 QPixmap bgpixmap;
88
89 bgpixmap.convertFromImage(bgimage.smoothScale(canvas.width(),
90 canvas.height()), QPixmap::Auto);
91 canvas.setBackgroundPixmap(bgpixmap);
92
93 if (base) {
94 base->reposition();
95 }
96
97 if (cannon) {
98 cannon->reposition();
99 }
85} 100}
86 101
102void ParaShoot::focusOutEvent (QFocusEvent *)
103{
104 if (!gamestopped)
105 canvas.setAdvancePeriod(-1);
106}
107
108void ParaShoot::focusInEvent (QFocusEvent *)
109{
110 if (!gamestopped)
111 canvas.setAdvancePeriod(updatespeed);
112}
87 113
88void ParaShoot::showScore( int score, int level ) 114void ParaShoot::showScore( int score, int level )
89{ 115{
90 levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); 116 levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) );
91} 117}
92 118
93 119
94void ParaShoot::newGame() 120void ParaShoot::newGame()
95{ 121{
96 clear(); 122 clear();
97 if (pauseTimer->isActive()) 123 if (pauseTimer->isActive())
98 pauseTimer->stop(); 124 pauseTimer->stop();
99 clear(); 125 clear();
100 Man::setManCount(0); 126 Man::setManCount(0);
101 score = 0; 127 score = 0;
102 Bullet::setShotCount(0); 128 Bullet::setShotCount(0);
103 Bullet::setNobullets(0); 129 Bullet::setNobullets(0);
104 nomen = 2; 130 nomen = 2;
105 Bullet::setLimit(nomen); 131 Bullet::setLimit(nomen);
106 level = 0; 132 level = 0;
107 updatespeed = 80; 133 updatespeed = 80;
108 showScore(0,0); 134 showScore(0,0);
109 gamestopped = false; 135 gamestopped = false;
110 Helicopter::deleteAll(); 136 Helicopter::deleteAll();
111 waitover = true; 137 waitover = true;
112 base = new Base(&canvas); 138 base = new Base(&canvas);
113 cannon = new Cannon(&canvas); 139 cannon = new Cannon(&canvas);
114 connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); 140 connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int)));
115 autoDropTimer->start(100); 141 autoDropTimer->start(100);
116} 142}
117 143
118 144
119void ParaShoot::clear() 145void ParaShoot::clear()
120{ 146{
121 autoDropTimer->stop(); 147 autoDropTimer->stop();
122// QCanvasItem* item; 148// QCanvasItem* item;
123 QCanvasItemList l = canvas.allItems(); 149 QCanvasItemList l = canvas.allItems();
124 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { 150 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
125 delete *it; 151 delete *it;
126 } 152 }
127} 153}
128 154
129void ParaShoot::gameOver() 155void ParaShoot::gameOver()
130{ 156{
131 QCanvasItem* item; 157 QCanvasItem* item;
132 QCanvasItemList l = canvas.allItems(); 158 QCanvasItemList l = canvas.allItems();
133 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { 159 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
134 item = *it; 160 item = *it;
135 if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) 161 if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900)
136 item->setAnimated(false); 162 item->setAnimated(false);
137 } 163 }
138 autoDropTimer->stop(); 164 autoDropTimer->stop();
139 Helicopter::silenceAll(); 165 Helicopter::silenceAll();
140 166
141 int shots = Bullet::getShotCount(); 167 int shots = Bullet::getShotCount();
142 168
143 int shotsFired = cannon->shotsFired(); 169 int shotsFired = cannon->shotsFired();
144 if ( shotsFired == 0 ) 170 if ( shotsFired == 0 )
145 shotsFired = 1; 171 shotsFired = 1;
146 QCanvasText* gameover = new QCanvasText( 172 QCanvasText* gameover = new QCanvasText(
147 tr( " GAME OVER!\n" 173 tr( " GAME OVER!\n"
148 " Your Score: %1\n" 174 " Your Score: %1\n"
149 " Parachuters Killed: %2\n" 175 " Parachuters Killed: %2\n"
150 " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), 176 " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ),
151 &canvas); 177 &canvas);
152 gameover->setColor(red); 178 gameover->setColor(red);
153 gameover->setFont( QFont("times", 18, QFont::Bold) ); 179 gameover->setFont( QFont("times", 16, QFont::Bold) );
154 gameover->move(canvas.width()/2 -110, canvas.height()/2 -50); 180 gameover->move((canvas.width() - gameover->boundingRect().width()) / 2,
181 (canvas.height() - gameover->boundingRect().height()) / 2);
155 gameover->setZ(500); 182 gameover->setZ(500);
156 gameover->show(); 183 gameover->show();
157 gamestopped = true; 184 gamestopped = true;
158 waitover = false; 185 waitover = false;
159 pauseTimer->start(3000); 186 pauseTimer->start(3000);
160} 187}
161 188
162void ParaShoot::wait() 189void ParaShoot::wait()
163{ 190{
164 waitover = true; 191 waitover = true;
165 pauseTimer->stop(); 192 pauseTimer->stop();
166} 193}
167 194
168void ParaShoot::play() 195void ParaShoot::play()
169{ 196{
170 if (Man::getManCount() < nomen ) { 197 if (Man::getManCount() < nomen ) {
171 new Man(&canvas); 198 new Man(&canvas);
172 } 199 }
173 if (Base::baseDestroyed()) { 200 if (Base::baseDestroyed()) {
174 gameOver(); 201 gameOver();
175 return; 202 return;
176 } 203 }
177} 204}
178 205
179void ParaShoot::increaseScore(int x) 206void ParaShoot::increaseScore(int x)
180{ 207{
181 score += x; 208 score += x;
182 if ( score / 150 != (score-x) / 150 ) 209 if ( score / 150 != (score-x) / 150 )
183 levelUp(); 210 levelUp();
184 showScore(level,score); 211 showScore(level,score);
185} 212}
186 213
187void ParaShoot::levelUp() 214void ParaShoot::levelUp()
188{ 215{
189 level++; 216 level++;
190 int stage = level % 3; 217 int stage = level % 3;
191 switch(stage) { 218 switch(stage) {
192 case 0: 219 case 0:
193 nomen++; 220 nomen++;
194 Bullet::setLimit(nomen); 221 Bullet::setLimit(nomen);
195 fanfare.play(); 222 fanfare.play();
196 break; 223 break;
197 case 1: 224 case 1:
198 new Helicopter(&canvas); 225 new Helicopter(&canvas);
199 break; 226 break;
200 case 2: 227 case 2:
201 moveFaster(); 228 moveFaster();
202 fanfare.play(); 229 fanfare.play();
203 break; 230 break;
204 default: return; 231 default: return;
205 } 232 }
206} 233}
207 234
208void ParaShoot::moveFaster() 235void ParaShoot::moveFaster()
209{ 236{
210 if (updatespeed > 50) 237 if (updatespeed > 50)
211 updatespeed = updatespeed-5; 238 updatespeed = updatespeed-5;
212 else 239 else
213 updatespeed = updatespeed-3; 240 updatespeed = updatespeed-3;
214 canvas.setAdvancePeriod(updatespeed); 241 canvas.setAdvancePeriod(updatespeed);
215} 242}
216 243
217void ParaShoot::keyPressEvent(QKeyEvent* event) 244void ParaShoot::keyPressEvent(QKeyEvent* event)
218{ 245{
219 if (gamestopped) { 246 if (gamestopped) {
220 if (waitover) 247 if (waitover)
221 newGame(); 248 newGame();
222 else 249 else
223 return; 250 return;
224 } else { 251 } else {
225 switch(event->key()) { 252 switch(event->key()) {
226 case Key_Up: 253 case Key_Up:
227 case Key_F1: 254 case Key_F1:
228 case Key_F9: 255 case Key_F9:
229 case Key_Space: 256 case Key_Space:
230 cannon->shoot(); 257 if ( cannon )
258 cannon->shoot();
231 break; 259 break;
232 case Key_Left: 260 case Key_Left:{
233 cannon->pointCannon(Cannon::Left); 261 if (cannon )
262 cannon->pointCannon(Cannon::Left);
234 lastcannonkey=Key_Left; 263 lastcannonkey=Key_Left;
235 break; 264 break;
236 case Key_Right: 265 }
237 cannon->pointCannon(Cannon::Right); 266 case Key_Right:{
267 if ( cannon )
268 cannon->pointCannon(Cannon::Right);
238 lastcannonkey=Key_Right; 269 lastcannonkey=Key_Right;
239 break; 270 break;
271 }
240 default: 272 default:
241 return; 273 return;
242 } 274 }
243 } 275 }
244} 276}
245 277
246void ParaShoot::keyReleaseEvent(QKeyEvent* event) 278void ParaShoot::keyReleaseEvent(QKeyEvent* event)
247{ 279{
248 if ( lastcannonkey == event->key() ) 280 if ( cannon && lastcannonkey == event->key() )
249 cannon->pointCannon(Cannon::NoDir); 281 cannon->pointCannon(Cannon::NoDir);
250} 282}
diff --git a/noncore/games/parashoot/interface.h b/noncore/games/parashoot/interface.h
index 5abbe0b..dd73f53 100644
--- a/noncore/games/parashoot/interface.h
+++ b/noncore/games/parashoot/interface.h
@@ -1,80 +1,82 @@
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**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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 "cannon.h" 21#include "cannon.h"
22#include "base.h" 22#include "base.h"
23#include "helicopter.h" 23#include "helicopter.h"
24 24
25#include <qpe/sound.h> 25#include <qtopia/sound.h>
26 26
27#include <qmainwindow.h> 27#include <qmainwindow.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qlabel.h> 29#include <qlabel.h>
30 30
31class QCanvas; 31class QCanvas;
32class Helicopter; 32class Helicopter;
33 33
34//enum Direction{ 34//enum Direction{
35// left, right, up, down }; 35// left, right, up, down };
36 36
37class ParaShoot : public QMainWindow { 37class ParaShoot : public QMainWindow {
38 Q_OBJECT 38 Q_OBJECT
39 39
40public: 40public:
41 static QString appName() { return QString::fromLatin1("parashoot"); }
42 ParaShoot(QWidget* parent=0, const char* name=0, WFlags f=0); 41 ParaShoot(QWidget* parent=0, const char* name=0, WFlags f=0);
43 42 static QString appName() {
43 return QString::fromLatin1("parashoot");
44 }
44 void clear(); 45 void clear();
45 void gameOver(); 46 void gameOver();
46 int mancount; 47 int mancount;
47 void levelUp(); 48 void levelUp();
48 void moveFaster(); 49 void moveFaster();
49 50
50protected: 51protected:
51 virtual void keyPressEvent(QKeyEvent*); 52 virtual void keyPressEvent(QKeyEvent*);
52 virtual void keyReleaseEvent(QKeyEvent*); 53 virtual void keyReleaseEvent(QKeyEvent*);
53 virtual void resizeEvent(QResizeEvent *e); 54 virtual void resizeEvent(QResizeEvent *e);
54 55 virtual void focusOutEvent(QFocusEvent *);
56 virtual void focusInEvent(QFocusEvent *);
57
55private slots: 58private slots:
56 void increaseScore(int); 59 void increaseScore(int);
57 void newGame(); 60 void newGame();
58 void play(); 61 void play();
59 void wait(); 62 void wait();
60 63
61private: 64private:
62 void showScore( int score, int level ); 65 void showScore( int score, int level );
63 QCanvasView* pb; 66 QCanvasView* pb;
64 QCanvas canvas; 67 QCanvas canvas;
65 Cannon* cannon; 68 Cannon* cannon;
66 Base* base; 69 Base* base;
67 QCanvasText* gameover;
68 QLabel* levelscore; 70 QLabel* levelscore;
69 int nomen; 71 int nomen;
70 int level; 72 int level;
71 int oldscore; 73 int oldscore;
72 int updatespeed; 74 int updatespeed;
73 QTimer* autoDropTimer; 75 QTimer* autoDropTimer;
74 QTimer* pauseTimer; 76 QTimer* pauseTimer;
75 bool gamestopped; 77 bool gamestopped;
76 bool waitover; 78 bool waitover;
77 Sound fanfare; 79 Sound fanfare;
78 int score; 80 int score;
79 int lastcannonkey; 81 int lastcannonkey;
80}; 82};
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,174 +1,191 @@
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**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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);
55 move(x, y); 55 move(x, y);
56 setFrame(5); 56 setFrame(5);
57 setZ(300); 57 setZ(300);
58 show(); 58 show();
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;
72} 72}
73int f = 0; 73int f = 0;
74 74
75void Man::advance(int phase) 75void Man::advance(int phase)
76{ 76{
77 QCanvasSprite::advance(phase); 77 QCanvasSprite::advance(phase);
78 if (phase == 0) { 78 if (phase == 0) {
79 checkCollision(); 79 checkCollision();
80 if (dead) { 80 if (dead) {
81 if (count < 10) { 81 if (count < 10) {
82 setFrame(6); 82 setFrame(6);
83 setVelocity(0,0); 83 setVelocity(0,0);
84 count++; 84 count++;
85 } else { 85 } else {
86 delete this; 86 delete this;
87 return; 87 return;
88 } 88 }
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;
104 QTime midnight(0, 0, 0); 111 QTime midnight(0, 0, 0);
105 srand(midnight.secsTo(QTime::currentTime()) ); 112 srand(midnight.secsTo(QTime::currentTime()) );
106 } 113 }
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);
132 setFrame(5); 149 setFrame(5);
133 setZ(300); 150 setZ(300);
134 show(); 151 show();
135 152
136 static bool first_time = TRUE; 153 static bool first_time = TRUE;
137 if (first_time) { 154 if (first_time) {
138 first_time = FALSE; 155 first_time = FALSE;
139 QTime midnight(0, 0, 0); 156 QTime midnight(0, 0, 0);
140 srand(midnight.secsTo(QTime::currentTime()) ); 157 srand(midnight.secsTo(QTime::currentTime()) );
141 } 158 }
142 int yfallspeed = 0; 159 int yfallspeed = 0;
143 yfallspeed = (rand() % 3) + 1; 160 yfallspeed = (rand() % 3) + 1;
144 setVelocity(0, yfallspeed); 161 setVelocity(0, yfallspeed);
145} 162}
146 163
147void Man::done() 164void Man::done()
148{ 165{
149 splat.play(); 166 splat.play();
150 count = 0; 167 count = 0;
151 dead = true; 168 dead = true;
152 setFrame(6); 169 setFrame(6);
153} 170}
154 171
155int Man::getManCount() 172int Man::getManCount()
156{ 173{
157 return mancount; 174 return mancount;
158} 175}
159 176
160void Man::setManCount(int count) 177void Man::setManCount(int count)
161{ 178{
162 mancount = count; 179 mancount = count;
163} 180}
164 181
165 182
166int Man::rtti() const 183int Man::rtti() const
167{ 184{
168 return man_rtti; 185 return man_rtti;
169} 186}
170 187
171Man::~Man() 188Man::~Man()
172{ 189{
173 mancount--; 190 mancount--;
174} 191}