t3dconsolealpha1.cpp
上传用户:husern
上传日期:2018-01-20
资源大小:42486k
文件大小:6k
源码类别:

游戏

开发平台:

Visual C++

  1. // T3DCONSOLEALPHA1.CPP - First alpha iteration of game console
  2. // INCLUDES ///////////////////////////////////////////////
  3. #define WIN32_LEAN_AND_MEAN  
  4. #include <windows.h>   // include important windows stuff
  5. #include <windowsx.h> 
  6. #include <mmsystem.h>
  7. #include <iostream.h> // include important C/C++ stuff
  8. #include <conio.h>
  9. #include <stdlib.h>
  10. #include <malloc.h>
  11. #include <memory.h>
  12. #include <string.h>
  13. #include <stdarg.h>
  14. #include <stdio.h> 
  15. #include <math.h>
  16. #include <io.h>
  17. #include <fcntl.h>
  18. // DEFINES ////////////////////////////////////////////////
  19. // defines for windows interface
  20. #define WINDOW_CLASS_NAME "WIN3DCLASS"  // class name
  21. #define WINDOW_TITLE      "T3D Graphics Console Alpha 1.0"
  22. #define WINDOW_WIDTH      320  // size of window
  23. #define WINDOW_HEIGHT     240
  24. // these read the keyboard asynchronously
  25. #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
  26. #define KEY_UP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
  27. // PROTOTYPES /////////////////////////////////////////////
  28. // game console
  29. int Game_Init(void *parms=NULL);
  30. int Game_Shutdown(void *parms=NULL);
  31. int Game_Main(void *parms=NULL);
  32. // GLOBALS ////////////////////////////////////////////////
  33. HWND main_window_handle           = NULL; // save the window handle
  34. HINSTANCE main_instance           = NULL; // save the instance
  35. char buffer[256];                          // used to print text
  36. // FUNCTIONS //////////////////////////////////////////////
  37. LRESULT CALLBACK WindowProc(HWND hwnd, 
  38.     UINT msg, 
  39.                             WPARAM wparam, 
  40.                             LPARAM lparam)
  41. {
  42. // this is the main message handler of the system
  43. PAINTSTRUCT ps;    // used in WM_PAINT
  44. HDC hdc;    // handle to a device context
  45. // what is the message 
  46. switch(msg)
  47. {
  48. case WM_CREATE: 
  49.         {
  50. // do initialization stuff here
  51. return(0);
  52. } break;
  53.     case WM_PAINT:
  54.          {
  55.          // start painting
  56.          hdc = BeginPaint(hwnd,&ps);
  57.          // end painting
  58.          EndPaint(hwnd,&ps);
  59.          return(0);
  60.         } break;
  61. case WM_DESTROY: 
  62. {
  63. // kill the application
  64. PostQuitMessage(0);
  65. return(0);
  66. } break;
  67. default:break;
  68.     } // end switch
  69. // process any messages that we didn't take care of 
  70. return (DefWindowProc(hwnd, msg, wparam, lparam));
  71. } // end WinProc
  72. // WINMAIN ////////////////////////////////////////////////
  73. int WINAPI WinMain( HINSTANCE hinstance,
  74. HINSTANCE hprevinstance,
  75. LPSTR lpcmdline,
  76. int ncmdshow)
  77. {
  78. // this is the winmain function
  79. WNDCLASS winclass; // this will hold the class we create
  80. HWND  hwnd; // generic window handle
  81. MSG      msg; // generic message
  82. HDC      hdc;       // generic dc
  83. PAINTSTRUCT ps;     // generic paintstruct
  84. // first fill in the window class stucture
  85. winclass.style = CS_DBLCLKS | CS_OWNDC | 
  86.                       CS_HREDRAW | CS_VREDRAW;
  87. winclass.lpfnWndProc    = WindowProc;
  88. winclass.cbClsExtra     = 0;
  89. winclass.cbWndExtra     = 0;
  90. winclass.hInstance     = hinstance;
  91. winclass.hIcon     = LoadIcon(NULL, IDI_APPLICATION);
  92. winclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  93. winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  94. winclass.lpszMenuName = NULL; 
  95. winclass.lpszClassName = WINDOW_CLASS_NAME;
  96. // register the window class
  97. if (!RegisterClass(&winclass))
  98. return(0);
  99. // create the window, note the test to see if WINDOWED_APP is
  100. // true to select the appropriate window flags
  101. if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
  102.   WINDOW_TITLE,  // title
  103.               WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION,
  104.     0,0,    // x,y
  105.   WINDOW_WIDTH,  // width
  106.               WINDOW_HEIGHT, // height
  107.   NULL,    // handle to parent 
  108.   NULL,    // handle to menu
  109.   hinstance,// instance
  110.   NULL))) // creation parms
  111. return(0);
  112. // save the window handle and instance in a global
  113. main_window_handle = hwnd;
  114. main_instance      = hinstance;
  115. // make sure window is visible
  116. ShowWindow(main_window_handle, SW_SHOW);
  117. // perform all game console specific initialization
  118. Game_Init();
  119. // enter main event loop
  120. while(1)
  121. {
  122. if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  123.    { 
  124.    // test if this is a quit
  125.        if (msg.message == WM_QUIT)
  126.            break;
  127.    // translate any accelerator keys
  128.    TranslateMessage(&msg);
  129.    // send the message to the window proc
  130.    DispatchMessage(&msg);
  131.        } // end if
  132.     
  133.        // main game processing goes here
  134.     Game_Main();
  135.     } // end while
  136. // shutdown game and release all resources
  137. Game_Shutdown();
  138. // return to Windows like this
  139. return(msg.wParam);
  140. } // end WinMain
  141. // T3D II GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////
  142. int Game_Init(void *parms)
  143. {
  144. // this function is where you do all the initialization 
  145. // for your game
  146. // return success
  147. return(1);
  148. } // end Game_Init
  149. ///////////////////////////////////////////////////////////
  150. int Game_Shutdown(void *parms)
  151. {
  152. // this function is where you shutdown your game and
  153. // release all resources that you allocated
  154. // return success
  155. return(1);
  156. } // end Game_Shutdown
  157. //////////////////////////////////////////////////////////
  158. int Game_Main(void *parms)
  159. {
  160. // this is the workhorse of your game it will be called
  161. // continuously in real-time this is like main() in C
  162. // all the calls for you game go here!
  163. // game logic here...
  164. // check of user is trying to exit
  165. if (KEY_DOWN(VK_ESCAPE))
  166.     {
  167.     PostMessage(main_window_handle, WM_DESTROY,0,0);
  168.     } // end if
  169. // return success
  170. return(1);
  171.  
  172. } // end Game_Main
  173. //////////////////////////////////////////////////////////