小游戏--吃豆子2 windows部分
来源:互联网 发布:明星加入外国国籍 知乎 编辑:程序博客网 时间:2024/04/27 23:54
// EatBean.cpp : 定义应用程序的入口点。//#include "stdafx.h"#include "EatBean.h"#include "GMap.h"#include "StageOne.h" #include "Player.h"#include "GObject.h"#include "RedEnermy.h"#include "GreenEnermy.h"#include "BlueEnermy.h"#define WLENTH 700#define WHIGHT 740#define MAX_LOADSTRING 100// 全局变量:HINSTANCE hInst;// 当前实例TCHAR szTitle[MAX_LOADSTRING];// 标题栏文本TCHAR szWindowClass[MAX_LOADSTRING];// 主窗口类名// 此代码模块中包含的函数的前向声明:ATOMMyRegisterClass(HINSTANCE hInstance);BOOLInitInstance(HINSTANCE, int , HWND &);LRESULT CALLBACKWndProc(HWND, UINT, WPARAM, LPARAM);INT_PTR CALLBACKAbout(HWND, UINT, WPARAM, LPARAM);template<class T> void Relese(T t){ if(t != NULL) delete t ;}StageOne *sg ;Player *p ; GObject *red1 , *green1 , *blue1 , *blue2 ;int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){UNREFERENCED_PARAMETER(hPrevInstance);UNREFERENCED_PARAMETER(lpCmdLine); // TODO: 在此放置代码。sg = new StageOne() ;p = new Player(12 , 10) ;red1 = new RedEnermy(8 , 11) ;green1 = new GreenEnermy(8 , 11) ;blue1 = new BlueEnermy(8 , 11) ;blue2 = new BlueEnermy(1 , 1) ;GObject::pState = sg ;Enermy::player = p ; MSG msg;HACCEL hAccelTable;// 初始化全局字符串LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);LoadString(hInstance, IDC_EATBEAN, szWindowClass, MAX_LOADSTRING);MyRegisterClass(hInstance);// 执行应用程序初始化:HWND hWnd ;if (!InitInstance (hInstance, nCmdShow ,hWnd)){return FALSE;}hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_EATBEAN));DWORD t = 0 ; // 主消息循环:while (p->GetTw() != OVER){if (PeekMessage(&msg, NULL , 0 , 0 , PM_REMOVE)){TranslateMessage(&msg);DispatchMessage(&msg);}if(GetAsyncKeyState(VK_DOWN) & 0x8000) p->SetTwCommand(DOWN) ;else if(GetAsyncKeyState(VK_UP) & 0x8000) p->SetTwCommand(UP) ;else if(GetAsyncKeyState(VK_LEFT) & 0x8000) p->SetTwCommand(LEFT) ;else if(GetAsyncKeyState(VK_RIGHT) & 0x8000) p->SetTwCommand(RIFHT) ;if(GetTickCount() - t > 58){ HDC hdc = GetDC(hWnd) ; p->Action() ; red1->Action() ; green1->Action() ; blue1->Action() ; blue2->Action() ; GObject::pState->DrawPean(hdc) ; p->DrawBlank(hdc) ; p->Draw(hdc) ; red1->DrawBlank(hdc) ; red1->Draw(hdc) ; green1->DrawBlank(hdc) ; green1->Draw(hdc) ; blue1->DrawBlank(hdc) ; blue1->Draw(hdc) ; blue2->DrawBlank(hdc) ; blue2->Draw(hdc) ; t = GetTickCount() ; DeleteDC(hdc) ;}}Relese(p) ;Relese(sg) ;Relese(red1) ;Relese(green1) ;Relese(blue1) ;Relese(blue2) ;return (int) msg.wParam;}//// 函数: MyRegisterClass()//// 目的: 注册窗口类。//// 注释://// 仅当希望// 此代码与添加到 Windows 95 中的“RegisterClassEx”// 函数之前的 Win32 系统兼容时,才需要此函数及其用法。调用此函数十分重要,// 这样应用程序就可以获得关联的// “格式正确的”小图标。//ATOM MyRegisterClass(HINSTANCE hInstance){WNDCLASSEX wcex;wcex.cbSize = sizeof(WNDCLASSEX);wcex.style= CS_HREDRAW | CS_VREDRAW;wcex.lpfnWndProc= WndProc;wcex.cbClsExtra= 0;wcex.cbWndExtra= 0;wcex.hInstance= hInstance;wcex.hIcon= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_EATBEAN));wcex.hCursor= LoadCursor(NULL, IDC_ARROW);wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);wcex.lpszMenuName= MAKEINTRESOURCE(IDC_EATBEAN);wcex.lpszClassName= szWindowClass;wcex.hIconSm= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));return RegisterClassEx(&wcex);}//// 函数: InitInstance(HINSTANCE, int)//// 目的: 保存实例句柄并创建主窗口//// 注释://// 在此函数中,我们在全局变量中保存实例句柄并// 创建和显示主程序窗口。//BOOL InitInstance(HINSTANCE hInstance, int nCmdShow , HWND &hWnd){ hInst = hInstance; // 将实例句柄存储在全局变量中 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 0, 0, WLENTH, WHIGHT, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE;}//// 函数: WndProc(HWND, UINT, WPARAM, LPARAM)//// 目的: 处理主窗口的消息。//// WM_COMMAND- 处理应用程序菜单// WM_PAINT- 绘制主窗口// WM_DESTROY- 发送退出消息并返回////LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){int wmId, wmEvent;PAINTSTRUCT ps;HDC hdc;switch (message){case WM_COMMAND:wmId = LOWORD(wParam);wmEvent = HIWORD(wParam);// 分析菜单选择:switch (wmId){case IDM_ABOUT:DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);break;case IDM_EXIT:DestroyWindow(hWnd);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}break;case WM_PAINT:hdc = BeginPaint(hWnd, &ps);// TODO: 在此添加任意绘图代码...GObject::pState->DrawObstacle(hdc) ;EndPaint(hWnd, &ps);break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0;}// “关于”框的消息处理程序。INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){UNREFERENCED_PARAMETER(lParam);switch (message){case WM_INITDIALOG:return (INT_PTR)TRUE;case WM_COMMAND:if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL){EndDialog(hDlg, LOWORD(wParam));return (INT_PTR)TRUE;}break;}return (INT_PTR)FALSE;}
BOOL Arc( HDC hdc, // handle to device context dc句柄 int nLeftRect, // x-coord of rectangle's upper-left corner 包容矩形左X值 int nTopRect, // y-coord of rectangle's upper-left corner 包容矩形顶Y值 int nRightRect, // x-coord of rectangle's lower-right corner 包容矩形右X值 int nBottomRect, // y-coord of rectangle's lower-right corner 包容矩形底Y值 int nXStartArc, // x-coord of first radial ending point 第一点X坐标 int nYStartArc, // y-coord of first radial ending point 第一点Y坐标 int nXEndArc, // x-coord of second radial ending point 结束点X坐标 int nYEndArc // y-coord of second radial ending point 结束点Y坐标);
弧为逆时针旋转 (注意:逆时针)
0 0
- 小游戏--吃豆子2 windows部分
- 小游戏----吃豆子
- 吃豆子的小游戏
- 吃豆子
- Java吃豆子游戏-2 接口
- google吃豆子游戏
- 吃豆子游戏
- 吃豆子过桥问题
- 吃豆子过桥
- CSS2D--吃豆子游戏
- c#吃豆子游戏,模仿百度在线应用吃豆子
- HTML5 canvas 模拟吃豆子
- c++实现吃豆子游戏
- 很怀旧的游戏--吃豆子
- 控制台界面的吃豆子游戏
- 手把手教学MFC吃豆子教程
- 一个简单的吃豆子游戏
- 网易18实习生网测题--吃豆子
- Myeclipse 快捷键
- GB28181 SIP视频监控统专题之 相关标准
- oracle表空间和数据字典的概念
- 人工智能和机器学习(深度学习)链接(了解补充)
- RadHat Linu 和windows 7双系统#问题分析
- 小游戏--吃豆子2 windows部分
- 被放走了的岁月
- win7 下设置挂载Linux服务器nfs共享的数据
- uml活动图
- oracle使用exp/imp导入导出(用户)
- javascript之Date
- openssl 获取x509.pem 证书信息
- 长大后似乎越来越喜欢怀恋过去
- Bluemix常见问题解答