1.  
  2. #ifndef GAME_H
  3. #define GAME_H
  4.  
  5. #include "CPInit.h"
  6.  
  7. // standard libraries
  8. #include <time.h>
  9. #include <math.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <iostream>
  13. #include <fstream>
  14. #include <string>
  15. #include <cstring>
  16. #include <sstream>
  17.  
  18. using namespace std;
  19.  
  20. #ifndef USE_SDL
  21.  //windows/directx headers
  22.   #include <windows.h>
  23.  #include <dinput.h>
  24.  #include "dxinput.h"
  25. #else
  26.  // define HWND class for SDL
  27.   typedef unsigned short int HWND; // 4 bytes
  28. #endif
  29.  
  30. // cross-plat library headers
  31. #include "SDL/SDL.h"
  32. #include "SDL/SDL_image.h"
  33. #include "SDL/SDL_mixer.h"
  34. #ifdef USE_SDL
  35.     #include "SDL/SDL_ttf.h"
  36. #endif
  37.  
  38. // cross-plat interface headers
  39. #include "CPGraphics.h"
  40. #include "CPInput.h"
  41. #include "CPSound.h"
  42. #include "CPTimer.h"
  43.  
  44. // game headers
  45. #include "csprite.h"
  46. #include "cship.h"
  47. #include "cguns.h"
  48. #include "cdebris.h"
  49.  
  50. // for debug output
  51. #include "debug.h"
  52.  
  53. //application title
  54. #define APPTITLE "BugHunt 2942AD"
  55.  
  56. //screen setup
  57. static int FULLSCREEN      = 0;     //0 = windowed, 1 = fullscreen
  58. static int SCREEN_WIDTH    = 1024;  //1280 // 1024 // 800
  59. static int SCREEN_HEIGHT   = 768;   // 960 // 768  // 600
  60. #define FRAMES_PER_SECOND 30 // desired FPS cap
  61.  
  62. #define TILEWIDTH  64
  63. #define TILEHEIGHT 64
  64. #define MAPWIDTH   32 //24 //16
  65. #define MAPHEIGHT  32 //64 //96
  66. #define GAMEWORLDWIDTH  2048 //(TILEWIDTH * MAPWIDTH)
  67. #define GAMEWORLDHEIGHT 2048 // (TILEHEIGHT * MAPHEIGHT)
  68.  
  69. // scrolling window size
  70. #define WINDOWWIDTH  (SCREEN_WIDTH / TILEWIDTH)   * TILEWIDTH
  71. #define WINDOWHEIGHT (SCREEN_HEIGHT / TILEHEIGHT) * TILEHEIGHT
  72.  
  73. // scroll buffer size
  74. #define SCROLLBUFFERWIDTH  (SCREEN_WIDTH + TILEWIDTH   * 2)
  75. #define SCROLLBUFFERHEIGHT (SCREEN_HEIGHT + TILEHEIGHT * 2)
  76.  
  77. // colors
  78.   const CPCOLOR CP_RED   = CPCOLOR_ARGB( 255, 255, 120, 120 ); // R
  79.   const CPCOLOR CP_GREEN = CPCOLOR_ARGB( 255, 120, 255, 120 ); // G
  80.   const CPCOLOR CP_BLUE  = CPCOLOR_ARGB( 255, 120, 120, 255 ); // B
  81.   const CPCOLOR CP_WHITE = CPCOLOR_ARGB( 255, 225, 225, 225 ); // WHITE-ISH
  82.  
  83. // player SHIP stats
  84. static int START_energy    = 30;
  85. static int START_eRecharge = 25; // ticks per delay to recharge
  86. static int START_Shields   = 3;
  87. static int START_Armor     = 2;
  88. static int START_Hull      = 1;
  89. static int START_shield_regen_delay  = 50;
  90.  
  91. // DRONE stats
  92. static int DRONE_maxSpd    = 1 + rand()% 4;                // 1 - 4
  93. static int DRONE_curSpd    = DRONE_maxSpd;
  94. static int DRONE_energy    = 15;
  95. static int DRONE_eRecharge = 30;  // ticks per delay to recharge
  96. static int DRONE_Shields   = 0;
  97. static int DRONE_Armor     = rand()%3 + 1; // 1-3
  98. static int DRONE_Hull      = rand()%2 + 1; // 1-2
  99. // BOSS stats
  100. static int BOSS_ARMOR      = 8;  //(-1) per life lost, for max (-7) = 1
  101. static int BOSS_HULL       = 10; //(-1) per life lost, for max (-7) = 3
  102.  
  103. const int MAX_TOKENS = 99;
  104.  
  105. // functions to read tokens from config file
  106. bool isLetter(int charValue);
  107. bool isNumber(int charValue);
  108. int getToken(string token);
  109. void setToken(string token, string value);
  110. bool load_Config(string filename);
  111.  
  112. // function to auto change views when collide with planets
  113. void changeView(int docked_planet);
  114.  
  115. //function prototypes
  116.   int Game_Init(HWND);
  117.  void Game_Run(HWND);
  118.  void Game_End(HWND);
  119.  
  120. // dynamic scrolling map support functions
  121. void UpdateScrollPosition();
  122.  
  123. void loadMaps();        // loads the static and moving object maps
  124.  
  125. void DrawSprites();
  126.  
  127. void Check_Keys();
  128.  
  129. DIRS getDirection(CPPOINT sourcePT, CPPOINT targetPT);      // determine which direction to turn to face target
  130. float findDistance(CPPOINT pt1,CPPOINT pt2);                // returns distance in pixels
  131. bool min_max(int num, int min,int max);                 // returns t/f is given # is with the range
  132.  
  133. void drawNumbers(int number, int screenX, int screenY, CPCOLOR color = CP_GREEN);
  134. void drawText(char* outText, int screenX, int screenY, CPCOLOR color);
  135. void drawBar(int x, int y,int curr,int max, int color); // draw bar at location; using current, max # and color
  136. void drawBars();                                        // wrapper to draw player / enemy health bars
  137.  
  138. int SpriteCollision(CSprite *sprite1, CSprite *sprite2);// test for collisions
  139. bool rectCollision(CPRECT r1, CPRECT r2);                  
  140. bool circleCollision(CPPOINT a,int radius1, CPPOINT b, int radius2);
  141.  
  142. void createDebris();        // randomly creates the initial Debris for SPACE/SYSTEM/PLANET views
  143. void respawnDebris();       // checks if debris leaves game space and spawns new debris
  144. void drawPlanets();     // non-moving objects
  145. void drawDebris();      // random moving objects
  146. void moveDebris();
  147. void checkDebris();     // player vs debris collision testing and results of impact
  148.  
  149. int planetCollision( CSprite *target ); // returns # of junk sprite collided with and reverses movement, if collided
  150. int debrisCollision( CSprite *target ); // updated xy velocity after impact of 2 objects
  151. void collision2Ds(double m1, double m2,
  152.                  double x1, double y1, double x2, double y2);
  153.  
  154. int getScrollX(int x);
  155. int getScrollY(int y);
  156.  
  157. void Init_Guns();               // setup the guns and ammo (for all SHIPS)
  158. void moveBullets();             // moves the active bullets
  159. void drawBullets();             // draws the bullet sprites
  160. void bulletCollision(CShip *target);
  161. void bullet_AI_Collision(CShip *target);
  162.  
  163. void createDrones();                // assigns the initial values to enemy ships
  164. void respawnDrones(int );
  165. void EnemyAI();                 // makes AI choices/state changes
  166. void BossAI();
  167. void respawnBoss(bool randLoc);
  168.  
  169. void DrawBG(CPTexture& pSource);
  170.  
  171. CPPOINT offsetPT(CPPOINT pt1, int Width, int Height,DIRS Facing);
  172.  
  173. // handle the explosions
  174. void newExp(CPPOINT dest);
  175. void animExp();
  176. void drawExp();
  177.  
  178. typedef enum
  179. {
  180.     SPACE  = 1,
  181.     SYSTEM = 2,
  182.     PLANET = 3
  183. } GAME_STATE;
  184.  
  185. void respawnPlayer();
  186.  
  187. #endif