00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <opie2/oresource.h>
00022
00023 #include "codes.h"
00024 #include "cannon.h"
00025
00026 Cannon::Cannon(QCanvas* canvas) :
00027 QCanvasSprite(0, canvas)
00028 {
00029 shotsfired=0;
00030 index = 8;
00031 cannonx = 0;
00032 cannony = 0;
00033 cannonarray = new QCanvasPixmapArray();
00034 QString c0 = Opie::Core::OResource::findPixmap("parashoot/can0001");
00035 c0.replace(QRegExp("0001"),"%1");
00036 cannonarray->readPixmaps(c0,17);
00037 setSequence(cannonarray);
00038 setFrame(index);
00039
00040 reposition();
00041
00042 movedir = NoDir;
00043 moveDelay = 0;
00044 setAnimated(TRUE);
00045 show();
00046 }
00047
00048 void Cannon::advance(int stage)
00049 {
00050 if ( stage == 1 && moveDelay-- == 0 ) {
00051 if (movedir == Left) {
00052 if (index > 0) {
00053 setFrame(index-1);
00054 index--;
00055 }
00056 }
00057 if (movedir == Right) {
00058 if (index < 16) {
00059 setFrame(index+1);
00060 index++;
00061 }
00062 }
00063 moveDelay = 0;
00064 }
00065 }
00066
00067 void Cannon::pointCannon(Direction dir)
00068 {
00069 movedir = dir;
00070 moveDelay = 0;
00071 advance(1);
00072 moveDelay = 1;
00073 }
00074
00075 void Cannon::setCoords()
00076 {
00077 switch(index) {
00078 case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break;
00079 case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break;
00080 case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break;
00081 case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break;
00082 case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break;
00083 case 5: cannonx = barrelxpos-19; cannony = barrelypos; break;
00084 case 6: cannonx = barrelxpos-15; cannony = barrelypos; break;
00085 case 7: cannonx = barrelxpos-10; cannony = barrelypos; break;
00086 case 8: cannonx = barrelxpos; cannony = barrelypos; break;
00087 case 9: cannonx = barrelxpos+2; cannony = barrelypos; break;
00088 case 10: cannonx = barrelxpos+6; cannony = barrelypos; break;
00089 case 11: cannonx = barrelxpos+8; cannony = barrelypos; break;
00090 case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break;
00091 case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break;
00092 case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break;
00093 case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break;
00094 case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break;
00095 }
00096 }
00097
00098 double Cannon::shootAngle()
00099 {
00100 switch(index) {
00101 case 0: return 30.0;
00102 case 1: return 37.5;
00103 case 2: return 45.0;
00104 case 3: return 52.5;
00105 case 4: return 60.0;
00106 case 5: return 67.5;
00107 case 6: return 75.0;
00108 case 7: return 82.5;
00109 case 8: return 90.0;
00110 case 9: return 97.5;
00111 case 10: return 105.0;
00112 case 11: return 112.5;
00113 case 12: return 120.0;
00114 case 13: return 127.5;
00115 case 14: return 135.0;
00116 case 15: return 142.5;
00117 case 16: return 150.0;
00118 }
00119 return 0;
00120 }
00121
00122 void Cannon::shoot()
00123 {
00124 setCoords();
00125 Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony);
00126 connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int)));
00127 shotsfired++;
00128 }
00129
00130 Cannon::~Cannon()
00131 {
00132 }
00133
00134 int Cannon::rtti() const
00135 {
00136 return cannon_rtti;
00137 }
00138
00139 void Cannon::reposition(void)
00140 {
00141 move(canvas()->width()/2-20, canvas()->height()-32);
00142
00143 barrelypos = canvas()->height()-32;
00144 barrelxpos = canvas()->width()/2;
00145
00146 setFrame(index);
00147 setCoords();
00148 }