资源预览内容
第1页 / 共15页
第2页 / 共15页
第3页 / 共15页
第4页 / 共15页
第5页 / 共15页
第6页 / 共15页
第7页 / 共15页
第8页 / 共15页
第9页 / 共15页
第10页 / 共15页
亲,该文档总共15页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
C语言打砖块游戏一、游戏截图2、 游戏源码#include #include #include #include /* DEFINES */ defines for windows#define WINDOW_CLASS_NAMETEXT(WIN32CLASS)#define WINDOW_WIDTH640#define WINDOW_HEIGHT480/ states for game loop#define GAME_STATE_INIT 0#define GAME_STATE_START_LEVEL 1#define GAME_STATE_RUN 2#define GAME_STATE_SHUTDOWN 3#define GAME_STATE_EXIT 4/ block defines#define NUM_BLOCK_ROWS 6#define NUM_BLOCK_COLUMNS 8#define BLOCK_WIDTH 64#define BLOCK_HEIGHT 16#define BLOCK_ORIGIN_X 8#define BLOCK_ORIGIN_Y 8#define BLOCK_X_GAP 80#define BLOCK_Y_GAP 32/ paddle defines#define PADDLE_START_X (WINDOW_WIDTH/2 - 16)#define PADDLE_START_Y (WINDOW_HEIGHT - 32);#define PADDLE_WIDTH 32#define PADDLE_HEIGHT 8#define PADDLE_COLOR RGB(0, 0, 255)/ ball defines#define BALL_START_Y (WINDOW_HEIGHT/2)#define BALL_SIZE 4/ color defines#define BACKGROUND_COLORRGB(0, 0, 0)#define BLOCK_COLORRGB(125, 0, 0)#define BALL_COLORRGB(222, 0, 222)/ these read the keyboard asynchronously#define KEY_DOWN(vk_code) (GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)#define KEY_UP(vk_code) (GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)/* basic unsigned types */typedef unsigned short USHORT;typedef unsigned short WORD;typedef unsigned char UCHAR;typedef unsigned char BYTE;/* FUNCTION DECLARATION */int Game_Init(void *parms = NULL);int Game_Shutdown(void *parms = NULL);int Game_Main(void *parms = NULL);DWORD Start_Clock(void);DWORD Wait_Clock(DWORD count);/* GLOBALS */HWNDmain_window_handle= NULL;/ save the window handleHINSTANCEmain_instance= NULL;/ save the instanceintgame_state= GAME_STATE_INIT;/ starting stateintpaddle_x = 0, paddle_y = 0;/ tracks position of paddleintball_x = 0, ball_y = 0;/ tracks position of ballintball_dx = 0, ball_dy = 0;/ velocity of ballintscore = 0;/ the scoreintlevel = 1;/ the current levelintblocks_hit = 0;/ tracks number of blocks hitDWORDstart_clock_count= 0;/ used for timing/ this contains the game grid dataUCHAR blocksNUM_BLOCK_ROWSNUM_BLOCK_COLUMNS; /* WINDPROC */LRESULT CALLBACK WindowProc(HWNDhwnd,UINTmsg,WPARAMwparam,LPARAMlparam)/ this is the main message handler of the systemPAINTSTRUCTps;HDChdc;switch (msg)case WM_CREATE:return 0;case WM_PAINT:hdc = BeginPaint(hwnd, &ps);EndPaint(hwnd, &ps);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;default:break;return DefWindowProc(hwnd, msg, wparam, lparam);/* WINMAIN */int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)WNDCLASSwinclass;HWNDhwnd;MSGmsg;HDChdc;PAINTSTRUCTps;/* CS_DBLCLKS Specifies that the window should be notified of double clicks with * WM_xBUTTONDBLCLK messages * CS_OWNDC标志,属于此窗口类的窗口实例都有自己的DC(称为私有DC),私有DC仅属于该窗口实例, * 所以程序只需要调用一次GetDC或BeginPaint获取DC,系统就为窗口初始化一个DC,并且保存程序 * 对其进行的改变。ReleaseDC和EndPaint函数不再需要了,因为其他程序无法访问和改变私有DC。 */winclass.| CS_OWNDC | CS_HREDRAW | CS_VREDRAW;winclass.lpfnWndProc= WindowProc;winclass.cbClsExtra= 0;winclass.cbWndExtra= 0;winclass.hInstance= hinstance;winclass.hIcon= LoadIcon(NULL, IDI_APPLICATION);winclass.hCursor= LoadCursor(NULL, IDC_ARROW);winclass.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH);winclass.lpszMenuName= NULL;winclass.lpszClassName= WINDOW_CLASS_NAME;/ register the window classif (!RegisterClass(&winclass)return 0;/ Create the window, note the use of WS_POPUPhwnd = CreateWindow(WINDOW_CLASS_NAME,/ classTEXT(WIN32 Game Console),/ titleWS_POPUP,/ style200,/ initial x100,/ initial yWINDOW_WIDTH,/ initial widthWINDOW_HEIGHT,/ initial heightNULL,/ handle to parentNULL,/ handle to menuhinstance,/ instanceNULL);/ creation parmsif (! hwnd)return 0;ShowWindow(hwnd, ncmdshow);UpdateWindow(hwnd);/ hide
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号