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 <d3d9.h>
  11. #include <d3dx9.h>
  12. #include <d3dx9math.h>
  13. #include <dxerr9.h>
  14. #include <dsound.h>
  15. #include <dinput.h>
  16. #include <windows.h>
  17. #include <time.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #include <string>
  22. #include <iostream>
  23. #include <fstream>
  24. #include <assert.h>
  25. using namespace std;
  26.  
  27. //framework-specific headers
  28.  
  29. #include "dxaudio.h"
  30. #include "dxinput.h"
  31. #include "dxgraphics.h"
  32. #include "csprite.h"
  33.  
  34.  
  35. /* ------ DEFINE(s) ------ */
  36.  
  37. //application title
  38. #define APPTITLE "Little RPG"
  39.  
  40. #define DEBUG_ON false
  41.  
  42. //screen setup
  43. #define FULLSCREEN 0       //0 = windowed, 1 = fullscreen
  44. #define SCREEN_WIDTH  1024
  45. #define SCREEN_HEIGHT 768
  46.  
  47. // tile info
  48. #define TILEWIDTH  64
  49. #define TILEHEIGHT 64      
  50. #define BACK_PER_ROW 4  // number of brackground tiles per row
  51.  
  52. // map
  53. #define MAPWIDTH   16 // 1024 / 64 = 16
  54. #define MAPHEIGHT  45 //  768 / 16 = 48
  55. #define GAMEWORLDWIDTH  (TILEWIDTH * MAPWIDTH)
  56. #define GAMEWORLDHEIGHT (TILEHEIGHT * MAPHEIGHT)
  57.  
  58. // over images in file "bushes.bmp"
  59. #define NUM_OVERLAYS 82
  60. #define MAX_OVERLAYS 50
  61.  
  62. // respawn delay for monsters
  63. #define DEATH_DELAY 300
  64.  
  65. // scrolling window size
  66. #define WINDOWWIDTH  (SCREEN_WIDTH / TILEWIDTH)   * TILEWIDTH
  67. #define WINDOWHEIGHT (SCREEN_HEIGHT / TILEHEIGHT) * TILEHEIGHT
  68.  
  69. // spell casting
  70. #define MANA_FIRE 20
  71. #define MANA_HEAL 10
  72. #define MANA_DELAY 50
  73.  
  74. typedef enum
  75. {
  76.     SPELL_NONE  =   0,
  77.     SPELL_FIRE  =   1,
  78.     SPELL_HEAL  =   2
  79. }  SPELLS;
  80.  
  81. /* ------ Structures ------ */
  82.  
  83. // used for the overlay tiles
  84. struct OverlayType
  85. {
  86.  int x, y; // tile xy
  87.  int tile;
  88.  RECT r1;  // collision rect
  89. };
  90.  
  91. /* ------ function prototypes ------ */
  92.  
  93.  int Game_Init(HWND);
  94. void Game_Run(HWND);
  95. void Game_End(HWND);
  96.  
  97. // dynamic scrolling map support functions
  98. void DrawSprite(LPDIRECT3DTEXTURE9, int,int,int,int, int, int);
  99. void DrawTilesBack();
  100. void DrawSprites();
  101.  
  102. // test for collisions
  103. bool rectCollision(RECT r1, RECT r2);
  104. bool collisionOverlays(RECT dest_rhombus);
  105.  int getOverlayCollided(RECT dest_rhombus);
  106.  
  107. // draw numbers to screen
  108. void drawNumbers(int number, int screenX, int screenY);
  109.  
  110. // MATH
  111. float findDistance(POINT pt1,POINT pt2);
  112.  
  113. // convert from tile xy to screen xy
  114. POINT tile_to_world(int tilex, int tiley);
  115.  
  116. // roll dice
  117. int rollDice(int , int);
  118.  
  119. // draws the game menus
  120. void drawMenu();
  121.  
  122. // determine which direction to turn to face target
  123. DIRS getDirection(POINT sourcePT, POINT targetPT);
  124.  
  125. //returns screen coordinates for a given x,y tile location
  126. POINT tile_to_world(int tilex, int tiley);
  127.  
  128. // returns tileXY where center of rhombus is at (roughly)
  129. POINT sprite_to_tile(RECT rhombus);
  130.  
  131. #endif