⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 游戏开发中心----游戏实验室 - 博客园.htm

📁 这是我上-dsp-5400用的课件。里面有软件的simulater的设置
💻 HTM
📖 第 1 页 / 共 5 页
字号:
      </FONT><FONT face=宋体 color=#99ccff size=2><BR>&nbsp;&nbsp;&nbsp; 
      CurrentFrame++; <BR></FONT></FONT><FONT face=宋体></FONT></FONT><FONT 
      face=Arial><FONT face=宋体 color=#99ccff size=2>&nbsp;&nbsp;&nbsp; if( 
      CurrrentFrame==3 )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      CurrentFrame = 0; </FONT><FONT face=宋体 color=#808080 size=2>// 
      这个步骤能够保证动作的循环 </FONT><FONT face=宋体 color=#99ccff size=2><BR>}</FONT><FONT 
      face=Fixedsys color=#99ccff size=2><BR></FONT><FONT face=Arial><FONT 
      face=Arial size=2><BR>  不知道这么个函数你能否看懂。之所以要采用 static 
      静态变量,是因为我们这个函数程序要循环运行。如果直接写个 int 的话,每次执行都会被赋回原值 0,那么图片就不会变了。 
      <BR><BR>  上面这段代码其实并不是那么理想。因为程序自己在那儿一个劲地运行,完全没有我们控制的份儿。别急!来看下面这份修改过的伪代码: 
      <BR><BR></FONT></FONT><FONT face=宋体 color=#99ccff size=2>#define 
      m_Width&nbsp;&nbsp; 32&nbsp;&nbsp; </FONT><FONT face=宋体 color=#808080 
      size=2>// 每个动作的 宽度 </FONT><FONT face=宋体 color=#99ccff size=2><BR>#define 
      m_Height&nbsp; 48&nbsp;&nbsp; </FONT><FONT face=宋体 color=#808080 size=2>// 
      每个动作的 高度 </FONT><FONT face=宋体 size=2><BR><BR></FONT><FONT face=宋体 
      color=#99ccff size=2>void ShowThePic() <BR>{<BR>&nbsp;&nbsp;&nbsp; static 
      RECT rect;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><FONT face=宋体 color=#808080 
      size=2>// 矩形对象,用于精确定位所要的当前动作 </FONT><FONT face=宋体 color=#99ccff 
      size=2><BR>&nbsp;&nbsp; &nbsp;static int CurrentFrame = 0; </FONT><FONT 
      face=宋体 color=#808080 size=2>// 当前动作的编号 </FONT><FONT face=宋体 color=#99ccff 
      size=2><BR>&nbsp;&nbsp;&nbsp; static int Direction = 0;&nbsp;&nbsp;&nbsp; 
      </FONT><FONT face=宋体 color=#808080 size=2>// 当前的方向 </FONT><FONT face=宋体 
      color=#99ccff size=2><BR>&nbsp;&nbsp;&nbsp; rect.top = Direction; 
      rect.bottom = (Direction+1)*m_Height; </FONT><FONT face=宋体 color=#808080 
      size=2>//对当前矩形的大小定义,数学的问题哦 </FONT><FONT face=宋体 color=#99ccff 
      size=2><BR>&nbsp; &nbsp; rect.left = CurrentFrame; rect.right = 
      (CurrentFrame+1)*m_Width; </FONT><FONT face=宋体 color=#808080 
      size=2>//根据英文的意思也可以知道在给谁赋值 </FONT><FONT face=宋体 color=#99ccff 
      size=2><BR>&nbsp;&nbsp;&nbsp; BltPicToScreen();&nbsp;&nbsp;&nbsp;&nbsp; 
      </FONT><FONT face=宋体 color=#808080 size=2>// 一个伪函数,作用是将当前矩形内的图形复制到屏幕上。 
      </FONT><FONT face=宋体 color=#99ccff size=2><BR><BR>&nbsp;&nbsp;&nbsp; if( 
      LeftArrowDown() ) </FONT><FONT face=宋体 color=#808080 size=2>// 如果 左箭头 被按下 
      </FONT><FONT face=宋体 color=#99ccff size=2><BR>&nbsp;&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Direction = 
      1;&nbsp;&nbsp;&nbsp; </FONT><FONT face=宋体 color=#808080 size=2>// 赋值方向为 1 
      </FONT><FONT face=宋体 color=#99ccff 
      size=2><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CurrentFrame++; 
      <BR>&nbsp;&nbsp;&nbsp; } <BR><BR>&nbsp;&nbsp;&nbsp; if( RightArrowDown() ) 
      <BR>&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      Direction = 3; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      CurrentFrame++; <BR>&nbsp;&nbsp;&nbsp; } <BR><BR>&nbsp;&nbsp;&nbsp; if( 
      UpArrowDown() ) <BR>&nbsp;&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Direction = 2; 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CurrentFrame++; 
      <BR>&nbsp;&nbsp;&nbsp; } <BR><BR>&nbsp;&nbsp;&nbsp; if( DownArrowDown() ) 
      <BR>&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      Direction = 0; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      CurrentFrame++; <BR>&nbsp;&nbsp;&nbsp; } <BR><BR>&nbsp;&nbsp;&nbsp; 
      if(CurrrentFrame==3)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      CurrentFrame = 0; </FONT><FONT face=宋体 color=#808080 size=2>// 
      这个步骤能够保证动作的循环 </FONT><FONT face=宋体 color=#99ccff size=2><BR>} </FONT><FONT 
      face=Arial 
      size=2><BR><BR>  经过这么一修改,问题再次得到解决。上面的代码就能够响应用户的操作了。当然,你这么直接在程序里输入这些代码是不行的:)因为是“伪代码”。你得根据实际情况,自己相应地做些修改,才能使程序运行! 
      <BR><BR>  (题外话:不晓得这么进行教学,你是否能够一点一点的积累到知识?这种教程是不是合适?请到论坛内发表意见,我真的很想能够摸索出大家接受的方法,有利教学) 
      <BR><BR>  欢迎回到教程中来!有人或许会问,为什么这么麻烦要把图形放在这么个图片里头,不一个动作一个图啊?呵呵,想想,那要多少图片啊,很难于管理的。况且,这样并不能避免使用这种常用手法,因为 
      RECT 已经是一个成员。游戏里不能不用他的! <BR><BR>  哇,口水干了。(其实是手累了:)我们下回再见吧。 <BR><BR>  下回预告: 
      <BR>  少年侦探柯南为了查清楚事情的真相,他......(?还真的预告啊?) 
      <BR>  不好意思,习惯性用语了:)在下回,我会讲一下,如何将今天的代码整合到程序中去。<BR><BR><BR><BR></FONT><B><A 
      name="三、游戏的基石: 窗口 的建立">三、游戏的基石: 窗口 的建立</A></B><FONT 
      size=2><BR><BR>  Welcome back!很高兴再次与你相遇教程。废话不多说,继续。 
      <BR><BR>  上次的代码片段,说实在,拿在手里没有用。为啥?因为不能运行的啊:)我们这次就按照上次的安排,讲如何将显示图片的代码片段整合到程序中,让它能够具体的体现出来。 
      <BR><BR>  我将在这儿讨论 Windows 编程,而不是 MFC 。关于 MFC 和 Windows 的不同和各自的优点,我们不多涉及了。 
      MFC 就是微软的一个封装开发库,极大程度的降低了 Windows 开发的复杂。但是,我们还是继续 Windows 编程,呵呵。 
      <BR><BR>  我们来看,一个基本的 Windows 程序是一个窗口对吧:)我们所玩的游戏,其实也是有窗口的,只不过是看不见的,而且被 
      DirectDraw 掩盖了而已。那么,如何创建一个窗口呢?我们来看: <BR><BR></FONT><FONT face=宋体 
      color=#99ccff size=2>BOOL Init(HINSTANCE hInst, int nCmdShow) 
      <BR>{<BR>&nbsp;&nbsp;&nbsp; HWND 
      hWnd;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </FONT><FONT face=宋体 color=#808080 size=2>// 窗口的句柄,就是一个储存窗口的对象 
      </FONT><FONT face=宋体 color=#99ccff size=2><BR>&nbsp;&nbsp;&nbsp; WNDCLASS 
      WndClass;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </FONT><FONT face=宋体 color=#808080 size=2>// 用于注册窗口的对象</FONT><FONT face=宋体 
      color=#99ccff size=2> <BR><BR>&nbsp;&nbsp;&nbsp; WndClass.style = 
      CS_HREDRAW | CS_VREDRAW; </FONT><FONT face=宋体 color=#808080 size=2>// 
      定义窗口的类型 </FONT><FONT face=宋体 color=#99ccff size=2><BR>&nbsp;&nbsp;&nbsp; 
      WndClass.lpfnWndProc = WinProc;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><FONT 
      face=宋体 color=#808080 size=2>// 指定了窗口消息的处理函数 ** 关键!</FONT><FONT face=宋体 
      color=#99ccff size=2> <BR>&nbsp;&nbsp;&nbsp; WndClass.cbClsExtra = 
      0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </FONT><FONT face=宋体 color=#808080 size=2>// 没有特定意义 </FONT><FONT face=宋体 
      color=#99ccff size=2><BR>&nbsp;&nbsp;&nbsp; WndClass.cbWndExtra = 
      0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </FONT><FONT face=宋体 color=#808080 size=2>// 没有特定意义 </FONT><FONT face=宋体 
      color=#99ccff size=2><BR>&nbsp;&nbsp;&nbsp; WndClass.hInstance = 
      hInst;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><FONT 
      face=宋体 color=#808080 size=2>// 窗口的实例 </FONT><FONT face=宋体 color=#99ccff 
      size=2><BR>&nbsp;&nbsp;&nbsp; WndClass.hIcon = LoadIcon(hInst, 
      IDI_APPLICATION); </FONT><FONT face=宋体 color=#808080 size=2>// 
      指定窗口的图标</FONT><FONT face=宋体 color=#99ccff size=2> <BR>&nbsp;&nbsp;&nbsp; 
      WndClass.hCursor = LoadCursor(hInst, IDC_ARROW);&nbsp;&nbsp; </FONT><FONT 
      face=宋体 color=#808080 size=2>// 指定程序的指针 </FONT><FONT face=宋体 color=#99ccff 
      size=2><BR>&nbsp;&nbsp;&nbsp; WndClass.hbrBackground = 
      (HBRUSH)GetStockObject(BLACK_BRUSH); </FONT><FONT face=宋体 color=#808080 
      size=2>// 指定背景色为黑色</FONT><FONT face=宋体 color=#99ccff size=2> 
      <BR>&nbsp;&nbsp;&nbsp; WndClass.lpszMenuName = 
      NULL;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><FONT face=宋体 
      color=#808080 size=2>// 指定菜单为无,游戏不需要 </FONT><FONT face=宋体 color=#99ccff 
      size=2><BR>&nbsp;&nbsp;&nbsp; WndClass.lpszClassName = "GDIM_GAME_ENGINE"; 
      </FONT><FONT face=宋体 color=#808080 size=2>//这个程序注册的名字</FONT><FONT face=宋体 
      color=#99ccff size=2> <BR>&nbsp;&nbsp;&nbsp; </FONT><FONT size=2><FONT 
      face=宋体 
      color=#99ccff>RegisterClass(&amp;WndClass);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </FONT><FONT face=宋体 color=#808080>// 注册程序 </FONT><FONT face=宋体 
      color=#99ccff><BR><BR>&nbsp;&nbsp;&nbsp; hWnd = 
      CreateWindowEx(WS_EX_TOPMOST, "GDIM_GAME_ENGINE", "GDIM_GAME", WS_POPUP, 
      112, 84, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInst, NULL); 
      <BR>&nbsp;&nbsp;&nbsp; </FONT><FONT face=宋体 color=#808080>// 
      这段代码就是实现了一个窗口的创建 <BR></FONT><FONT face=宋体 color=#99ccff>&nbsp;&nbsp;&nbsp; 
      </FONT><FONT face=宋体 color=#808080>// 我们可以通过来检测是否创建成功。如果失败将返回一个 FALSE 的值。 
      </FONT><FONT face=宋体 color=#99ccff><BR>&nbsp;&nbsp;&nbsp; if(!hWnd) return 
      FALSE; <BR>&nbsp;&nbsp;&nbsp; ShowWindow(hWnd, nCmdShow);&nbsp; 
      </FONT><FONT face=宋体 color=#808080>// 显示窗口</FONT><FONT face=宋体 
      color=#99ccff> <BR>&nbsp;&nbsp;&nbsp; 
      UpdateWindow(hWnd);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </FONT><FONT face=宋体 color=#808080>// 更新窗口 </FONT><FONT face=宋体 
      color=#99ccff><BR>} 
      </FONT><BR><BR>  好了,到这儿呢,我们就成功的创建了一个窗口。我们回头看我注了“**”的地方,关于这个函数,我们得写个同名函数来处理 
      Windows 的消息。呵呵,不好意思,再看一个函数: <BR><BR></FONT></FONT><FONT size=2><FONT 
      face=宋体 color=#99ccff>BOOL bActive = 
      FALSE;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><FONT face=宋体 
      color=#808080>// 用于判断程序是否运行的变量 </FONT><FONT face=宋体 
      color=#99ccff><BR><BR>long PASCAL WinProc(HWND hWnd, UINT message, WPARAM 
      wParam, LPARAM lParam)<BR>{ <BR>&nbsp;&nbsp;&nbsp; switch(message) 
      <BR>&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp; case WM_ACTIVATE: 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bActive = 
      TRUE;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><FONT face=宋体 color=#808080>// 
      当程序被激活时,赋值 TRUE </FONT><FONT face=宋体 
      color=#99ccff><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -