#define WIN32_LEAN_AND_MEAN #include #include "resource.h" #include "tdx.h" int TDX_screenx=640; int TDX_screeny=480; TDXsprite sp1; BOOL Init() { TDXinit(); TDXsetdebugmode(true); TDXsetdebugcolor(RGB(0,0,0)); TDXshowcursorposition(true); TDXloadmouse("images/pointer.bmp",25,25); DEBUG("Game Start "); sp1.LoadBitmap("images/invad_1.bmp",100,100); sp1.SetPos(TDX_screenx/2-50, TDX_screeny-TDX_screeny/4); return TRUE; } void EndGame( void ) { sp1.Clear(); TDXendgame(); } void GamePlay() { TDXupdateinput(); TDXclearscreen(0); if (isPress(CDXKEY_ESCAPE)) { SendMessage(h_window, WM_CLOSE, 0, 0); return; } if (isPress(CDXKEY_LEFTARROW)) sp1.GoLeft(); if (isPress(CDXKEY_RIGHTARROW)) sp1.GoRight(); if (isPress(CDXKEY_UPARROW)) sp1.GoUp(); if (isPress(CDXKEY_DOWNARROW)) sp1.GoDown(); sp1.Draw(); TDXshowmouse(); TDXgameflip(); } static long PASCAL WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_TIMER: { if (wParam==SECSUPERFAST) { sp1.Anim(0,19); } if (wParam==SECVERYFAST) { } if (wParam==SECFAST) { } if (wParam==SEC03) { } if (wParam==SEC05) { } if (wParam==SEC07) { } if (wParam==SEC1) { } if (wParam==SEC2) { } if (wParam==SEC3) { } if (wParam==SEC5) { } if (wParam==SEC8) { } if (wParam==SEC10) { } if (wParam==SEC15) { } if (wParam==SEC20) { } if (wParam==SEC30) { } }break; case WM_CHAR: { // [Text Box].UpdateKey(LOWORD(wParam)); }break; case WM_MOUSEMOVE: { int x=LOWORD(lParam); int y=HIWORD(lParam); TDXupdatemouse(x,y); }break; case WM_SETCURSOR: SetCursor(NULL); return 1; case WM_CLOSE: EndGame(); case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } } int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { MSG msg; h_instance = hInstance; WNDCLASS WndClass; WndClass.style = CS_HREDRAW | CS_VREDRAW; WndClass.lpfnWndProc = WinProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = h_instance; WndClass.hIcon = LoadIcon(h_instance, "APPICON"); WndClass.hCursor = LoadCursor(0, IDC_ARROW); WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); WndClass.lpszMenuName = 0; WndClass.lpszClassName = szClassName; RegisterClass(&WndClass); h_window = CreateWindowEx( 0, szClassName, "MyGame", WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, 0, 0, 320, 240, NULL, NULL, h_instance, NULL); if( !h_window ) CDXError( NULL , "could not create the main window" ); AdjustWinStyle(TDX_screenx, TDX_screeny); ShowWindow(h_window, nCmdShow); UpdateWindow(h_window); if(!Init()) { PostQuitMessage(0); return FALSE; } while(1) { if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if(!GetMessage(&msg, NULL, 0, 0 )) return msg.wParam; TranslateMessage(&msg); DispatchMessage(&msg); } else { GamePlay(); } } }