1. // Beginning Game Programming, 2nd Edition
  2. // Chapter 8
  3. // Tiled_Sprite program header file
  4.  
  5.  
  6. #ifndef GAME_H
  7. #define GAME_H
  8.  
  9. //windows/directx headers
  10. #include <d3dx9math.h>
  11. #include <dxerr9.h>
  12. #include <dinput.h>
  13. #include <windows.h>
  14. #include <time.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include "libwmp3.h"
  18.  
  19. #include <iostream>
  20. #include <fstream>
  21.  
  22. using namespace std;
  23.  
  24. //framework-specific headers
  25. #include "dxgraphics.h"
  26. #include "dxinput.h"
  27.  
  28. #include "csprite.h"
  29. #include "cship.h"
  30. #include "cguns.h"
  31. #include "cdebris.h"
  32.  
  33. //application title
  34. #define APPTITLE "2942"
  35.  
  36. //screen setup // GLOBALS //
  37. #define FULLSCREEN    1     //0 = windowed, 1 = fullscreen
  38. #define SCREEN_WIDTH  1680 // 1024  //1280 // 1024 // 800
  39. #define SCREEN_HEIGHT 1050 // 768   // 960 // 768  // 600
  40.  
  41. #define TILEWIDTH  64
  42. #define TILEHEIGHT 64
  43. #define MAPWIDTH   32 //24 //16
  44. #define MAPHEIGHT  32 //64 //96
  45. #define GAMEWORLDWIDTH  2048 //(TILEWIDTH * MAPWIDTH)
  46. #define GAMEWORLDHEIGHT 2048 // (TILEHEIGHT * MAPHEIGHT)
  47.  
  48. // scrolling window size
  49. #define WINDOWWIDTH  (SCREEN_WIDTH / TILEWIDTH)   * TILEWIDTH
  50. #define WINDOWHEIGHT (SCREEN_HEIGHT / TILEHEIGHT) * TILEHEIGHT
  51.  
  52. // scroll buffer size
  53. #define SCROLLBUFFERWIDTH  (SCREEN_WIDTH + TILEWIDTH   * 2)
  54. #define SCROLLBUFFERHEIGHT (SCREEN_HEIGHT + TILEHEIGHT * 2)
  55.  
  56. //function prototypes
  57.  int Game_Init(HWND);
  58. void Game_Run(HWND);
  59. void Game_End(HWND);
  60.  
  61. // dynamic scrolling map support functions
  62. void DrawTile(LPDIRECT3DSURFACE9, int,int,int,int, LPDIRECT3DSURFACE9, int, int);
  63. void DrawTiles();
  64. void DrawScrollWindow();
  65. void UpdateScrollPosition();
  66. void loadMaps();        // loads the static and moving object maps
  67.  
  68. void DrawSprite(float x, float y, int width, int height, float sx, float sy, float angle, unsigned char alpha, LPDIRECT3DTEXTURE9 sprite, RECT *rc, IDirect3DDevice9* pd3dDevice, bool FixAngle);
  69.  
  70. void DrawSprites();
  71.  
  72. void Check_Keys();
  73.  
  74.  DIRS getDirection(POINT sourcePT, POINT targetPT);     // determine which direction to turn to face target
  75. float findDistance(POINT pt1,POINT pt2);                // returns distance in pixels
  76. bool min_max(int num, int min,int max);                 // returns t/f is given # is with the range
  77.  
  78. void drawNumbers(int number, int screenX, int screenY);
  79. void drawText(LPCSTR outText, int screenX, int screenY);
  80. void drawBar(int x, int y,int curr,int max, int color); // draw bar at location; using current, max # and color
  81. void drawBars();                                        // wrapper to draw player / enemy health bars
  82.  
  83.  int SpriteCollision(CSprite *sprite1, CSprite *sprite2);// test for collisions
  84. bool rectCollision(RECT r1, RECT r2);                  
  85. bool circleCollision(POINT a,int radius1, POINT b, int radius2);
  86.  
  87. void createDebris();                                    // randomly creates the initial Debris for SPACE/SYSTEM/PLANET views
  88. void respawnDebris();                                   // checks if debris leaves game space and spawns new debris
  89. void drawPlanets();                                     // non-moving objects
  90. void drawDebris();                                      // random moving objects
  91. void moveDebris();
  92. void checkDebris();                                     // player vs debris collision testing and results of impact
  93.  
  94. int planetCollision(CSprite *target);                   // returns # of junk sprite collided with and reverses movement, if collided
  95. int debrisCollision( CSprite *target);                  // updated xy velocity after impact of 2 objects
  96. void collision2Ds(double m1, double m2,
  97.                  double x1, double y1, double x2, double y2);
  98.  
  99. int getScrollX(int x);
  100. int getScrollY(int y);
  101.  
  102. void Init_Guns();                                       // setup the guns and ammo (for all SHIPS)
  103. void moveBullets();                                     // moves the active bullets
  104. void drawBullets();                                     // draws the bullet sprites
  105. void bulletCollision(CShip *target);
  106. void bullet_AI_Collision(CShip *target);
  107.  
  108. void createDrones();                                    // assigns the initial values to enemy ships
  109. void respawnDrones(int );
  110. void EnemyAI();                                         // makes AI choices/state changes
  111. void BossAI();
  112. void respawnBoss();
  113.  
  114. void DrawBG(IDirect3DSurface9  *pSource);
  115.  
  116.  
  117. POINT offsetPT(POINT pt1, int Width, int Height,DIRS Facing);
  118.  
  119. // handle the explosions
  120. void newExp(POINT dest);
  121. void animExp();
  122. void drawExp();
  123.  
  124. typedef enum
  125. {
  126.     Splash1,
  127.     Splash2,
  128.     Splash3,
  129.     Menu,
  130.     Options,
  131.     RunGame
  132. } MENU_STATE;
  133.  
  134. typedef enum
  135. {
  136.     SPACE  = 1,
  137.     SYSTEM = 2,
  138.     PLANET = 3
  139. } GAME_STATE;
  140.  
  141. #endif
  142.