2 Copyright (C) 1998-2001 Andreas Zehender <az@azweb.de>
3 Copyright (C) 2006-2008 Dirk Rathlev <dirkrathlev@gmx.de>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <QGraphicsScene>
28 #include "mathroutines.h"
30 SunSprite::SunSprite(QSvgRenderer
* svg
, const QString
& element
)
31 :SimpleSprite(svg
, element
)
37 PowerupSprite::PowerupSprite(QSvgRenderer
* svg
, const QString
& element
, int t
,
39 :SimpleSprite(svg
, element
)
45 ShipSprite::ShipSprite(QSvgRenderer
* svg
, const QString
& element
, int pn
)
46 :MobileSprite(svg
, element
,pn
)
58 void ShipSprite::setRotation(double r
)
62 rotation
-=((int)(rotation
/(2*M_PI
))-1)*2*M_PI
;
64 rotation
-=(int)(rotation
/(2*M_PI
))*2*M_PI
;
66 translate(center().x(),center().y());
67 rotate(-(rotation
-angle
)*57.3);
68 translate(-center().x(),-center().y());
72 void ShipSprite::forward(double mult
)
74 MobileSprite::forward(mult
);
81 if(reloadBulletTime
>0)
82 reloadBulletTime
-=mult
;
87 void ShipSprite::forward(double mult
,int fr
)
89 MobileSprite::forward(mult
,fr
);
90 rotation
=fr
/ROTNUM
*M_PI
*2;
97 if(reloadBulletTime
>0)
98 reloadBulletTime
-=mult
;
100 reloadMineTime
-=mult
;
103 void ShipSprite::calculateGravityAndEnergy(double gravity
,double sunEnergy
,
106 double nx
,ny
,ex
,ey
,abs_2
,phi
,sq
,eg
;
110 ex
=x()+center().x()-scene()->width()/2.0;
111 ey
=y()+center().y()-scene()->height()/2.0;
116 if ( explodes() && (sq
<20) )
123 setVelocity(xVelocity()-eg
*nx
/abs_2
,
124 yVelocity()-eg
*ny
/abs_2
);
129 phi
=rectToAngle(nx
,ny
);
130 energy
+=fabs(sunEnergy
*mult
/(abs_2
)*cos(phi
+rotation
));
137 void ShipSprite::rotateRight(double rotationEnergyNeed
,double rotationSpeed
)
139 if(energy
>rotationEnergyNeed
)
141 energy
-=rotationEnergyNeed
;
142 setRotation(rotation
-rotationSpeed
);
146 void ShipSprite::rotateLeft(double rotationEnergyNeed
,double rotationSpeed
)
148 if(energy
>rotationEnergyNeed
)
150 energy
-=rotationEnergyNeed
;
151 setRotation(rotation
+rotationSpeed
);
155 BulletSprite::BulletSprite(QSvgRenderer
* svg
, const QString
& element
, int pn
,double lifetime
)
156 :MobileSprite(svg
,element
,pn
)
162 void BulletSprite::forward(double mult
)
164 MobileSprite::forward(mult
);
168 void BulletSprite::forward(double mult
,int fr
)
170 MobileSprite::forward(mult
,fr
);
174 MineSprite::MineSprite(QSvgRenderer
* svg
, const QList
<QString
>& animation
, const QList
<QString
>& exploanimation
, int pn
,double atime
,double f
)
175 :AnimatedSprite(svg
, animation
,pn
)
177 exploframes
= exploanimation
;
187 void MineSprite::explode()
189 setAnimation(exploframes
);
190 timeToGo
=frameCount();
197 void MineSprite::forward(double mult
)
204 if(explosiontime
>(timeToGo
-0.001))
205 explosiontime
=timeToGo
-0.01;
206 setFrame((int)explosiontime
);
211 activateTime
-=(double)mult
;
219 MobileSprite::forward(mult
);
222 void MineSprite::calculateGravity(double gravity
,double mult
)
224 double abs_2
,nx
,ny
,ex
,ey
,sq
,eg
;
228 ex
=x()-scene()->width()/2.0;
229 ey
=y()-scene()->height()/2.0;
237 setVelocity(xVelocity()-eg
*nx
/abs_2
,
238 yVelocity()-eg
*ny
/abs_2
);
244 ExplosionSprite::ExplosionSprite(QSvgRenderer
* svg
, const QList
<QString
>& animation
, MobileSprite
*sp
)
245 :AnimatedSprite(svg
, animation
)
250 timeToGo
= frameCount();
253 setPos(QPointF(sp
->x(),sp
->y()));
256 void ExplosionSprite::forward(double mult
)
259 setPos(QPointF(obj
->x(),obj
->y()));