doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GameSSDWindow.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 #include "../idlib/precompiled.h"
29 #pragma hdrstop
30 
31 #include "../framework/Session_local.h"
32 
33 #include "DeviceContext.h"
34 #include "Window.h"
35 #include "UserInterfaceLocal.h"
36 #include "GameSSDWindow.h"
37 
38 
39 #define Z_NEAR 100.0f
40 #define Z_FAR 4000.0f
41 #define ENTITY_START_DIST 3000
42 
43 #define V_WIDTH 640.0f
44 #define V_HEIGHT 480.0f
45 
46 /*
47 *****************************************************************************
48 * SSDCrossHair
49 ****************************************************************************
50 */
51 
52 #define CROSSHAIR_STANDARD_MATERIAL "game/SSD/crosshair_standard"
53 #define CROSSHAIR_SUPER_MATERIAL "game/SSD/crosshair_super"
54 
56 }
57 
59 }
60 
62 
63  savefile->Write(&currentCrosshair, sizeof(currentCrosshair));
64  savefile->Write(&crosshairWidth, sizeof(crosshairWidth));
65  savefile->Write(&crosshairHeight, sizeof(crosshairHeight));
66 
67 }
68 
70 
72 
73  savefile->Read(&currentCrosshair, sizeof(currentCrosshair));
74  savefile->Read(&crosshairWidth, sizeof(crosshairWidth));
75  savefile->Read(&crosshairHeight, sizeof(crosshairHeight));
76 
77 }
78 
80 
83 
84  crosshairWidth = 64;
85  crosshairHeight = 64;
86 
88 
89 }
90 
91 void SSDCrossHair::Draw(idDeviceContext *dc, const idVec2& cursor) {
92 
93  float x,y;
94  x = cursor.x-(crosshairWidth/2);
95  y = cursor.y-(crosshairHeight/2);
97 
98 }
99 
100 /*
101 *****************************************************************************
102 * SSDEntity
103 ****************************************************************************
104 */
105 
107  EntityInit();
108 }
109 
111 }
112 
114 
115  savefile->Write(&type, sizeof(type));
117  savefile->Write(&position, sizeof(position));
118  savefile->Write(&size, sizeof(size));
119  savefile->Write(&radius, sizeof(radius));
120  savefile->Write(&hitRadius, sizeof(hitRadius));
121  savefile->Write(&rotation, sizeof(rotation));
122 
123  savefile->Write(&matColor, sizeof(matColor));
124 
125  game->WriteSaveGameString(text, savefile);
126  savefile->Write(&textScale, sizeof(textScale));
127  savefile->Write(&foreColor, sizeof(foreColor));
128 
129  savefile->Write(&currentTime, sizeof(currentTime));
130  savefile->Write(&lastUpdate, sizeof(lastUpdate));
131  savefile->Write(&elapsed, sizeof(elapsed));
132 
133  savefile->Write(&destroyed, sizeof(destroyed));
134  savefile->Write(&noHit, sizeof(noHit));
135  savefile->Write(&noPlayerDamage, sizeof(noPlayerDamage));
136 
137  savefile->Write(&inUse, sizeof(inUse));
138 
139 }
140 
142 
143  savefile->Read(&type, sizeof(type));
146  savefile->Read(&position, sizeof(position));
147  savefile->Read(&size, sizeof(size));
148  savefile->Read(&radius, sizeof(radius));
149  savefile->Read(&hitRadius, sizeof(hitRadius));
150  savefile->Read(&rotation, sizeof(rotation));
151 
152  savefile->Read(&matColor, sizeof(matColor));
153 
154  game->ReadSaveGameString(text, savefile);
155  savefile->Read(&textScale, sizeof(textScale));
156  savefile->Read(&foreColor, sizeof(foreColor));
157 
158  game = _game;
159  savefile->Read(&currentTime, sizeof(currentTime));
160  savefile->Read(&lastUpdate, sizeof(lastUpdate));
161  savefile->Read(&elapsed, sizeof(elapsed));
162 
163  savefile->Read(&destroyed, sizeof(destroyed));
164  savefile->Read(&noHit, sizeof(noHit));
165  savefile->Read(&noPlayerDamage, sizeof(noPlayerDamage));
166 
167  savefile->Read(&inUse, sizeof(inUse));
168 }
169 
171 
172  inUse = false;
173 
174 
176 
177  materialName = "";
178  material = NULL;
179  position.Zero();
180  size.Zero();
181  radius = 0.0f;
182  hitRadius = 0.0f;
183  rotation = 0.0f;
184 
185 
186  currentTime = 0;
187  lastUpdate = 0;
188 
189  destroyed = false;
190  noHit = false;
191  noPlayerDamage = false;
192 
193  matColor.Set(1, 1, 1, 1);
194 
195  text = "";
196  textScale = 1.0f;
197  foreColor.Set(1, 1, 1, 1);
198 }
199 
201  game = _game;
202 }
203 
204 void SSDEntity::SetMaterial(const char* name) {
205  materialName = name;
206  material = declManager->FindMaterial( name );
207  material->SetSort( SS_GUI );
208 }
209 
210 void SSDEntity::SetPosition(const idVec3& _position) {
211  position = _position;
212 }
213 
214 void SSDEntity::SetSize(const idVec2& _size) {
215  size = _size;
216 }
217 
218 void SSDEntity::SetRadius(float _radius, float _hitFactor) {
219  radius = _radius;
220  hitRadius = _radius*_hitFactor;
221 }
222 
223 void SSDEntity::SetRotation(float _rotation) {
224  rotation = _rotation;
225 }
226 
228 
230 
231  //Is this the first update
232  if(lastUpdate == 0) {
234  return;
235  }
236 
238 
239  EntityUpdate();
240 
241  lastUpdate = currentTime;
242 }
243 
244 bool SSDEntity::HitTest(const idVec2& pt) {
245 
246  if(noHit) {
247  return false;
248  }
249 
250  idVec3 screenPos = WorldToScreen(position);
251 
252 
253  //Scale the radius based on the distance from the player
254  float scale = 1.0f -((screenPos.z-Z_NEAR)/(Z_FAR-Z_NEAR));
255  float scaledRad = scale*hitRadius;
256 
257  //So we can compare against the square of the length between two points
258  float scaleRadSqr = scaledRad*scaledRad;
259 
260  idVec2 diff = screenPos.ToVec2()-pt;
261  float dist = idMath::Fabs(diff.LengthSqr());
262 
263  if(dist < scaleRadSqr) {
264  return true;
265  }
266  return false;
267 }
268 
270 
271 
272  idVec2 persize;
273  float x,y;
274 
275  idBounds bounds;
276  bounds[0] = idVec3(position.x - (size.x/2.0f), position.y - (size.y/2.0f), position.z);
277  bounds[1] = idVec3(position.x + (size.x/2.0f), position.y + (size.y/2.0f), position.z);
278 
279  idBounds screenBounds = WorldToScreen(bounds);
280  persize.x = idMath::Fabs(screenBounds[1].x - screenBounds[0].x);
281  persize.y = idMath::Fabs(screenBounds[1].y - screenBounds[0].y);
282 
283  idVec3 center = screenBounds.GetCenter();
284 
285  x = screenBounds[0].x;
286  y = screenBounds[1].y;
287  dc->DrawMaterialRotated(x, y, persize.x, persize.y, material, matColor, 1.0f, 1.0f, DEG2RAD(rotation));
288 
289  if(text.Length() > 0) {
291  dc->DrawText( text, textScale, 0, foreColor, rect, false );
292  }
293 
294 }
295 
297  inUse = false;
298 }
299 
301 
302  idVec3 screenMin = WorldToScreen(worldBounds[0]);
303  idVec3 screenMax = WorldToScreen(worldBounds[1]);
304 
305  idBounds screenBounds(screenMin, screenMax);
306  return screenBounds;
307 }
308 
310 
311  float d = 0.5f*V_WIDTH*idMath::Tan(DEG2RAD(90.0f)/2.0f);
312 
313  //World To Camera Coordinates
314  idVec3 cameraTrans(0,0,d);
315  idVec3 cameraPos;
316  cameraPos = worldPos + cameraTrans;
317 
318  //Camera To Screen Coordinates
319  idVec3 screenPos;
320  screenPos.x = d*cameraPos.x/cameraPos.z + (0.5f*V_WIDTH-0.5f);
321  screenPos.y = -d*cameraPos.y/cameraPos.z + (0.5f*V_HEIGHT-0.5f);
322  screenPos.z = cameraPos.z;
323 
324  return screenPos;
325 }
326 
328 
329  idVec3 worldPos;
330 
331  worldPos.x = screenPos.x - 0.5f * V_WIDTH;
332  worldPos.y = -(screenPos.y - 0.5f * V_HEIGHT);
333  worldPos.z = screenPos.z;
334 
335  return worldPos;
336 }
337 
338 /*
339 *****************************************************************************
340 * SSDMover
341 ****************************************************************************
342 */
343 
345 }
346 
348 }
349 
351  SSDEntity::WriteToSaveGame(savefile);
352 
353  savefile->Write(&speed, sizeof(speed));
354  savefile->Write(&rotationSpeed, sizeof(rotationSpeed));
355 }
356 
358  SSDEntity::ReadFromSaveGame(savefile, _game);
359 
360  savefile->Read(&speed, sizeof(speed));
361  savefile->Read(&rotationSpeed, sizeof(rotationSpeed));
362 }
363 
364 void SSDMover::MoverInit(const idVec3& _speed, float _rotationSpeed) {
365 
366  speed = _speed;
367  rotationSpeed = _rotationSpeed;
368 }
369 
371 
373 
374  //Move forward based on speed (units per second)
375  idVec3 moved = ((float)elapsed/1000.0f)*speed;
376  position += moved;
377 
378  float rotated = ((float)elapsed/1000.0f)*rotationSpeed*360.0f;
379  rotation += rotated;
380  if(rotation >= 360) {
381  rotation -= 360.0f;
382  }
383  if(rotation < 0) {
384  rotation += 360.0f;
385  }
386 }
387 
388 
389 /*
390 *****************************************************************************
391 * SSDAsteroid
392 ****************************************************************************
393 */
394 
396 
397 #define ASTEROID_MATERIAL "game/SSD/asteroid"
398 
400 }
401 
403 }
404 
406  SSDMover::WriteToSaveGame(savefile);
407 
408  savefile->Write(&health, sizeof(health));
409 }
410 
412  SSDMover::ReadFromSaveGame(savefile, _game);
413 
414  savefile->Read(&health, sizeof(health));
415 }
416 
417 void SSDAsteroid::Init(idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health) {
418 
419  EntityInit();
420  MoverInit(idVec3(0,0, -_speed), rotate);
421 
422  SetGame(_game);
423 
425 
427  SetSize(_size);
428  SetRadius(Max(size.x, size.y), 0.3f);
430 
431 
432  position = startPosition;
433 
434  health = _health;
435 }
436 
438 
440 }
441 
442 SSDAsteroid* SSDAsteroid::GetNewAsteroid(idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health) {
443  for(int i = 0; i < MAX_ASTEROIDS; i++) {
444  if(!asteroidPool[i].inUse) {
445  asteroidPool[i].Init(_game, startPosition, _size, _speed, rotate, _health);
446  asteroidPool[i].inUse = true;
447  asteroidPool[i].id = i;
448 
449  return &asteroidPool[i];
450  }
451  }
452  return NULL;
453 }
454 
456  return &asteroidPool[id];
457 }
458 
460  int count = 0;
461  for(int i = 0; i < MAX_ASTEROIDS; i++) {
462  if(asteroidPool[i].inUse) {
463  count++;
464  }
465  }
466  savefile->Write(&count, sizeof(count));
467  for(int i = 0; i < MAX_ASTEROIDS; i++) {
468  if(asteroidPool[i].inUse) {
469  savefile->Write(&(asteroidPool[i].id), sizeof(asteroidPool[i].id));
470  asteroidPool[i].WriteToSaveGame(savefile);
471  }
472  }
473 }
474 
476 
477  int count;
478  savefile->Read(&count, sizeof(count));
479  for(int i = 0; i < count; i++) {
480  int id;
481  savefile->Read(&id, sizeof(id));
482  SSDAsteroid* ent = GetSpecificAsteroid(id);
483  ent->ReadFromSaveGame(savefile, _game);
484  }
485 }
486 
487 /*
488 *****************************************************************************
489 * SSDAstronaut
490 ****************************************************************************
491 */
492 
494 
495 #define ASTRONAUT_MATERIAL "game/SSD/astronaut"
496 
498 }
499 
501 }
502 
504  SSDMover::WriteToSaveGame(savefile);
505 
506  savefile->Write(&health, sizeof(health));
507 }
508 
510  SSDMover::ReadFromSaveGame(savefile, _game);
511 
512  savefile->Read(&health, sizeof(health));
513 }
514 
515 void SSDAstronaut::Init(idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health) {
516 
517  EntityInit();
518  MoverInit(idVec3(0,0, -_speed), rotate);
519 
520  SetGame(_game);
521 
523 
525  SetSize(idVec2(256,256));
526  SetRadius(Max(size.x, size.y), 0.3f);
528 
529  position = startPosition;
530  health = _health;
531 }
532 
533 SSDAstronaut* SSDAstronaut::GetNewAstronaut(idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health) {
534  for(int i = 0; i < MAX_ASTRONAUT; i++) {
535  if(!astronautPool[i].inUse) {
536  astronautPool[i].Init(_game, startPosition, _speed, rotate, _health);
537  astronautPool[i].inUse = true;
538  astronautPool[i].id = i;
539  return &astronautPool[i];
540  }
541  }
542  return NULL;
543 }
544 
546  return &astronautPool[id];
547 
548 }
549 
551  int count = 0;
552  for(int i = 0; i < MAX_ASTRONAUT; i++) {
553  if(astronautPool[i].inUse) {
554  count++;
555  }
556  }
557  savefile->Write(&count, sizeof(count));
558  for(int i = 0; i < MAX_ASTRONAUT; i++) {
559  if(astronautPool[i].inUse) {
560  savefile->Write(&(astronautPool[i].id), sizeof(astronautPool[i].id));
561  astronautPool[i].WriteToSaveGame(savefile);
562  }
563  }
564 }
565 
567 
568  int count;
569  savefile->Read(&count, sizeof(count));
570  for(int i = 0; i < count; i++) {
571  int id;
572  savefile->Read(&id, sizeof(id));
574  ent->ReadFromSaveGame(savefile, _game);
575  }
576 }
577 
578 /*
579 *****************************************************************************
580 * SSDExplosion
581 ****************************************************************************
582 */
583 
585 
586 
587 //#define EXPLOSION_MATERIAL "game/SSD/fball"
588 //#define EXPLOSION_TELEPORT "game/SSD/teleport"
589 
590 const char* explosionMaterials[] = {
591  "game/SSD/fball",
592  "game/SSD/teleport"
593 };
594 
595 #define EXPLOSION_MATERIAL_COUNT 2
596 
599 }
600 
602 }
603 
605  SSDEntity::WriteToSaveGame(savefile);
606 
607  savefile->Write(&finalSize, sizeof(finalSize));
608  savefile->Write(&length, sizeof(length));
609  savefile->Write(&beginTime, sizeof(beginTime));
610  savefile->Write(&endTime, sizeof(endTime));
611  savefile->Write(&explosionType, sizeof(explosionType));
612 
613 
614  savefile->Write(&(buddy->type), sizeof(buddy->type));
615  savefile->Write(&(buddy->id), sizeof(buddy->id));
616 
617  savefile->Write(&killBuddy, sizeof(killBuddy));
618  savefile->Write(&followBuddy, sizeof(followBuddy));
619 }
620 
622  SSDEntity::ReadFromSaveGame(savefile, _game);
623 
624  savefile->Read(&finalSize, sizeof(finalSize));
625  savefile->Read(&length, sizeof(length));
626  savefile->Read(&beginTime, sizeof(beginTime));
627  savefile->Read(&endTime, sizeof(endTime));
628  savefile->Read(&explosionType, sizeof(explosionType));
629 
630  int type, id;
631  savefile->Read(&type, sizeof(type));
632  savefile->Read(&id, sizeof(id));
633 
634  //Get a pointer to my buddy
635  buddy = _game->GetSpecificEntity(type, id);
636 
637  savefile->Read(&killBuddy, sizeof(killBuddy));
638  savefile->Read(&followBuddy, sizeof(followBuddy));
639 }
640 
641 void SSDExplosion::Init(idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy, bool _followBuddy) {
642 
643  EntityInit();
644 
645  SetGame(_game);
646 
648  explosionType = _type;
649 
651  SetPosition(_position);
652  position.z -= 50;
653 
654  finalSize = _size;
655  length = _length;
658 
659  buddy = _buddy;
660  killBuddy = _killBuddy;
661  followBuddy = _followBuddy;
662 
663  //Explosion Starts from nothing and will increase in size until it gets to final size
664  size.Zero();
665 
666  noPlayerDamage = true;
667  noHit = true;
668 }
669 
671 
673 
674  //Always set my position to my buddies position except change z to be on top
675  if(followBuddy) {
677  position.z -= 50;
678  } else {
679  //Only mess with the z if we are not following
680  position.z = buddy->position.z - 50;
681  }
682 
683  //Scale the image based on the time
685 
686  //Destroy myself after the explosion is done
687  if(currentTime > endTime) {
688  destroyed = true;
689 
690  if(killBuddy) {
691  //Destroy the exploding object
692  buddy->destroyed = true;
693  }
694  }
695 }
696 
697 SSDExplosion* SSDExplosion::GetNewExplosion(idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy, bool _followBuddy) {
698  for(int i = 0; i < MAX_EXPLOSIONS; i++) {
699  if(!explosionPool[i].inUse) {
700  explosionPool[i].Init(_game, _position, _size, _length, _type, _buddy, _killBuddy, _followBuddy);
701  explosionPool[i].inUse = true;
702  return &explosionPool[i];
703  }
704  }
705  return NULL;
706 }
707 
709  return &explosionPool[id];
710 }
711 
713  int count = 0;
714  for(int i = 0; i < MAX_EXPLOSIONS; i++) {
715  if(explosionPool[i].inUse) {
716  count++;
717  }
718  }
719  savefile->Write(&count, sizeof(count));
720  for(int i = 0; i < MAX_EXPLOSIONS; i++) {
721  if(explosionPool[i].inUse) {
722  savefile->Write(&(explosionPool[i].id), sizeof(explosionPool[i].id));
723  explosionPool[i].WriteToSaveGame(savefile);
724  }
725  }
726 }
727 
729 
730  int count;
731  savefile->Read(&count, sizeof(count));
732  for(int i = 0; i < count; i++) {
733  int id;
734  savefile->Read(&id, sizeof(id));
736  ent->ReadFromSaveGame(savefile, _game);
737  }
738 }
739 
740 /*
741 *****************************************************************************
742 * SSDPoints
743 ****************************************************************************
744 */
745 
747 
750 }
751 
753 }
754 
756  SSDEntity::WriteToSaveGame(savefile);
757 
758  savefile->Write(&length, sizeof(length));
759  savefile->Write(&distance, sizeof(distance));
760  savefile->Write(&beginTime, sizeof(beginTime));
761  savefile->Write(&endTime, sizeof(endTime));
762 
763  savefile->Write(&beginPosition, sizeof(beginPosition));
764  savefile->Write(&endPosition, sizeof(endPosition));
765 
766  savefile->Write(&beginColor, sizeof(beginColor));
767  savefile->Write(&endColor, sizeof(endColor));
768 
769 }
770 
772  SSDEntity::ReadFromSaveGame(savefile, _game);
773 
774  savefile->Read(&length, sizeof(length));
775  savefile->Read(&distance, sizeof(distance));
776  savefile->Read(&beginTime, sizeof(beginTime));
777  savefile->Read(&endTime, sizeof(endTime));
778 
779  savefile->Read(&beginPosition, sizeof(beginPosition));
780  savefile->Read(&endPosition, sizeof(endPosition));
781 
782  savefile->Read(&beginColor, sizeof(beginColor));
783  savefile->Read(&endColor, sizeof(endColor));
784 }
785 
786 void SSDPoints::Init(idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color) {
787 
788  EntityInit();
789 
790  SetGame(_game);
791 
792  length = _length;
793  distance = _distance;
796 
797  textScale = 0.4f;
798  text = va("%d", _points);
799 
800  float width = 0;
801  for(int i = 0; i < text.Length(); i++) {
802  width += game->GetDC()->CharWidth(text[i], textScale);
803  }
804 
805  size.Set(0,0);
806 
807  //Set the start position at the top of the passed in entity
810 
811  position.z = 0;
812  position.x -= (width/2.0f);
813 
815 
817  endPosition.y += _distance;
818 
819  //beginColor.Set(0,1,0,1);
820  endColor.Set(1,1,1,0);
821 
822  beginColor = color;
823  beginColor.w = 1;
824 
825  noPlayerDamage = true;
826  noHit = true;
827 }
828 
830 
831  float t = (float)(currentTime - beginTime)/(float)length;
832 
833  //Move up from the start position
835 
836  //Interpolate the color
838 
839  if(currentTime > endTime) {
840  destroyed = true;
841  }
842 }
843 
844 SSDPoints* SSDPoints::GetNewPoints(idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color) {
845  for(int i = 0; i < MAX_POINTS; i++) {
846  if(!pointsPool[i].inUse) {
847  pointsPool[i].Init(_game, _ent, _points, _length, _distance, color);
848  pointsPool[i].inUse = true;
849  return &pointsPool[i];
850  }
851  }
852  return NULL;
853 }
854 
856  return &pointsPool[id];
857 }
858 
860  int count = 0;
861  for(int i = 0; i < MAX_POINTS; i++) {
862  if(pointsPool[i].inUse) {
863  count++;
864  }
865  }
866  savefile->Write(&count, sizeof(count));
867  for(int i = 0; i < MAX_POINTS; i++) {
868  if(pointsPool[i].inUse) {
869  savefile->Write(&(pointsPool[i].id), sizeof(pointsPool[i].id));
870  pointsPool[i].WriteToSaveGame(savefile);
871  }
872  }
873 }
874 
876 
877  int count;
878  savefile->Read(&count, sizeof(count));
879  for(int i = 0; i < count; i++) {
880  int id;
881  savefile->Read(&id, sizeof(id));
882  SSDPoints* ent = GetSpecificPoints(id);
883  ent->ReadFromSaveGame(savefile, _game);
884  }
885 }
886 
887 /*
888 *****************************************************************************
889 * SSDProjectile
890 ****************************************************************************
891 */
892 
894 
895 #define PROJECTILE_MATERIAL "game/SSD/fball"
896 
899 }
900 
902 }
903 
905  SSDEntity::WriteToSaveGame(savefile);
906 
907  savefile->Write(&dir, sizeof(dir));
908  savefile->Write(&speed, sizeof(speed));
909  savefile->Write(&beginTime, sizeof(beginTime));
910  savefile->Write(&endTime, sizeof(endTime));
911 
912  savefile->Write(&endPosition, sizeof(endPosition));
913 }
914 
916  SSDEntity::ReadFromSaveGame(savefile, _game);
917 
918  savefile->Read(&dir, sizeof(dir));
919  savefile->Read(&speed, sizeof(speed));
920  savefile->Read(&beginTime, sizeof(beginTime));
921  savefile->Read(&endTime, sizeof(endTime));
922 
923  savefile->Read(&endPosition, sizeof(endPosition));
924 }
925 
926 void SSDProjectile::Init(idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size) {
927 
928  EntityInit();
929 
930  SetGame(_game);
931 
933  size.Set(_size,_size);
934 
935  position = _beginPosition;
936  endPosition = _endPosition;
937 
938  dir = _endPosition - position;
939  dir.Normalize();
940 
941  //speed.Zero();
942  speed.x = speed.y = speed.z = _speed;
943 
944  noHit = true;
945 }
946 
948 
950 
951  //Move forward based on speed (units per second)
952  idVec3 moved = dir*((float)elapsed/1000.0f)*speed.z;
953  position += moved;
954 
955  if(position.z > endPosition.z) {
956  //We have reached our position
957  destroyed = true;
958  }
959 }
960 
961 SSDProjectile* SSDProjectile::GetNewProjectile(idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size) {
962  for(int i = 0; i < MAX_PROJECTILES; i++) {
963  if(!projectilePool[i].inUse) {
964  projectilePool[i].Init(_game, _beginPosition, _endPosition, _speed, _size);
965  projectilePool[i].inUse = true;
966  return &projectilePool[i];
967  }
968  }
969  return NULL;
970 }
971 
973  return &projectilePool[id];
974 }
975 
977  int count = 0;
978  for(int i = 0; i < MAX_PROJECTILES; i++) {
979  if(projectilePool[i].inUse) {
980  count++;
981  }
982  }
983  savefile->Write(&count, sizeof(count));
984  for(int i = 0; i < MAX_PROJECTILES; i++) {
985  if(projectilePool[i].inUse) {
986  savefile->Write(&(projectilePool[i].id), sizeof(projectilePool[i].id));
987  projectilePool[i].WriteToSaveGame(savefile);
988  }
989  }
990 }
991 
993 
994  int count;
995  savefile->Read(&count, sizeof(count));
996  for(int i = 0; i < count; i++) {
997  int id;
998  savefile->Read(&id, sizeof(id));
1000  ent->ReadFromSaveGame(savefile, _game);
1001  }
1002 }
1003 
1004 /*
1005 *****************************************************************************
1006 * SSDPowerup
1007 ****************************************************************************
1008 */
1009 
1010 const char* powerupMaterials[][2] = {
1011  "game/SSD/powerupHealthClosed", "game/SSD/powerupHealthOpen",
1012  "game/SSD/powerupSuperBlasterClosed", "game/SSD/powerupSuperBlasterOpen",
1013  "game/SSD/powerupNukeClosed", "game/SSD/powerupNukeOpen",
1014  "game/SSD/powerupRescueClosed", "game/SSD/powerupRescueOpen",
1015  "game/SSD/powerupBonusPointsClosed", "game/SSD/powerupBonusPointsOpen",
1016  "game/SSD/powerupDamageClosed", "game/SSD/powerupDamageOpen",
1017 };
1018 
1019 #define POWERUP_MATERIAL_COUNT 6
1020 
1022 
1024 
1025 }
1026 
1028 }
1029 
1031  SSDMover::WriteToSaveGame(savefile);
1032 
1033  savefile->Write(&powerupState, sizeof(powerupState));
1034  savefile->Write(&powerupType, sizeof(powerupType));
1035 }
1036 
1038  SSDMover::ReadFromSaveGame(savefile, _game);
1039 
1040  savefile->Read(&powerupState, sizeof(powerupState));
1041  savefile->Read(&powerupType, sizeof(powerupType));
1042 }
1043 
1044 void SSDPowerup::OnHit(int key) {
1045 
1047 
1048  //Small explosion to indicate it is opened
1049  SSDExplosion* explosion = SSDExplosion::GetNewExplosion(game, position, size*2.0f, 300, SSDExplosion::EXPLOSION_NORMAL, this, false, true);
1050  game->entities.Append(explosion);
1051 
1052 
1055  } else {
1056  //Destory the powerup with a big explosion
1058  game->entities.Append(explosion);
1059  game->PlaySound("arcade_explode");
1060 
1061  noHit = true;
1062  noPlayerDamage = true;
1063  }
1064 }
1065 
1067 
1069  //The powerup was open so activate it
1071  }
1072 
1073  //Just destroy the powerup
1074  destroyed = true;
1075 }
1076 
1078 }
1079 
1081  switch(powerupType) {
1082  case POWERUP_TYPE_HEALTH:
1083  {
1084  game->AddHealth(10);
1085  break;
1086  }
1088  {
1089  game->OnSuperBlaster();
1090  break;
1091  }
1093  {
1094  game->OnNuke();
1095  break;
1096  }
1098  {
1099  game->OnRescueAll();
1100  break;
1101  }
1103  {
1104  int points = (game->random.RandomInt(5)+1) * 100;
1105  game->AddScore(this, points);
1106  break;
1107  }
1108  case POWERUP_TYPE_DAMAGE:
1109  {
1110  game->AddDamage(10);
1111  game->PlaySound("arcade_explode");
1112  break;
1113  }
1114 
1115  }
1116 }
1117 
1118 
1119 void SSDPowerup::Init(idGameSSDWindow* _game, float _speed, float _rotation) {
1120 
1121  EntityInit();
1122  MoverInit(idVec3(0,0, -_speed), _rotation);
1123 
1124  SetGame(_game);
1125  SetSize(idVec2(200,200));
1126  SetRadius(Max(size.x, size.y), 0.3f);
1127 
1129 
1130  idVec3 startPosition;
1131  startPosition.x = game->random.RandomInt(V_WIDTH)-(V_WIDTH/2.0f);
1132  startPosition.y = game->random.RandomInt(V_HEIGHT)-(V_HEIGHT/2.0f);
1133  startPosition.z = ENTITY_START_DIST;
1134 
1135  position = startPosition;
1136  //SetPosition(startPosition);
1137 
1140  if(powerupType >= POWERUP_TYPE_MAX) {
1141  powerupType = 0;
1142  }
1143 
1144  /*OutputDebugString(va("Powerup: %d\n", powerupType));
1145  if(powerupType == 0) {
1146  int x = 0;
1147  }*/
1148 
1150 }
1151 
1152 SSDPowerup* SSDPowerup::GetNewPowerup(idGameSSDWindow* _game, float _speed, float _rotation) {
1153 
1154  for(int i = 0; i < MAX_POWERUPS; i++) {
1155  if(!powerupPool[i].inUse) {
1156  powerupPool[i].Init(_game, _speed, _rotation);
1157  powerupPool[i].inUse = true;
1158  return &powerupPool[i];
1159  }
1160  }
1161  return NULL;
1162 }
1163 
1165  return &powerupPool[id];
1166 }
1167 
1169  int count = 0;
1170  for(int i = 0; i < MAX_POWERUPS; i++) {
1171  if(powerupPool[i].inUse) {
1172  count++;
1173  }
1174  }
1175  savefile->Write(&count, sizeof(count));
1176  for(int i = 0; i < MAX_POWERUPS; i++) {
1177  if(powerupPool[i].inUse) {
1178  savefile->Write(&(powerupPool[i].id), sizeof(powerupPool[i].id));
1179  powerupPool[i].WriteToSaveGame(savefile);
1180  }
1181  }
1182 }
1183 
1185 
1186  int count;
1187  savefile->Read(&count, sizeof(count));
1188  for(int i = 0; i < count; i++) {
1189  int id;
1190  savefile->Read(&id, sizeof(id));
1191  SSDPowerup* ent = GetSpecificPowerup(id);
1192  ent->ReadFromSaveGame(savefile, _game);
1193  }
1194 }
1195 
1196 /*
1197 *****************************************************************************
1198 * idGameSSDWindow
1199 ****************************************************************************
1200 */
1201 
1203 
1205  dc = d;
1206  gui = g;
1207  CommonInit();
1208 }
1209 
1211  gui = g;
1212  CommonInit();
1213 }
1214 
1216  ResetGameStats();
1217 }
1218 
1220  idWindow::WriteToSaveGame(savefile);
1221 
1222  savefile->Write(&ssdTime, sizeof(ssdTime));
1223 
1224  beginLevel.WriteToSaveGame(savefile);
1225  resetGame.WriteToSaveGame(savefile);
1226  continueGame.WriteToSaveGame(savefile);
1227  refreshGuiData.WriteToSaveGame(savefile);
1228 
1229  crosshair.WriteToSaveGame(savefile);
1230  savefile->Write(&screenBounds, sizeof(screenBounds));
1231 
1232  savefile->Write(&levelCount, sizeof(levelCount));
1233  for(int i = 0; i < levelCount; i++) {
1234  savefile->Write(&(levelData[i]), sizeof(SSDLevelData_t));
1235  savefile->Write(&(asteroidData[i]), sizeof(SSDAsteroidData_t));
1236  savefile->Write(&(astronautData[i]), sizeof(SSDAstronautData_t));
1237  savefile->Write(&(powerupData[i]), sizeof(SSDPowerupData_t));
1238  }
1239 
1240  savefile->Write(&weaponCount, sizeof(weaponCount));
1241  for(int i = 0; i < weaponCount; i++) {
1242  savefile->Write(&(weaponData[i]), sizeof(SSDWeaponData_t));
1243  }
1244 
1245  savefile->Write(&superBlasterTimeout, sizeof(superBlasterTimeout));
1246  savefile->Write(&gameStats, sizeof(SSDGameStats_t));
1247 
1248  //Write All Static Entities
1249  SSDAsteroid::WriteAsteroids(savefile);
1252  SSDPoints::WritePoints(savefile);
1254  SSDPowerup::WritePowerups(savefile);
1255 
1256  int entCount = entities.Num();
1257  savefile->Write(&entCount, sizeof(entCount));
1258  for(int i = 0; i < entCount; i++) {
1259  savefile->Write(&(entities[i]->type), sizeof(entities[i]->type));
1260  savefile->Write(&(entities[i]->id), sizeof(entities[i]->id));
1261  }
1262 }
1263 
1265  idWindow::ReadFromSaveGame(savefile);
1266 
1267 
1268  savefile->Read(&ssdTime, sizeof(ssdTime));
1269 
1270  beginLevel.ReadFromSaveGame(savefile);
1271  resetGame.ReadFromSaveGame(savefile);
1272  continueGame.ReadFromSaveGame(savefile);
1273  refreshGuiData.ReadFromSaveGame(savefile);
1274 
1275  crosshair.ReadFromSaveGame(savefile);
1276  savefile->Read(&screenBounds, sizeof(screenBounds));
1277 
1278  savefile->Read(&levelCount, sizeof(levelCount));
1279  for(int i = 0; i < levelCount; i++) {
1280  SSDLevelData_t newLevel;
1281  savefile->Read(&newLevel, sizeof(SSDLevelData_t));
1282  levelData.Append(newLevel);
1283 
1284  SSDAsteroidData_t newAsteroid;
1285  savefile->Read(&newAsteroid, sizeof(SSDAsteroidData_t));
1286  asteroidData.Append(newAsteroid);
1287 
1288  SSDAstronautData_t newAstronaut;
1289  savefile->Read(&newAstronaut, sizeof(SSDAstronautData_t));
1290  astronautData.Append(newAstronaut);
1291 
1292  SSDPowerupData_t newPowerup;
1293  savefile->Read(&newPowerup, sizeof(SSDPowerupData_t));
1294  powerupData.Append(newPowerup);
1295  }
1296 
1297  savefile->Read(&weaponCount, sizeof(weaponCount));
1298  for(int i = 0; i < weaponCount; i++) {
1299  SSDWeaponData_t newWeapon;
1300  savefile->Read(&newWeapon, sizeof(SSDWeaponData_t));
1301  weaponData.Append(newWeapon);
1302  }
1303 
1304  savefile->Read(&superBlasterTimeout, sizeof(superBlasterTimeout));
1305 
1306  savefile->Read(&gameStats, sizeof(SSDGameStats_t));
1307  //Reset this because it is no longer valid
1309 
1310  SSDAsteroid::ReadAsteroids(savefile, this);
1311  SSDAstronaut::ReadAstronauts(savefile, this);
1312  SSDExplosion::ReadExplosions(savefile, this);
1313  SSDPoints::ReadPoints(savefile, this);
1314  SSDProjectile::ReadProjectiles(savefile, this);
1315  SSDPowerup::ReadPowerups(savefile, this);
1316 
1317  int entCount;
1318  savefile->Read(&entCount, sizeof(entCount));
1319 
1320  for(int i = 0; i < entCount; i++) {
1321  int type, id;
1322  savefile->Read(&type, sizeof(type));
1323  savefile->Read(&id, sizeof(id));
1324 
1325  SSDEntity* ent = GetSpecificEntity(type, id);
1326  if(ent) {
1327  entities.Append(ent);
1328  }
1329  }
1330 }
1331 
1332 const char *idGameSSDWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
1333 
1334  // need to call this to allow proper focus and capturing on embedded children
1335  const char *ret = idWindow::HandleEvent(event, updateVisuals);
1336 
1337  if(!gameStats.gameRunning) {
1338  return ret;
1339  }
1340 
1341  int key = event->evValue;
1342 
1343  if ( event->evType == SE_KEY ) {
1344 
1345  if ( !event->evValue2 ) {
1346  return ret;
1347  }
1348 
1349  if ( key == K_MOUSE1 || key == K_MOUSE2) {
1350  FireWeapon(key);
1351  } else {
1352  return ret;
1353  }
1354  }
1355  return ret;
1356 }
1357 
1358 idWinVar *idGameSSDWindow::GetWinVarByName (const char *_name, bool winLookup, drawWin_t** owner) {
1359 
1360  idWinVar *retVar = NULL;
1361 
1362  if (idStr::Icmp(_name, "beginLevel") == 0) {
1363  retVar = &beginLevel;
1364  }
1365 
1366  if (idStr::Icmp(_name, "resetGame") == 0) {
1367  retVar = &resetGame;
1368  }
1369 
1370  if (idStr::Icmp(_name, "continueGame") == 0) {
1371  retVar = &continueGame;
1372  }
1373  if (idStr::Icmp(_name, "refreshGuiData") == 0) {
1374  retVar = &refreshGuiData;
1375  }
1376 
1377 
1378  if(retVar) {
1379  return retVar;
1380  }
1381 
1382  return idWindow::GetWinVarByName(_name, winLookup, owner);
1383 }
1384 
1385 
1386 void idGameSSDWindow::Draw(int time, float x, float y) {
1387 
1388  //Update the game every frame before drawing
1389  UpdateGame();
1390 
1391  RefreshGuiData();
1392 
1393  if(gameStats.gameRunning) {
1394 
1395  ZOrderEntities();
1396 
1397  //Draw from back to front
1398  for(int i = entities.Num()-1; i >= 0; i--) {
1399  entities[i]->Draw(dc);
1400  }
1401 
1402  //The last thing to draw is the crosshair
1403  idVec2 cursor;
1404  //GetCursor(cursor);
1405  cursor.x = gui->CursorX();
1406  cursor.y = gui->CursorY();
1407 
1408  crosshair.Draw(dc, cursor);
1409  }
1410 }
1411 
1412 
1414 
1415  if (idStr::Icmp(_name, "beginLevel") == 0) {
1416  beginLevel = src->ParseBool();
1417  return true;
1418  }
1419  if (idStr::Icmp(_name, "resetGame") == 0) {
1420  resetGame = src->ParseBool();
1421  return true;
1422  }
1423  if (idStr::Icmp(_name, "continueGame") == 0) {
1424  continueGame = src->ParseBool();
1425  return true;
1426  }
1427  if (idStr::Icmp(_name, "refreshGuiData") == 0) {
1428  refreshGuiData = src->ParseBool();
1429  return true;
1430  }
1431 
1432  if(idStr::Icmp(_name, "levelcount") == 0) {
1433  levelCount = src->ParseInt();
1434  for(int i = 0; i < levelCount; i++) {
1435  SSDLevelData_t newLevel;
1436  memset(&newLevel, 0, sizeof(SSDLevelData_t));
1437  levelData.Append(newLevel);
1438 
1439  SSDAsteroidData_t newAsteroid;
1440  memset(&newAsteroid, 0, sizeof(SSDAsteroidData_t));
1441  asteroidData.Append(newAsteroid);
1442 
1443  SSDAstronautData_t newAstronaut;
1444  memset(&newAstronaut, 0, sizeof(SSDAstronautData_t));
1445  astronautData.Append(newAstronaut);
1446 
1447  SSDPowerupData_t newPowerup;
1448  memset(&newPowerup, 0, sizeof(SSDPowerupData_t));
1449  powerupData.Append(newPowerup);
1450 
1451 
1452  }
1453  return true;
1454  }
1455  if(idStr::Icmp(_name, "weaponCount") == 0) {
1456  weaponCount = src->ParseInt();
1457  for(int i = 0; i < weaponCount; i++) {
1458  SSDWeaponData_t newWeapon;
1459  memset(&newWeapon, 0, sizeof(SSDWeaponData_t));
1460  weaponData.Append(newWeapon);
1461  }
1462  return true;
1463  }
1464 
1465  if(idStr::FindText(_name, "leveldata", false) >= 0) {
1466  idStr tempName = _name;
1467  int level = atoi(tempName.Right(2))-1;
1468 
1469  idStr levelData;
1470  ParseString(src, levelData);
1471  ParseLevelData(level, levelData);
1472  return true;
1473  }
1474 
1475  if(idStr::FindText(_name, "asteroiddata", false) >= 0) {
1476  idStr tempName = _name;
1477  int level = atoi(tempName.Right(2))-1;
1478 
1480  ParseString(src, asteroidData);
1481  ParseAsteroidData(level, asteroidData);
1482  return true;
1483  }
1484 
1485  if(idStr::FindText(_name, "weapondata", false) >= 0) {
1486  idStr tempName = _name;
1487  int weapon = atoi(tempName.Right(2))-1;
1488 
1489  idStr weaponData;
1490  ParseString(src, weaponData);
1491  ParseWeaponData(weapon, weaponData);
1492  return true;
1493  }
1494 
1495  if(idStr::FindText(_name, "astronautdata", false) >= 0) {
1496  idStr tempName = _name;
1497  int level = atoi(tempName.Right(2))-1;
1498 
1500  ParseString(src, astronautData);
1501  ParseAstronautData(level, astronautData);
1502  return true;
1503  }
1504 
1505  if(idStr::FindText(_name, "powerupdata", false) >= 0) {
1506  idStr tempName = _name;
1507  int level = atoi(tempName.Right(2))-1;
1508 
1510  ParseString(src, powerupData);
1511  ParsePowerupData(level, powerupData);
1512  return true;
1513  }
1514 
1515  return idWindow::ParseInternalVar(_name, src);
1516 }
1517 
1518 void idGameSSDWindow::ParseLevelData(int level, const idStr& levelDataString) {
1519 
1520  idParser parser;
1521  idToken token;
1522  parser.LoadMemory(levelDataString.c_str(), levelDataString.Length(), "LevelData");
1523 
1524  levelData[level].spawnBuffer = parser.ParseFloat();
1525  levelData[level].needToWin = parser.ParseInt(); //Required Destroyed
1526 
1527 }
1528 
1529 void idGameSSDWindow::ParseAsteroidData(int level, const idStr& asteroidDataString) {
1530 
1531  idParser parser;
1532  idToken token;
1533  parser.LoadMemory(asteroidDataString.c_str(), asteroidDataString.Length(), "AsteroidData");
1534 
1535  asteroidData[level].speedMin = parser.ParseFloat(); //Speed Min
1536  asteroidData[level].speedMax = parser.ParseFloat(); //Speed Max
1537 
1538  asteroidData[level].sizeMin = parser.ParseFloat(); //Size Min
1539  asteroidData[level].sizeMax = parser.ParseFloat(); //Size Max
1540 
1541  asteroidData[level].rotateMin = parser.ParseFloat(); //Rotate Min (rotations per second)
1542  asteroidData[level].rotateMax = parser.ParseFloat(); //Rotate Max (rotations per second)
1543 
1544  asteroidData[level].spawnMin = parser.ParseInt(); //Spawn Min
1545  asteroidData[level].spawnMax = parser.ParseInt(); //Spawn Max
1546 
1547  asteroidData[level].asteroidHealth = parser.ParseInt(); //Health of the asteroid
1548  asteroidData[level].asteroidDamage = parser.ParseInt(); //Asteroid Damage
1549  asteroidData[level].asteroidPoints = parser.ParseInt(); //Points awarded for destruction
1550 }
1551 
1552 void idGameSSDWindow::ParsePowerupData(int level, const idStr& powerupDataString) {
1553 
1554  idParser parser;
1555  idToken token;
1556  parser.LoadMemory(powerupDataString.c_str(), powerupDataString.Length(), "PowerupData");
1557 
1558  powerupData[level].speedMin = parser.ParseFloat(); //Speed Min
1559  powerupData[level].speedMax = parser.ParseFloat(); //Speed Max
1560 
1561  powerupData[level].rotateMin = parser.ParseFloat(); //Rotate Min (rotations per second)
1562  powerupData[level].rotateMax = parser.ParseFloat(); //Rotate Max (rotations per second)
1563 
1564  powerupData[level].spawnMin = parser.ParseInt(); //Spawn Min
1565  powerupData[level].spawnMax = parser.ParseInt(); //Spawn Max
1566 
1567 }
1568 
1569 void idGameSSDWindow::ParseWeaponData(int weapon, const idStr& weaponDataString) {
1570 
1571  idParser parser;
1572  idToken token;
1573  parser.LoadMemory(weaponDataString.c_str(), weaponDataString.Length(), "WeaponData");
1574 
1575  weaponData[weapon].speed = parser.ParseFloat();
1576  weaponData[weapon].damage = parser.ParseFloat();
1577  weaponData[weapon].size = parser.ParseFloat();
1578 }
1579 
1580 void idGameSSDWindow::ParseAstronautData(int level, const idStr& astronautDataString) {
1581 
1582  idParser parser;
1583  idToken token;
1584  parser.LoadMemory(astronautDataString.c_str(), astronautDataString.Length(), "AstronautData");
1585 
1586  astronautData[level].speedMin = parser.ParseFloat(); //Speed Min
1587  astronautData[level].speedMax = parser.ParseFloat(); //Speed Max
1588 
1589  astronautData[level].rotateMin = parser.ParseFloat(); //Rotate Min (rotations per second)
1590  astronautData[level].rotateMax = parser.ParseFloat(); //Rotate Max (rotations per second)
1591 
1592  astronautData[level].spawnMin = parser.ParseInt(); //Spawn Min
1593  astronautData[level].spawnMax = parser.ParseInt(); //Spawn Max
1594 
1595  astronautData[level].health = parser.ParseInt(); //Health of the asteroid
1596  astronautData[level].points = parser.ParseInt(); //Asteroid Damage
1597  astronautData[level].penalty = parser.ParseInt(); //Points awarded for destruction
1598 }
1599 
1602 
1603 
1604  beginLevel = false;
1605  resetGame = false;
1606  continueGame = false;
1607  refreshGuiData = false;
1608 
1609  ssdTime = 0;
1610  levelCount = 0;
1611  weaponCount = 0;
1612  screenBounds = idBounds(idVec3(-320,-240,0), idVec3(320,240,0));
1613 
1614  superBlasterTimeout = 0;
1615 
1616  currentSound = 0;
1617 
1618  //Precahce all assets that are loaded dynamically
1621 
1622  for(int i = 0; i < EXPLOSION_MATERIAL_COUNT; i++) {
1624  }
1626  for(int i = 0; i < POWERUP_MATERIAL_COUNT; i++) {
1629  }
1630 
1631  // Precache sounds
1632  declManager->FindSound( "arcade_blaster" );
1633  declManager->FindSound( "arcade_capture " );
1634  declManager->FindSound( "arcade_explode" );
1635 
1636  ResetGameStats();
1637 }
1638 
1640 
1641  ResetEntities();
1642 
1643  //Reset the gamestats structure
1644  memset(&gameStats, 0, sizeof(gameStats));
1645 
1646  gameStats.health = 100;
1647 
1648 }
1649 
1651 
1652  ResetEntities();
1653 
1654  //Reset the level statistics structure
1655  memset(&gameStats.levelStats, 0, sizeof(gameStats.levelStats));
1656 
1657 
1658 }
1659 
1661  //Destroy all of the entities
1662  for(int i = 0; i < entities.Num(); i++) {
1663  entities[i]->DestroyEntity();
1664  }
1665  entities.Clear();
1666 }
1667 
1669 
1670  gameStats.gameRunning = true;
1671 }
1672 
1674 
1675  gameStats.gameRunning = false;
1676 }
1677 
1679 
1680 
1681  StopGame();
1682 
1683  gui->HandleNamedEvent("gameOver");
1684 }
1685 
1687 
1688  ResetLevelStats();
1689 
1691 
1692  StartGame();
1693 }
1694 
1699  gameStats.health = 100;
1700 
1701  StartGame();
1702 }
1703 
1705 
1707 
1708  // Add the bonuses
1709  int accuracy;
1710  if( !gameStats.levelStats.shotCount ) {
1711  accuracy = 0;
1712  } else {
1713  accuracy = (int)( ( (float)gameStats.levelStats.hitCount / (float)gameStats.levelStats.shotCount ) * 100.0f );
1714  }
1715  int accuracyPoints = Max( 0, accuracy - 50 ) * 20;
1716 
1717  gui->SetStateString("player_accuracy_score", va("%i", accuracyPoints));
1718 
1719  gameStats.score += accuracyPoints;
1720 
1721  int saveAccuracy;
1723  if( !totalAst ) {
1724  saveAccuracy = 0;
1725  } else {
1726  saveAccuracy = (int)( ( (float)gameStats.levelStats.savedAstronauts / (float)totalAst ) * 100.0f );
1727  }
1728  accuracyPoints = Max( 0, saveAccuracy - 50 ) * 20;
1729 
1730  gui->SetStateString("save_accuracy_score", va("%i", accuracyPoints));
1731 
1732  gameStats.score += accuracyPoints;
1733 
1734 
1735 
1736  StopSuperBlaster();
1737 
1738  gameStats.nextLevel++;
1739 
1740  if(gameStats.nextLevel >= levelCount) {
1741  //Have they beaten the game
1742  GameComplete();
1743  } else {
1744 
1745  //Make sure we don't go above the levelcount
1746  //min(gameStats.nextLevel, levelCount-1);
1747 
1748  StopGame();
1749  gui->HandleNamedEvent("levelComplete");
1750  }
1751 }
1752 
1754  StopGame();
1755  gui->HandleNamedEvent("gameComplete");
1756 }
1757 
1758 
1760 
1761  //Check to see if and functions where called by the gui
1762  if(beginLevel == true) {
1763  beginLevel = false;
1765  }
1766  if(resetGame == true) {
1767  resetGame = false;
1768  ResetGameStats();
1769  }
1770  if(continueGame == true) {
1771  continueGame = false;
1772  ContinueGame();
1773  }
1774  if(refreshGuiData == true) {
1775  refreshGuiData = false;
1776  RefreshGuiData();
1777  }
1778 
1779  if(gameStats.gameRunning) {
1780 
1781  //We assume an upate every 16 milliseconds
1782  ssdTime += 16;
1783 
1785  StopSuperBlaster();
1786  }
1787 
1788  //Find if we are targeting and enemy
1789  idVec2 cursor;
1790  //GetCursor(cursor);
1791  cursor.x = gui->CursorX();
1792  cursor.y = gui->CursorY();
1794 
1795  //Update from back to front
1796  for(int i = entities.Num()-1; i >= 0; i--) {
1797  entities[i]->Update();
1798  }
1799 
1800  CheckForHits();
1801 
1802  //Delete entities that need to be deleted
1803  for(int i = entities.Num()-1; i >= 0; i--) {
1804  if(entities[i]->destroyed) {
1805  SSDEntity* ent = entities[i];
1806  ent->DestroyEntity();
1808  }
1809  }
1810 
1811  //Check if we can spawn an asteroid
1812  SpawnAsteroid();
1813 
1814  //Check if we should spawn an astronaut
1815  SpawnAstronaut();
1816 
1817  //Check if we should spawn an asteroid
1818  SpawnPowerup();
1819  }
1820 }
1821 
1823 
1824  //See if the entity has gotten close enough
1825  for(int i = 0; i < entities.Num(); i++) {
1826  SSDEntity* ent = entities[i];
1827  if(ent->position.z <= Z_NEAR) {
1828 
1829  if(!ent->noPlayerDamage) {
1830 
1831  //Is the object still in the screen
1832  idVec3 entPos = ent->position;
1833  entPos.z = 0;
1834 
1835  idBounds entBounds(entPos);
1836  entBounds.ExpandSelf(ent->hitRadius);
1837 
1838  if(screenBounds.IntersectsBounds(entBounds)) {
1839 
1840  ent->OnStrikePlayer();
1841 
1842  //The entity hit the player figure out what is was and act appropriately
1843  if(ent->type == SSD_ENTITY_ASTEROID) {
1844  AsteroidStruckPlayer(static_cast<SSDAsteroid*>(ent));
1845  } else if(ent->type == SSD_ENTITY_ASTRONAUT) {
1846  AstronautStruckPlayer(static_cast<SSDAstronaut*>(ent));
1847  }
1848  } else {
1849  //Tag for removal later in the frame
1850  ent->destroyed = true;
1851  }
1852  }
1853  }
1854  }
1855 }
1856 
1858  //Z-Order the entities
1859  //Using a simple sorting method
1860  for (int i = entities.Num()-1; i >= 0; i--) {
1861  bool flipped = false;
1862  for (int j = 0; j<i ; j++) {
1863  if (entities[j]->position.z > entities[j+1]->position.z) {
1864  SSDEntity* ent = entities[j];
1865  entities[j] = entities[j+1];
1866  entities[j+1] = ent;
1867  flipped = true;
1868  }
1869  }
1870  if (!flipped) {
1871  //Jump out because it is sorted
1872  break;
1873  }
1874  }
1875 }
1876 
1878 
1879  int currentTime = ssdTime;
1880 
1881  if(currentTime < gameStats.levelStats.nextAsteroidSpawnTime) {
1882  //Not time yet
1883  return;
1884  }
1885 
1886  //Lets spawn it
1887  idVec3 startPosition;
1888 
1889  float spawnBuffer = levelData[gameStats.currentLevel].spawnBuffer*2.0f;
1890  startPosition.x = random.RandomInt(V_WIDTH+spawnBuffer)-((V_WIDTH/2.0f)+spawnBuffer);
1891  startPosition.y = random.RandomInt(V_HEIGHT+spawnBuffer)-((V_HEIGHT/2.0f)+spawnBuffer);
1892  startPosition.z = ENTITY_START_DIST;
1893 
1897 
1898  SSDAsteroid* asteroid = SSDAsteroid::GetNewAsteroid(this, startPosition, idVec2(size, size), speed, rotate, asteroidData[gameStats.currentLevel].asteroidHealth);
1899  entities.Append(asteroid);
1900 
1902 }
1903 
1905 
1906  idVec2 cursorWorld = GetCursorWorld();
1907  idVec2 cursor;
1908  //GetCursor(cursor);
1909  cursor.x = gui->CursorX();
1910  cursor.y = gui->CursorY();
1911 
1912  if(key == K_MOUSE1) {
1913 
1915 
1917  //Aim the projectile from the bottom of the screen directly at the ent
1918  //SSDProjectile* newProj = new SSDProjectile(this, idVec3(320,0,0), gameStats.levelStats.targetEnt->position, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
1920  entities.Append(newProj);
1921  //newProj = SSDProjectile::GetNewProjectile(this, idVec3(-320,-0,0), gameStats.levelStats.targetEnt->position, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
1922  //entities.Append(newProj);
1923 
1924  //We hit something
1926 
1928 
1930  HitAsteroid(static_cast<SSDAsteroid*>(gameStats.levelStats.targetEnt), key);
1932  HitAstronaut(static_cast<SSDAstronaut*>(gameStats.levelStats.targetEnt), key);
1934 
1935  }
1936  } else {
1938  //SSDProjectile* newProj = SSDProjectile::GetNewProjectile(this, idVec3(0,-180,0), idVec3(cursorWorld.x, cursorWorld.y, (Z_FAR-Z_NEAR)/2.0f), weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
1939 
1940  //Aim the projectile so it crosses the cursor 1/4 of screen
1941  idVec3 vec = idVec3(cursorWorld.x, cursorWorld.y, (Z_FAR-Z_NEAR)/8.0f);
1942  vec *= 8;
1944  entities.Append(newProj);
1945 
1946  }
1947 
1948 
1949  //Play the blaster sound
1950  PlaySound("arcade_blaster");
1951 
1952  } /*else if (key == K_MOUSE2) {
1953  if(gameStats.levelStats.targetEnt) {
1954  if(gameStats.levelStats.targetEnt->type == SSD_ENTITY_ASTRONAUT) {
1955  HitAstronaut(static_cast<SSDAstronaut*>(gameStats.levelStats.targetEnt), key);
1956  }
1957  }
1958  }*/
1959 }
1960 
1962 
1963  for(int i = 0; i < entities.Num(); i++) {
1964  //Since we ZOrder the entities every frame we can stop at the first entity we hit.
1965  //ToDo: Make sure this assumption is true
1966  if(entities[i]->HitTest(pt)) {
1967  return entities[i];
1968  }
1969  }
1970  return NULL;
1971 }
1972 
1973 void idGameSSDWindow::HitAsteroid(SSDAsteroid* asteroid, int key) {
1974 
1975 
1976 
1977  asteroid->health -= weaponData[gameStats.currentWeapon].damage;
1978 
1979  if(asteroid->health <= 0) {
1980 
1981  //The asteroid has been destroyed
1982  SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, asteroid->position, asteroid->size*2, 300, SSDExplosion::EXPLOSION_NORMAL, asteroid);
1983  entities.Append(explosion);
1984  PlaySound("arcade_explode");
1985 
1986  AddScore(asteroid, asteroidData[gameStats.currentLevel].asteroidPoints);
1987 
1988  //Don't let the player hit it anymore because
1989  asteroid->noHit = true;
1990 
1992  //if(gameStats.levelStats.destroyedAsteroids >= levelData[gameStats.currentLevel].needToWin) {
1993  // LevelComplete();
1994  //}
1995 
1996  } else {
1997  //This was a damage hit so create a real small quick explosion
1998  SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, asteroid->position, asteroid->size/2.0f, 200, SSDExplosion::EXPLOSION_NORMAL, asteroid, false, false);
1999  entities.Append(explosion);
2000  }
2001 }
2002 
2004 
2005  asteroid->noPlayerDamage = true;
2006  asteroid->noHit = true;
2007 
2008  AddDamage(asteroidData[gameStats.currentLevel].asteroidDamage);
2009 
2010  SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, asteroid->position, asteroid->size*2, 300, SSDExplosion::EXPLOSION_NORMAL, asteroid);
2011  entities.Append(explosion);
2012  PlaySound("arcade_explode");
2013 }
2014 
2016 
2017  SSDPoints* pointsEnt;
2018 
2019  if(points > 0) {
2020  pointsEnt = SSDPoints::GetNewPoints(this, ent, points, 1000, 50, idVec4(0,1,0,1));
2021  } else {
2022  pointsEnt = SSDPoints::GetNewPoints(this, ent, points, 1000, 50, idVec4(1,0,0,1));
2023  }
2024  entities.Append(pointsEnt);
2025 
2026  gameStats.score += points;
2027  gui->SetStateString( "player_score", va("%i", gameStats.score ) );
2028 }
2029 
2030 void idGameSSDWindow::AddDamage(int damage) {
2031  gameStats.health -= damage;
2032  gui->SetStateString( "player_health", va("%i", gameStats.health ) );
2033 
2034  gui->HandleNamedEvent( "playerDamage" );
2035 
2036  if(gameStats.health <= 0) {
2037  //The player is dead
2038  GameOver();
2039  }
2040 }
2041 
2042 void idGameSSDWindow::AddHealth(int health) {
2043  gameStats.health += health;
2044  gameStats.health = Min( 100, gameStats.health );
2045 }
2046 
2047 
2049 
2050  gui->HandleNamedEvent("nuke");
2051 
2052  //Destory All Asteroids
2053  for(int i = 0 ; i < entities.Num(); i++) {
2054 
2055  if(entities[i]->type == SSD_ENTITY_ASTEROID) {
2056 
2057  //The asteroid has been destroyed
2059  entities.Append(explosion);
2060 
2061  AddScore(entities[i], asteroidData[gameStats.currentLevel].asteroidPoints);
2062 
2063  //Don't let the player hit it anymore because
2064  entities[i]->noHit = true;
2065 
2067  }
2068  }
2069  PlaySound("arcade_explode");
2070 
2071  //Check to see if a nuke ends the level
2072  /*if(gameStats.levelStats.destroyedAsteroids >= levelData[gameStats.currentLevel].needToWin) {
2073  LevelComplete();
2074 
2075  }*/
2076 }
2077 
2079 
2080  gui->HandleNamedEvent("rescueAll");
2081 
2082  //Rescue All Astronauts
2083  for(int i = 0 ; i < entities.Num(); i++) {
2084 
2085  if(entities[i]->type == SSD_ENTITY_ASTRONAUT) {
2086 
2088  }
2089  }
2090 }
2091 
2093 
2095 }
2096 
2097 
2098 
2100 
2101 
2102  gui->SetStateString("nextLevel", va("%i", gameStats.nextLevel+1));
2103  gui->SetStateString("currentLevel", va("%i", gameStats.currentLevel+1));
2104 
2105  float accuracy;
2107  accuracy = 0;
2108  } else {
2109  accuracy = ((float)gameStats.levelStats.hitCount/(float)gameStats.levelStats.shotCount)*100.0f;
2110  }
2111  gui->SetStateString( "player_accuracy", va("%d%%", (int)accuracy));
2112 
2113  float saveAccuracy;
2115 
2116  if(!totalAst) {
2117  saveAccuracy = 0;
2118  } else {
2119  saveAccuracy = ((float)gameStats.levelStats.savedAstronauts/(float)totalAst)*100.0f;
2120  }
2121  gui->SetStateString( "save_accuracy", va("%d%%", (int)saveAccuracy));
2122 
2123 
2124 
2125 
2127  int dist = (gameStats.levelStats.targetEnt->position.z/100.0f);
2128  dist *= 100;
2129  gui->SetStateString("target_info", va("%i meters", dist));
2130  } else {
2131  gui->SetStateString("target_info", "No Target");
2132  }
2133 
2134  gui->SetStateString( "player_health", va("%i", gameStats.health ) );
2135  gui->SetStateString( "player_score", va("%i", gameStats.score ) );
2136  gui->SetStateString( "player_prebonusscore", va("%i", gameStats.prebonusscore ) );
2137  gui->SetStateString( "level_complete", va("%i/%i", gameStats.levelStats.savedAstronauts, levelData[gameStats.currentLevel].needToWin ));
2138 
2139 
2140  if(superBlasterTimeout) {
2141  float timeRemaining = (superBlasterTimeout - ssdTime)/1000.0f;
2142  gui->SetStateString("super_blaster_time", va("%.2f", timeRemaining));
2143  }
2144 }
2145 
2147 
2148  idVec2 cursor;
2149  //GetCursor(cursor);
2150  cursor.x = gui->CursorX();
2151  cursor.y = gui->CursorY();
2152  cursor.x = cursor.x - 0.5f * V_WIDTH;
2153  cursor.y = -(cursor.y - 0.5f * V_HEIGHT);
2154  return cursor;
2155 }
2156 
2158 
2159  int currentTime = ssdTime;
2160 
2161  if(currentTime < gameStats.levelStats.nextAstronautSpawnTime) {
2162  //Not time yet
2163  return;
2164  }
2165 
2166  //Lets spawn it
2167  idVec3 startPosition;
2168 
2169  startPosition.x = random.RandomInt(V_WIDTH)-(V_WIDTH/2.0f);
2170  startPosition.y = random.RandomInt(V_HEIGHT)-(V_HEIGHT/2.0f);
2171  startPosition.z = ENTITY_START_DIST;
2172 
2175 
2176  SSDAstronaut* astronaut = SSDAstronaut::GetNewAstronaut(this, startPosition, speed, rotate, astronautData[gameStats.currentLevel].health);
2177  entities.Append(astronaut);
2178 
2180 }
2181 
2182 void idGameSSDWindow::HitAstronaut(SSDAstronaut* astronaut, int key) {
2183 
2184 
2185  if(key == K_MOUSE1) {
2186  astronaut->health -= weaponData[gameStats.currentWeapon].damage;
2187 
2188  if(astronaut->health <= 0) {
2189 
2191 
2192  //The astronaut has been destroyed
2193  SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, astronaut->position, astronaut->size*2, 300, SSDExplosion::EXPLOSION_NORMAL, astronaut);
2194  entities.Append(explosion);
2195  PlaySound("arcade_explode");
2196 
2197  //Add the penalty for killing the astronaut
2198  AddScore(astronaut, astronautData[gameStats.currentLevel].penalty);
2199 
2200  //Don't let the player hit it anymore
2201  astronaut->noHit = true;
2202  } else {
2203  //This was a damage hit so create a real small quick explosion
2204  SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, astronaut->position, astronaut->size/2.0f, 200, SSDExplosion::EXPLOSION_NORMAL, astronaut, false, false);
2205  entities.Append(explosion);
2206  }
2207  }
2208 }
2209 
2211 
2213 
2214  astronaut->noPlayerDamage = true;
2215  astronaut->noHit = true;
2216 
2217  //We are saving an astronaut
2218  SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, astronaut->position, astronaut->size*2, 300, SSDExplosion::EXPLOSION_TELEPORT, astronaut);
2219  entities.Append(explosion);
2220  PlaySound("arcade_capture");
2221 
2222  //Give the player points for saving the astronaut
2223  AddScore(astronaut, astronautData[gameStats.currentLevel].points);
2224 
2226  LevelComplete();
2227  }
2228 
2229 }
2230 
2232 
2233  int currentTime = ssdTime;
2234 
2235  if(currentTime < gameStats.levelStats.nextPowerupSpawnTime) {
2236  //Not time yet
2237  return;
2238  }
2239 
2242 
2243  SSDPowerup* powerup = SSDPowerup::GetNewPowerup(this, speed, rotate);
2244  entities.Append(powerup);
2245 
2247 
2248 }
2249 
2251 
2252  gui->HandleNamedEvent("startSuperBlaster");
2254  superBlasterTimeout = ssdTime + 10000;
2255 
2256 }
2258  gui->HandleNamedEvent("stopSuperBlaster");
2260  superBlasterTimeout = 0;
2261 
2262 }
2263 
2265  SSDEntity* ent = NULL;
2266  switch(type) {
2267  case SSD_ENTITY_ASTEROID:
2269  break;
2270  case SSD_ENTITY_ASTRONAUT:
2272  break;
2273  case SSD_ENTITY_EXPLOSION:
2275  break;
2276  case SSD_ENTITY_POINTS:
2277  ent = SSDPoints::GetSpecificPoints(id);
2278  break;
2279  case SSD_ENTITY_PROJECTILE:
2281  break;
2282  case SSD_ENTITY_POWERUP:
2284  break;
2285  }
2286  return ent;
2287 }
2288 
2289 #define MAX_SOUND_CHANNEL 8
2290 
2291 void idGameSSDWindow::PlaySound(const char* sound) {
2292 
2294 
2295  currentSound++;
2297  currentSound = 0;
2298  }
2299 }
int currentTime
Definition: GameSSDWindow.h:87
float crosshairWidth
Definition: GameSSDWindow.h:43
void SetPosition(const idVec3 &_position)
virtual void ReadFromSaveGame(idFile *savefile, idGameSSDWindow *_game)
GLubyte g
Definition: glext.h:4662
virtual void SetStateString(const char *varName, const char *value)
byte color[4]
Definition: MegaTexture.cpp:54
idBounds screenBounds
GLsizei const GLfloat * points
Definition: glext.h:3884
void SetMaterial(const char *_name)
SSDEntity * GetSpecificEntity(int type, int id)
virtual void WriteToSaveGame(idFile *savefile)
virtual void WriteToSaveGame(idFile *savefile)
void Init(idGameSSDWindow *_game, const idVec3 &startPosition, const idVec2 &_size, float _speed, float rotate, int _health)
float Normalize(void)
Definition: Vector.h:646
idVec4 foreColor
Definition: GameSSDWindow.h:84
virtual const idSoundShader * FindSound(const char *name, bool makeDefault=true)=0
virtual void ReadFromSaveGame(idFile *savefile, idGameSSDWindow *_game)
static SSDPoints * GetNewPoints(idGameSSDWindow *_game, SSDEntity *_ent, int _points, int _length, int _distance, const idVec4 &color)
const int VIRTUAL_WIDTH
Definition: DeviceContext.h:37
idVec3 speed
idVec3 GetCenter(void) const
Definition: Bounds.h:211
idSoundWorld * sw
Definition: Session.h:154
idVec4 colorWhite
Definition: Lib.cpp:116
static SSDAstronaut astronautPool[MAX_ASTRONAUT]
#define MAX_POINTS
const char * explosionMaterials[]
float y
Definition: Vector.h:55
void HitAstronaut(SSDAstronaut *astronaut, int key)
int lastUpdate
Definition: GameSSDWindow.h:88
ID_INLINE T Max(T x, T y)
Definition: Lib.h:158
static void WriteProjectiles(idFile *savefile)
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:4804
int Length(void) const
Definition: Str.h:702
virtual bool ParseInternalVar(const char *name, idParser *src)
Definition: Window.cpp:1915
#define PROJECTILE_MATERIAL
#define V_HEIGHT
virtual void PlayShaderDirectly(const char *name, int channel=-1)=0
GLenum GLint GLint y
Definition: glext.h:2849
idVec3 beginPosition
void Init(idGameSSDWindow *_game, SSDEntity *_ent, int _points, int _length, int _distance, const idVec4 &color)
float z
Definition: Vector.h:320
static SSDProjectile * GetNewProjectile(idGameSSDWindow *_game, const idVec3 &_beginPosition, const idVec3 &_endPosition, float _speed, float _size)
case const int
Definition: Callbacks.cpp:52
static void ReadExplosions(idFile *savefile, idGameSSDWindow *_game)
#define MAX_ASTRONAUT
idBounds WorldToScreen(const idBounds worldBounds)
#define CROSSHAIR_SUPER_MATERIAL
void ParseString(idParser *src, idStr &out)
Definition: Window.cpp:1883
static SSDPoints * GetSpecificPoints(int id)
Definition: Vector.h:316
case const float
Definition: Callbacks.cpp:62
virtual void WriteToSaveGame(idFile *savefile)
#define MAX_ASTEROIDS
SSDEntity * EntityHitTest(const idVec2 &pt)
virtual void WriteToSaveGame(idFile *savefile)
static void ReadAsteroids(idFile *savefile, idGameSSDWindow *_game)
virtual void EntityUpdate()
virtual void WriteToSaveGame(idFile *savefile)
Definition: Window.cpp:3464
SSDCrossHair crosshair
float textScale
Definition: GameSSDWindow.h:83
idWinFloat rotate
Definition: Window.h:406
idVec3 position
Definition: GameSSDWindow.h:74
int LoadMemory(const char *ptr, int length, const char *name)
Definition: Parser.cpp:3049
void BeginLevel(int level)
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
idWinBool refreshGuiData
Definition: Token.h:71
static SSDAsteroid * GetSpecificAsteroid(int id)
idVec2 size
Definition: GameSSDWindow.h:75
SSDEntity * targetEnt
virtual void ReadFromSaveGame(idFile *savefile)
idDeviceContext * dc
Definition: Window.h:425
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
GLuint src
Definition: glext.h:5390
#define MAX_PROJECTILES
virtual void WriteToSaveGame(idFile *savefile)
void OnActivatePowerup()
virtual ~SSDEntity()
float x
Definition: Vector.h:318
float rotationSpeed
#define ASTRONAUT_MATERIAL
GLenum GLint x
Definition: glext.h:2849
int i
Definition: process.py:33
static SSDPowerup * GetNewPowerup(idGameSSDWindow *_game, float _speed, float _rotation)
void PlaySound(const char *sound)
void AddHealth(int health)
void AstronautStruckPlayer(SSDAstronaut *astronaut)
int Icmp(const char *text) const
Definition: Str.h:667
const idVec2 & ToVec2(void) const
Definition: Vector.h:711
idVec4 beginColor
virtual void OnHit(int key)
virtual void WriteToSaveGame(idFile *savefile)
Definition: Winvar.h:137
#define ENTITY_START_DIST
virtual const char * HandleEvent(const sysEvent_t *event, bool *updateVisuals)
void SetSize(const idVec2 &_size)
unsigned char cursor
Definition: Window.h:393
virtual void ReadFromSaveGame(idFile *savefile, idGameSSDWindow *_game)
void DrawMaterialRotated(float x, float y, float w, float h, const idMaterial *mat, const idVec4 &color, float scalex=1.0, float scaley=1.0, float angle=0.0f)
Definition: File.h:50
#define Z_NEAR
void EntityInit()
virtual void OnHit(int key)
void SetRotation(float _rotation)
bool ParseBool(void)
Definition: Parser.cpp:2797
int RandomInt(void)
Definition: Random.h:70
void AsteroidStruckPlayer(SSDAsteroid *asteroid)
static void WriteExplosions(idFile *savefile)
GLuint GLuint GLsizei count
Definition: glext.h:2845
Definition: Vector.h:52
idVec4 endColor
virtual void Draw(int time, float x, float y)
idList< SSDEntity * > entities
virtual void ReadFromSaveGame(idFile *savefile)
int ParseInt(void)
Definition: Parser.cpp:2775
int DrawText(const char *text, float textScale, int textAlign, idVec4 color, idRectangle rectDraw, bool wrap, int cursor=-1, bool calcOnly=false, idList< int > *breaks=NULL, int limit=0)
Definition: Vector.h:808
virtual void ReadFromSaveGame(idFile *savefile, idGameSSDWindow *_game)
idStr materialName
Definition: GameSSDWindow.h:72
idGameSSDWindow(idUserInterfaceLocal *gui)
#define CROSSHAIR_STANDARD_MATERIAL
float RandomFloat(void)
Definition: Random.h:82
void Init(idGameSSDWindow *_game, const idVec3 &startPosition, float _speed, float rotate, int _health)
virtual void ReadFromSaveGame(idFile *savefile, idGameSSDWindow *_game)
SSDEntity * buddy
void Init(idGameSSDWindow *_game, float _speed, float _rotation)
static float Fabs(float f)
Definition: Math.h:779
virtual void OnStrikePlayer()
virtual void WriteToSaveGame(idFile *savefile)
void AddDamage(int damage)
#define NULL
Definition: Lib.h:88
int currentCrosshair
Definition: GameSSDWindow.h:42
idDeviceContext * GetDC(void)
Definition: Window.h:206
float y
Definition: Vector.h:319
int evValue2
Definition: sys_public.h:218
void ParseAsteroidData(int level, const idStr &asteroidDataString)
virtual float CursorY()
void ParseAstronautData(int level, const idStr &astronautDataString)
virtual void ReadFromSaveGame(idFile *savefile, idGameSSDWindow *_game)
virtual int Read(void *buffer, int len)
Definition: File.cpp:179
void ContinueGame()
Continue game resets the players health.
static int FindText(const char *str, const char *text, bool casesensitive=true, int start=0, int end=-1)
Definition: Str.cpp:207
void Init(idGameSSDWindow *_game, const idVec3 &_position, const idVec2 &_size, int _length, int _type, SSDEntity *_buddy, bool _killBuddy=true, bool _followBuddy=true)
static void ReadPoints(idFile *savefile, idGameSSDWindow *_game)
#define POWERUP_MATERIAL_COUNT
virtual void EntityUpdate()
float w
Definition: Vector.h:813
static void WritePoints(idFile *savefile)
float x
Definition: Vector.h:54
void ParseLevelData(int level, const idStr &levelDataString)
float ParseFloat(void)
Definition: Parser.cpp:2812
static void ReadAstronauts(idFile *savefile, idGameSSDWindow *_game)
#define MAX_SOUND_CHANNEL
void AddScore(SSDEntity *ent, int points)
virtual ~SSDPowerup()
virtual void EntityUpdate()
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Winvar.h:141
const char * Right(int len, idStr &result) const
Definition: Str.h:896
GLenum GLsizei width
Definition: glext.h:2846
static float Tan(float a)
Definition: Math.h:459
idStr text
Definition: GameSSDWindow.h:82
const idMaterial * crosshairMaterial[CROSSHAIR_COUNT]
Definition: GameSSDWindow.h:41
const idMaterial * material
Definition: GameSSDWindow.h:73
#define DEG2RAD(a)
Definition: Math.h:56
void ReadSaveGameString(idStr &string, idFile *savefile)
Definition: Window.cpp:3590
void WriteSaveGameString(const char *string, idFile *savefile)
Definition: Window.cpp:3404
virtual void ReadFromSaveGame(idFile *savefile, idGameSSDWindow *_game)
sysEventType_t evType
Definition: sys_public.h:216
int size
Definition: List.h:136
virtual void EntityUpdate()
static SSDPoints pointsPool[MAX_POINTS]
static SSDAsteroid * GetNewAsteroid(idGameSSDWindow *_game, const idVec3 &startPosition, const idVec2 &_size, float _speed, float rotate, int _health)
idDeclManager * declManager
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup=false, drawWin_t **owner=NULL)
const char * powerupMaterials[][2]
int CharWidth(const char c, float scale)
idVec2 finalSize
virtual void WriteToSaveGame(idFile *savefile)
static SSDExplosion explosionPool[MAX_EXPLOSIONS]
int Append(const type &obj)
Definition: List.h:646
#define MAX_EXPLOSIONS
void Init(idGameSSDWindow *_game, const idVec3 &_beginPosition, const idVec3 &_endPosition, float _speed, float _size)
static SSDAstronaut * GetNewAstronaut(idGameSSDWindow *_game, const idVec3 &startPosition, float _speed, float rotate, int _health)
idWinBool resetGame
#define EXPLOSION_MATERIAL_COUNT
void SetGame(idGameSSDWindow *_game)
#define V_WIDTH
idUserInterfaceLocal * gui
Definition: Window.h:427
GLuint id
Definition: glext.h:3103
virtual void WriteToSaveGame(idFile *savefile)
virtual ~SSDMover()
tuple f
Definition: idal.py:89
idList< SSDAstronautData_t > astronautData
void Lerp(const idVec4 &v1, const idVec4 &v2, const float l)
Definition: Vector.cpp:318
int Num(void) const
Definition: List.h:265
bool RemoveIndex(int index)
Definition: List.h:849
bool IntersectsBounds(const idBounds &a) const
Definition: Bounds.h:361
static SSDPowerup powerupPool[MAX_POWERUPS]
void ParseWeaponData(int weapon, const idStr &weaponDataString)
SSDGameStats_t gameStats
void OnOpenPowerup()
#define ASTEROID_MATERIAL
const GLcharARB * name
Definition: glext.h:3629
GLsizeiptr size
Definition: glext.h:3112
idWinBool beginLevel
idWinBool continueGame
virtual int Write(const void *buffer, int len)
Definition: File.cpp:189
static SSDExplosion * GetSpecificExplosion(int id)
Definition: Str.h:116
static SSDAstronaut * GetSpecificAstronaut(int id)
void SetRadius(float _radius, float _hitFactor=1.0f)
GLsizei const GLcharARB const GLint * length
Definition: glext.h:3599
float hitRadius
Definition: GameSSDWindow.h:77
float radius
Definition: GameSSDWindow.h:76
void FireWeapon(int key)
const char * c_str(void) const
Definition: Str.h:487
idVec3 endPosition
idList< SSDWeaponData_t > weaponData
static SSDAsteroid asteroidPool[MAX_ASTEROIDS]
void SetSort(float s) const
Definition: Material.h:513
void HitAsteroid(SSDAsteroid *asteroid, int key)
idGameSSDWindow * game
Definition: GameSSDWindow.h:86
bool HitTest(const idVec2 &pt)
static void WritePowerups(idFile *savefile)
void Draw(idDeviceContext *dc, const idVec2 &cursor)
#define Z_FAR
void MoverInit(const idVec3 &_speed, float _rotationSpeed)
GLint j
Definition: qgl.h:264
idBounds & ExpandSelf(const float d)
Definition: Bounds.h:322
void Lerp(const idVec3 &v1, const idVec3 &v2, const float l)
Definition: Vector.cpp:232
GLint level
Definition: glext.h:2878
static SSDExplosion * GetNewExplosion(idGameSSDWindow *_game, const idVec3 &_position, const idVec2 &_size, int _length, int _type, SSDEntity *_buddy, bool _killBuddy=true, bool _followBuddy=true)
idSession * session
Definition: Session.cpp:48
char * va(const char *fmt,...)
Definition: Str.cpp:1568
virtual const char * HandleEvent(const sysEvent_t *event, bool *updateVisuals)
Definition: Window.cpp:709
virtual void DestroyEntity()
virtual void Draw(idDeviceContext *dc)
virtual void HandleNamedEvent(const char *namedEvent)
virtual void ReadFromSaveGame(idFile *savefile, idGameSSDWindow *_game)
virtual void EntityUpdate()
float crosshairHeight
Definition: GameSSDWindow.h:43
static void WriteAsteroids(idFile *savefile)
virtual bool ParseInternalVar(const char *name, idParser *src)
idVec3 ScreenToWorld(const idVec3 &screenPos)
static void ReadPowerups(idFile *savefile, idGameSSDWindow *_game)
static SSDProjectile * GetSpecificProjectile(int id)
virtual void WriteToSaveGame(idFile *savefile)
void DrawMaterial(float x, float y, float w, float h, const idMaterial *mat, const idVec4 &color, float scalex=1.0, float scaley=1.0)
idVec4 matColor
Definition: GameSSDWindow.h:80
void Zero(void)
Definition: Vector.h:415
idList< SSDPowerupData_t > powerupData
virtual void EntityUpdate()
void Set(const float x, const float y, const float z, const float w)
Definition: Vector.h:873
ID_INLINE T Min(T x, T y)
Definition: Lib.h:159
virtual float CursorX()
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup=false, drawWin_t **owner=NULL)
Definition: Window.cpp:1776
void InitCrosshairs()
SSDGameStats_t Data that is used for the game that is currently running.
idList< SSDLevelData_t > levelData
static SSDProjectile projectilePool[MAX_PROJECTILES]
void ParsePowerupData(int level, const idStr &powerupDataString)
float rotation
Definition: GameSSDWindow.h:78
Powerups work in two phases: 1.) Closed container hurls at you If you shoot the container it open 3...
SSDLevelStats_t levelStats
float LengthSqr(void) const
Definition: Vector.h:166
bool noPlayerDamage
Definition: GameSSDWindow.h:93
idVec3 endPosition
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Window.cpp:3607
static void ReadProjectiles(idFile *savefile, idGameSSDWindow *_game)
bool destroyed
Definition: GameSSDWindow.h:91
virtual void OnStrikePlayer()
static void WriteAstronauts(idFile *savefile)
GLdouble GLdouble t
Definition: glext.h:2943
void Clear(void)
Definition: List.h:184
virtual void WriteToSaveGame(idFile *savefile)
static idRandom random
static SSDPowerup * GetSpecificPowerup(int id)
const int VIRTUAL_HEIGHT
Definition: DeviceContext.h:38
idList< SSDAsteroidData_t > asteroidData