#include <windows.h>
#include <ddraw.h>
#include <fstream>
#include <stdio.h>
using namespace std;
/********************************************************************
created: 2008/08/20
created: 20:8:2008 14:12
filename: E:\GAMES\Game\GameMain.cpp
file path: E:\GAMES\Game
file base: GameMain
file ext: cpp
author: SJay
purpose: 宏定义
*********************************************************************/
#define GAME_WEIDTH 640 // 游戏屏幕宽 [8/20/2008 ssj]
#define GAME_HEIGHT 480 // 游戏屏幕高 [8/20/2008 ssj]
#define GAME_BPP 32 // 游戏屏幕颜色深度 [8/20/2008 ssj]
#define WND_CLASS "SUN"
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000)?1:0) // 检测鼠标按下 [8/20/2008 ssj]
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000)?0:1) // 检测鼠标松开 [8/20/2008 ssj]
/********************************************************************
created: 2008/08/20
created: 20:8:2008 14:53
filename: E:\GAMES\Game\GameMain.cpp
file path: E:\GAMES\Game
file base: GameMain
file ext: cpp
author: SJay
purpose: 函数定义
*********************************************************************/
BOOL InitWindow(HINSTANCE, int);// 窗体初始化函数 [8/20/2008 ssj]
BOOL InitDDraw(); // DX初始化函数 [8/20/2008 ssj]
LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); // 消息响应函数 [8/20/2008 ssj]
void GameRun(); // 游戏循环函数 [8/20/2008 ssj]
BOOL ClearSurFace(); // 页面清理函数 [8/20/2008 ssj]
BOOL FilpSurFace(); // 翻页函数 [8/20/2008 ssj]
BOOL Render(); // 渲染下一帧 [8/20/2008 ssj]
void GameExit(); // 游戏结束函数 [8/20/2008 ssj]
void RleaseSrc(); // 释放资源 [8/20/2008 ssj]
void WindowExit(); // 关闭应用程序 [8/20/2008 ssj]
void xz();
void LoadSurFace();
DWORD Get_Clock(void);
DWORD Start_Clock(void);
DWORD Wait_Clock(DWORD count);
BOOL CheckMove(int x,int y);
/********************************************************************
created: 2008/08/20
created: 20:8:2008 20:41
filename: E:\Games\Game\GameMain.cpp
file path: E:\Games\Game
file base: GameMain
file ext: cpp
author: SJay
purpose: 结构体定义
*********************************************************************/
struct dt // 地图数据结构体 [8/20/2008 ssj]
{
int top;
int left;
int sfkxz;
int dz;
int dzcs;
};
struct head // 地图头结构体 [8/20/2008 ssj]
{
int h;
int w;
int y;
int x;
};
struct zbk
{
BOOL sfkxz;
int dz;
int dzcs;
};
/********************************************************************
created: 2008/08/20
created: 20:8:2008 14:55
filename: E:\GAMES\Game\GameMain.cpp
file path: E:\GAMES\Game
file base: GameMain
file ext: cpp
author: SJay
purpose: 变量定义
*********************************************************************/
HWND hWnd=NULL; // 窗口句柄 [8/20/2008 ssj]
HINSTANCE m_hInstance=NULL; // 应用程序实例 [8/20/2008 ssj]
HDC hdc=NULL; // 全局上下文指针 [8/20/2008 ssj]
DWORD fps=0; // 帧数 [8/20/2008 ssj]
DWORD fps_tem=0; // 临时帧数 [8/20/2008 ssj]
DWORD fps_i=1; // 执行次数 [8/20/2008 ssj]
DWORD Time1=0; // 计时器1 [8/20/2008 ssj]
DWORD Time2=0; // 计时器2 [8/20/2008 ssj]
int NPC_state_x=0; // NPC位图状态X [8/20/2008 ssj]
int NPC_state_y=0; // NPC位图状态Y [8/20/2008 ssj]
int NPC_x=100; // NPC坐标X [8/20/2008 ssj]
int NPC_y=100; // NPC坐标y [8/20/2008 ssj]
BOOL wfl=FALSE;
DWORD start_clock_count;
int jbtj=1;
zbk *ydxz;
LPDIRECTDRAW7 lpDD=NULL; // 设备指针 [8/20/2008 ssj]
LPDIRECTDRAWSURFACE7 lpDDSPrimary=NULL; // 主页面 [8/20/2008 ssj]
LPDIRECTDRAWSURFACE7 lpDDSBuffer=NULL; // 缓冲页面 [8/20/2008 ssj]
LPDIRECTDRAWSURFACE7 lpDDSOffScreen_dtMap=NULL; // 地图页面 [8/20/2008 ssj]
LPDIRECTDRAWSURFACE7 lpDDSOffScreen_Role=NULL; // 角色页面 [8/20/2008 ssj]
LPDIRECTDRAWSURFACE7 lpDDSOffScreen_ObjMap=NULL; // 部件页面 [8/20/2008 ssj]
LPDIRECTDRAWSURFACE7 lpDDSOffScreen_TempMap=NULL; // 临时图片保存页面 [8/20/2008 ssj]
LPDIRECTDRAWCLIPPER lpDDClipper; // 页面剪切 [8/20/2008 ssj]
/********************************************************************
created: 2008/08/20
created: 20:8:2008 14:54
filename: E:\GAMES\Game\GameMain.cpp
file path: E:\GAMES\Game
file base: GameMain
file ext: cpp
author: SJay
purpose: 应用程序入口函数
*********************************************************************/
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
if (!InitWindow(hInstance,nCmdShow))
{
return 0;
}
if (!InitDDraw())
{
return 0;
}
MSG msg;
//进入消息循环:
for(;;)
{
GameRun();
xz();
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if ( msg.message==WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
/********************************************************************
created: 2008/08/20
created: 20:8:2008 15:05
filename: E:\GAMES\Game\GameMain.cpp
file path: E:\GAMES\Game
file base: GameMain
file ext: cpp
author: SJay
purpose: 窗体初始化
*********************************************************************/
BOOL InitWindow(HINSTANCE hInstance, int nCmdShow)
{
WNDCLASS wc; // 定义WNDCLASS结构 [8/20/2008 ssj]
wc.style = NULL; // 样式 [8/20/2008 ssj]
wc.lpfnWndProc = (WNDPROC)WinProc; // 指定消息响应函数 [8/20/2008 ssj]
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance; // 设置应用程序实例号 [8/20/2008 ssj]
wc.hIcon = NULL; // 设置窗口图标样式 [8/20/2008 ssj]
wc.hCursor = LoadCursor(NULL,IDC_ARROW); // 设置鼠标样式 [8/20/2008 ssj]
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // 设置窗口背景色画刷 [8/20/2008 ssj]
wc.lpszMenuName = NULL; // 设置窗口菜单 [8/20/2008 ssj]
wc.lpszClassName = WND_CLASS; // 设置窗口类名 [8/20/2008 ssj]
RegisterClass(&wc); // 注册窗口 [8/20/2008 ssj]
hWnd = CreateWindow(WND_CLASS, // 创建窗口 [8/20/2008 ssj]
"GameMain",
WS_POPUP|WS_MAXIMIZE,0,0,
GetSystemMetrics( SM_CXSCREEN ), //此函数返回屏幕宽度
GetSystemMetrics( SM_CYSCREEN ), //此函数返回屏幕高度
NULL,NULL,hInstance,NULL);
if( !hWnd ) return FALSE; // 判断窗口是否被创建 [8/20/2008 ssj]
ShowWindow(hWnd,nCmdShow); //显示窗口 [8/20/2008 ssj]
UpdateWindow(hWnd); //刷新窗口 [8/20/2008 ssj]
m_hInstance=hInstance;
HDC tem_DC; // 获取上下文内存DC [8/20/2008 ssj]
tem_DC=GetDC(hWnd);
hdc=CreateCompatibleDC(tem_DC);
ReleaseDC(hWnd,tem_DC);
return TRUE;
}
/********************************************************************
created: 2008/08/20
created: 20:8:2008 15:05
filename: E:\GAMES\Game\GameMain.cpp
file path: E:\GAMES\Game
file base: GameMain
file ext: cpp
author: SJay
purpose: DX初始化
*********************************************************************/
BOOL InitDDraw()
{
DDSURFACEDESC2 ddsd; // DirectDraw的页面描述 [8/20/2008 ssj]
if (DD_OK!=DirectDrawCreateEx(NULL,(void **)&lpDD,IID_IDirectDraw7,NULL)) // 创建设备指针 [8/20/2008 ssj]
return FALSE;
if (FAILED(lpDD->SetCooperativeLevel(hWnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN))) // 设置DirectDraw控制级 [8/20/2008 ssj]
return FALSE;
if (FAILED(lpDD->SetDisplayMode( GAME_WEIDTH, GAME_HEIGHT, GAME_BPP, 0, DDSDM_STANDARDVGAMODE ))) // 设置显示模式 [8/20/2008 ssj]
return FALSE;
if ( DD_OK != DirectDrawCreateClipper(0,&lpDDClipper,NULL)) // 创建页面剪切 [8/20/2008 ssj]
return FALSE;
if ( DD_OK !=lpDDClipper->SetHWnd(0,hWnd)) // �
游戏移动限制实现
需积分: 11 15 浏览量
2008-08-22
19:50:12
上传
评论
收藏 380KB RAR 举报
ssj5210410
- 粉丝: 1
- 资源: 6
最新资源
- #P0015. 全排列 超级简单
- pta题库答案c语言之排序4统计工龄.zip
- pta题库答案c语言之树结构7堆中的路径.zip
- pta题库答案c语言之树结构3TreeTraversalsAgain.zip
- pta题库答案c语言之树结构2ListLeaves.zip
- pta题库答案c语言之树结构1树的同构.zip
- 基于C++实现民航飞行与地图简易管理系统可执行程序+说明+详细注释.zip
- pta题库答案c语言之复杂度1最大子列和问题.zip
- 三维装箱问题(Three-Dimensional Bin Packing Problem,3D-BPP)是一个经典的组合优化问题
- 以下是一些关于Linux线程同步的基本概念和方法.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈