mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SpaceShip.cpp
Go to the documentation of this file.
1 
6 #include "SpaceShip.h"
7 #include "Plane.h"
8 
10 
17 SpaceShip::SpaceShip( float r, GLuint displayList ) : MovingObject( ), ModelObject( r, displayList ) {
18  initialize();
19 }
20 
22 
29 SpaceShip::SpaceShip( Vector3 position, float r, GLuint displayList ) : MovingObject( position ), ModelObject( r, displayList ) {
30  initialize();
31 }
32 
34 
43 SpaceShip::SpaceShip( float x, float y, float z, float r, GLuint displayList ) : MovingObject( x, y, z ), ModelObject( r, displayList ) {
44  initialize();
45 }
46 
51 
52 }
53 
57 void SpaceShip::initialize( void ) {
58  m_laserHeat = 0;
59  m_maxLaserHeat = 100;
60  m_overHeated = false;
61  m_backShieldPower = 100;
62  m_frontShieldPower = 100;
63  m_maxShieldPower = 100;
64  m_missiles = 4;
65  m_maxMissiles = 4;
66  heatPunishTime = 1000;
67  originalView = Vector3(0,0,1);
68  originalUp = Vector3(0,1,0);
69  shooting = false;
70  m_shieldRecovers = false;
71  m_ship_was_hit = false;
72 }
73 
75 
78 GLvoid SpaceShip::draw( void ) {
79  glPushMatrix();
80  glTranslatef( getPos().x, getPos().y, getPos().z );
81 
82  Vector3 orgView = this->getOriginalView();
83  orgView.normalize();
84 
85  Vector3 actView = this->getView();
86  actView.normalize();
87 
88  Vector3 orthogonal = orgView * actView;
89  orthogonal.normalize();
90 
91  float projection = orgView.innerProduct(actView); // / actView.length();
92  float angle = acos(projection) / ANGLE2DEG;
93 
94  Vector3 nullvector = Vector3(0,0,0);
95 
96  Plane * testplane = new Plane(nullvector, orthogonal, orgView);
97 
98  float testdistance = testplane->distance(actView);
99 
100  if (testdistance < 0)
101  angle = 360 - angle;
102 
103  glRotatef(angle,orthogonal.x,orthogonal.y,orthogonal.z);
104 
106  glPopMatrix();
107 }
108 
110 
115  if( m_frontShieldPower < 0 || m_backShieldPower < 0 )
116  return true;
117  else
118  return false;
119 }
120 
122 
127 void SpaceShip::coolLaser( DWORD time ) {
128  m_laserHeat -= time * m_maxLaserHeat/5000.0;
129  if( m_laserHeat < 0 )
130  m_laserHeat = 0;
131  if( heatPunishTime > 0)
132  heatPunishTime -= time;
133  else
134  m_overHeated = false;
135 }
136 
137 void SpaceShip::advance( float t)
138 {
140 }
141 
142 void SpaceShip::updateLaser( float t) {
143  if ( shooting && !m_overHeated )
144  useLaser(t);
145  else
146  coolLaser(t);
147 }
148 
149 void SpaceShip::update( float t) {
150  if( m_shieldRecovers ) {
151  this->recoverShieldBack( t );
152  this->recoverShieldFront( t );
153  }
154  advance(t);
155  updateLaser(t);
156 }
157 
162  return m_laserHeat;
163 }
164 
166  return m_maxLaserHeat;
167 }
168 
173  return m_laserHeat/m_maxLaserHeat;
174 }
175 
179 unsigned int SpaceShip::getMissileCount( void ) {
180  return this->m_missiles;
181 }
182 
187  return m_overHeated;
188 }
189 
191 
196 void SpaceShip::useLaser( DWORD time ) {
197  m_laserHeat += time*6 * m_maxLaserHeat/5000.0; // this creates over-heating in 5 seconds or 5000 ms
198  if( m_laserHeat > m_maxLaserHeat ) {
199  m_laserHeat = m_maxLaserHeat;
200  m_overHeated = true;
201  heatPunishTime = 1000;
202  }
203 }
204 
206 
209 void SpaceShip::useMissile( void ) {
210  if( this->m_missiles > 0 )
211  m_missiles--;
212 
213 }
214 
216  return (shooting&&!m_overHeated);
217 }
218 
219 void SpaceShip::setLaserHeat( float heat ) {
220  m_laserHeat = heat;
221 }
222 
223 void SpaceShip::setShoot(bool status){
224  shooting = status;
225 }
226 
231  return m_backShieldPower;
232 }
233 
238  return m_backShieldPower / m_maxShieldPower;
239 }
240 
245  return m_frontShieldPower;
246 }
247 
252  return m_frontShieldPower / m_maxShieldPower;
253 }
254 
259  return originalUp;
260 }
261 
266  return originalView;
267 }
268 
269 void SpaceShip::receiveHitBack( DWORD time ) {
270  m_ship_was_hit=true;
271  if( m_backShieldPower >= 0 )
272  m_backShieldPower -= time*3* m_maxShieldPower/5000.0; // this creates over-heating in 5 seconds or 5000 ms
273 }
274 
275 void SpaceShip::receiveHitFront( DWORD time ) {
276  m_ship_was_hit=true;
277  if( m_frontShieldPower >= 0 )
278  m_frontShieldPower -= time*3* m_maxShieldPower/5000.0; // this creates over-heating in 5 seconds or 5000 ms
279 }
280 
281 void SpaceShip::recoverShieldBack( DWORD time ) {
282  m_backShieldPower += time*0.75 * m_maxShieldPower / 10000.0;
283  if( m_backShieldPower > m_maxShieldPower )
284  m_backShieldPower = m_maxShieldPower;
285 }
286 
287 void SpaceShip::recoverShieldFront( DWORD time ) {
288  m_frontShieldPower += time*0.75 * m_maxShieldPower / 10000.0;
289  if( m_frontShieldPower > m_maxShieldPower )
290  m_frontShieldPower = m_maxShieldPower;
291 
292 }
293 void SpaceShip::setShieldCapacity( float capacity ) {
294  if( capacity < 0 )
295  return;
296  m_maxShieldPower = capacity;
297  if( m_frontShieldPower > m_maxShieldPower )
298  m_frontShieldPower = m_maxShieldPower;
299  if( m_backShieldPower > m_maxShieldPower )
300  m_backShieldPower = m_maxShieldPower;
301 }
302 
303 void SpaceShip::setShieldRecovering( bool recovers ) {
304  m_shieldRecovers = recovers;
305 }
306 
308 {
309  return m_ship_was_hit;
310 }