HGE指南1翻译

来源:互联网 发布:mysql数据库密码忘记 编辑:程序博客网 时间:2024/05/15 02:50

HGE指南1翻译

作者:潇潇  出处:www.j2mefans.com
该文章为本站原创,如有引用,请注明出处和作者


Tutorial 01 - Minimal HGE application 最小的HE程序
First, we include hge.h header and declare a variable to store the HGE interface pointer to: 首先,我们包含hge.h头文件并且定一个变量去存储HGE接口指针: 
#include <hge.h>

HGE *hge = 0;
Then we create our frame function. The frame function is a user -defined function that will be called by HGE once per frame: put your game loop code here. When the frame function returns true,  the HGE stops execution of game loop. 然后我们创建自己的帧函数。这个帧函数是一个用户自定义函数,他将在每 帧被HGE调用一次:所以放置你的游戏循环代码在这里。如果这个帧函数返回值为真,HGE停止执行游戏循环。

In this example we just check whether ESC key has been pressed: 在这个例子里,我们检查ESC键是否已经被按下:
bool FrameFunc()
{
  if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;
  return false;
}
The WinMain function is a standard windows application entry point. Here we'll obtain a pointer to HGE interface to access HGE functions. In this example we use global pointer to HGE interface. Instead you may use hgeCreate function every time you need access to HGE. Just be sure to have a corresponding Release call for each call to hgeCreate. WinMain 函数是一个标准windows应用程序入口点。在这里我们得到一个HGE接口指针去访问HGE函数。在这个例子中我们使用全局HGE接口指针。每次你需要 访问HGE你可以使用hgeCreate函数。每次调用hgeCreate后就可以有一个相应的版本。
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  hge = hgeCreate(HGE_VERSION);
Then we set some internal HGE system states to configure the environment. Although most of the system states have appropriate defaults,  at least HGE_FRAMEFUNC must be set before calling System_Start. 然后,我们设置 一些内在的HGE系统状态去配置这个环境。虽然大多数系统默认状态都有适当的默认值,至少在调用System_Start之前HGE_FRAMEFUNC 必须被设置。
  hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
  hge->System_SetState(HGE_WINDOWED, true);
  hge->System_SetState(HGE_USESOUND, false);
  hge->System_SetState(HGE_TITLE,
                 "HGE Tutorial 01 - Minimal HGE application");
Now we initiate HGE with the states set. If something goes wrong,  the System_Initiate function returns false and more specific description of what have happened can be read with System_GetErrorMessage.  现在我们开始HGE的状态设置。如果某些事情发生错误,System_Initate函数返回false并且可以使用 System_GetErrorMessage读取关于发生问题的更详细的描述。

Having HGE initiated we start the game loop with call to the System_Start function. The execution "stops" here until true is returned from the frame function.  在HGE初始化之后我们通过调用System_Start函数开始游戏循环。直到从帧函数返回true,在这里执行停止。
  if(hge->System_Initiate())
  {
    hge->System_Start();
  }
  else
  {    
    MessageBox(NULL, hge->System_GetErrorMessage(), "Error",
               MB_OK | MB_ICONERROR | MB_APPLMODAL);
  }
Now ESC has been pressed or the user has closed the window by other means. We should restore video mode and free all allocated resources. Also we should release the HGE interface:  现在ESC被按下或者用户通过其他方法关闭了窗口。我们将恢复显示模式并且释放所有分配的资源。我们也将释放HGE接口:
  hge->System_Shutdown();
  hge->Release();

  return 0;
}
Voila!  Just about 20 lines of code and we have fully functional and running environment for a game!  瞧!仅仅20行的代码,我们就有了一个完整功能和游戏运行环境。

The complete source code with detailed comments for this tutorial you may find in the folder tutorials /tutorial01. 完整的带详细注释的指南1的源代码,你可以在tutorials/tutorial01文件夹中找到。