MasterX.h
Upload User: hnktjx
Upload Date: 2009-12-18
Package Size: 39k
Code Size: 5k
Category:

Game Program

Development Platform:

C/C++

  1. /* MasterX System Devlopment Kit (SDK)
  2. DirectX API Encapsulation For easy game programming.
  3. Written by Jared Bruni
  4. Age 17 Years Old.
  5. Email Me: MasterOnLSD@lostsidedead.com 
  6. www.lostsidedead.com
  7.   for MasterX SDK documentation check out
  8.   www.lostsidedead.com/gameprog/
  9.   I LOVE VIDEO GAMES!! :) THEY ROCK
  10.   note required librarys within your project link settings
  11.   dxguid.lib dddraw.lib dsound.lib dinput.lib
  12. */
  13. #include <ddraw.h>
  14. #include <windows.h>
  15. #include <mmsystem.h>
  16. #include <dsound.h>
  17. #include <dinput.h>
  18. // for register based calling convention rather then stack based (speed)
  19. #define FAST __fastcall
  20. // for std based calling convention
  21. #define XSTD __stdcall 
  22. #define MXENTRY __stdcall
  23. // for pascal based calling convention
  24. #define XPAS __pascal
  25. // Helper typedef's so you dont gotta use evil MS stuff
  26. typedef int MASTERSCREEN;
  27. typedef int MASTERMSG;
  28. typedef long MXRESULT;
  29. typedef unsigned long WindowHandle;
  30. enum DisplayColor { COLOR_8, COLOR_16,COLOR_24,COLOR_32,COLOR_DEFAULT };
  31. struct MasterScreen
  32. {
  33. LPDIRECTDRAW lpDD;
  34. LPDIRECTDRAWSURFACE lpBack;
  35. LPDIRECTDRAWSURFACE lpFront;
  36. ~MasterScreen();
  37. };
  38. class MasterText
  39. {
  40. public:
  41. MasterScreen*  scr;
  42. HFONT font;
  43. HFONT underfont;
  44. COLORREF bk;
  45. COLORREF text;
  46. void init(MasterScreen*);
  47. void setfont(HFONT);
  48. void setunderfont(HFONT);
  49. void setbkcolor(COLORREF);
  50. void settextcolor(COLORREF);
  51. void FAST printtext(char*,int x,int y);
  52. void FAST printtextunderline(char*, int x, int y);
  53. void FAST printtextrect(char*, int x, int y, int w, int h);
  54. void setdefaultfont();
  55. };
  56. typedef class MasterGraphic
  57. {
  58. MasterScreen* scr;
  59. LPDIRECTDRAWSURFACE surf;
  60. char  filename[50];
  61. bool ckey;
  62. public:
  63. int w;
  64. int h;
  65. void init(MasterScreen* scr);
  66. bool LoadGraphic(char* filename);
  67. bool LoadGraphic(char* filename,MasterScreen* scr);
  68. void ReLoadGraphic();
  69. void SetColorKey(COLORREF r);
  70. void DisplayGraphic(int x, int y);
  71. ~MasterGraphic();
  72. MasterGraphic();
  73. void Release();
  74. }MasterSprite;
  75. class MasterSound
  76. {
  77. public:
  78. IDirectSoundBuffer *pSound;
  79. bool LoadSound(IDirectSound* pds,LPCTSTR name);
  80. void Play();
  81. bool PlayStatus();
  82. void Release();
  83. MasterSound();
  84. ~MasterSound();
  85. };
  86. // Painting Functions
  87. class MasterPaint
  88. {
  89. MasterScreen* scr;
  90. public:
  91. void init(MasterScreen* xscr);
  92. void FAST mxdrawrect(int x, int y, int x2, int y2,COLORREF fill,COLORREF outline);
  93. void FAST mxdrawroundrect(int x, int y, int x2, int y2,int cw, int ch, COLORREF fill,COLORREF outline);
  94. void FAST mxdrawpie(int x, int y, int x2, int y2, int nx, int ny, int nx2, int ny2,COLORREF fill, COLORREF outline);
  95. void FAST mxdrawchord(int x, int y, int x2, int y2, int nx, int ny, int nx2, int ny2, COLORREF fill, COLORREF outline);
  96. void FAST mxdrawellipse(int x, int y, int x2, int y2,COLORREF fill,COLORREF outline);
  97. };
  98. class MasterXHWND
  99. {
  100. MASTERSCREEN mscr;
  101. void Destroy();
  102.     DDBLTFX ddbltfx;
  103. bool setprimarysurface();
  104. bool initSound();
  105. void initInput();
  106. public:
  107. HWND hwnd;
  108. MasterScreen scr;
  109. MasterText   text;
  110. MasterPaint  paint;
  111. bool alive;
  112. UINT activeapp;
  113. IDirectInput *pDI;
  114.     IDirectInputDevice *pKeyboard;
  115.     IDirectSound *pDS;
  116. void (* update) (MASTERSCREEN xscr);
  117. bool CreateMasterX(char* mytitle,int width,int height,DisplayColor color,WNDPROC proc,HINSTANCE hInst,HICON icon,HCURSOR cursor);
  118. WPARAM InitLoop( void (* update) (MASTERSCREEN xscr));
  119. void Kill();
  120. MASTERSCREEN  GetScreen();
  121. void SetScreen(MASTERSCREEN xmscr);
  122. LRESULT SendMasterMessage(UINT msg,WPARAM wParam,LPARAM lParam);
  123. void clear();
  124. void mx_update();
  125. bool LoadGraphic(MasterGraphic* g, char* filename);
  126. bool LoadSound(MasterSound* s,LPCSTR resourceID);
  127.     bool KeyCheck(int key);
  128. bool AsyncKeyCheck(int key);
  129. };
  130. //******************************** DirectDraw/DirectSound Helper Functions.. from ddutil
  131. IDirectDrawSurface* DDLoadBitmap(IDirectDraw* pdd, LPCSTR szBitmap);
  132. IDirectDrawSurface* CreateOffScreenSurface(IDirectDraw* pdd, int dx, int dy); // Creating the Surface
  133. HRESULT DDCopyBitmap(IDirectDrawSurface* pdds, HBITMAP hbm, int dx, int dy); // Copy Bitmap
  134. ///////////////////////////////////////////////////////////////////////////////
  135. IDirectSoundBuffer *DSLoadSoundBuffer(IDirectSound *pDS, LPCTSTR lpName);
  136. BOOL DSReloadSoundBuffer(IDirectSoundBuffer *pDSB, LPCTSTR lpName);
  137. BOOL DSGetWaveResource(HMODULE hModule, LPCTSTR lpName,
  138.    WAVEFORMATEX **ppWaveHeader, BYTE **ppbWaveData, DWORD *pdwWaveSize);
  139. BOOL DSFillSoundBuffer(IDirectSoundBuffer *pDSB, BYTE *pbWaveData, DWORD dwWaveSize);
  140. BOOL DSParseWaveResource(void *pvRes, WAVEFORMATEX **ppWaveHeader, BYTE **ppbWaveData, 
  141.  DWORD *pdwWaveSize);
  142. HRESULT
  143. DDSetColorKey(IDirectDrawSurface * pdds, COLORREF rgb);
  144. DWORD
  145. DDColorMatch(IDirectDrawSurface * pdds, COLORREF rgb);
  146. HRESULT
  147. DDCopyBitmap2(IDirectDrawSurface * pdds, HBITMAP hbm, int x, int y,
  148.   int dx, int dy);
  149. HRESULT
  150. DDReLoadBitmap(IDirectDrawSurface * pdds, LPCSTR szBitmap);
  151. int APIENTRY MasterMain(HINSTANCE hInst,LPSTR line);
  152. struct mxbitmap
  153. {
  154. int w;
  155. int h;
  156. IDirectDrawSurface* surf;
  157. };
  158. static int MXWIDTH;
  159. static int MXHEIGHT;