HGEd2d 引擎 和hge游戏中精灵生命值怎么设定

3206人阅读
大概三个月前,我在试着用几款2D游戏引擎。
&&& 第一款是SDL,这是同事推荐给我的一款跨平台的2D游戏引擎。这款引擎评价很高,总的来说是因为它够底层,实现的功能非常基本,又提供了一套平台无关的接口。所以开发人员在此之上可以天马行空的开发。不过我不是那么热衷底层&&于是我在写了几个实验性的程序之后放弃了他。呵呵,当时研究它主要是因为自己也在做嵌入式,对跨平台很感兴趣。但是当时看一个老外,好像叫lazyfoo,写的开发教程让我学到了很多游戏开发方面基本的知识。
&&& 然后第二款是HGE,它是基于driectX的一款开源2D游戏引擎,也是提供较底层的功能。最核心的大概是它提供基于帧的逻辑和渲染回调,开发人员来实现每帧进行的操作。HGE还提供了一套我觉得非常不好的教程,对于新手是绝对的误导&&它的教程里的代码都乱七八糟,感觉就像个C++新手写的代码一样,各种全局变量,各种魔数,各种乱命名,可读性和框架性都较差。(可能也是HGE的开发者为了求简,不过我觉得这个教程可以做的更好。)
&&& 这时,我自己做的一套简单的游戏,已经简单的设计好UI接口。于是我用HGE来实现这套接口。
&&& 我觉得HGE很恶心的地方就是它基于每帧的回调(当然你可以修改HGE内核来去除这一点,不过将带来更多麻烦,因为HGE很多函数就是基于帧回调机制的。)所以你不能像使用一个Canvas一样来进行实时绘制。于是我在游戏里自己实现了一套消息机制,把整个HGE框架跑在另一个线程中,游戏数据核心线程通过发消息的方式去通知界面更新,或者获取玩家操作。
这是当时自己弄的设计,DirectX or Ddraw改成HGE,后来自己也实现了。
刚开始的时候感觉还好,后来代码稍微上规模的话,就觉得很吃力了。因为我是基于具体游戏功能来封装HGE的接口。在之后又重构了几次,整体架构还算清晰,但是界面和代码之间的耦合度实在太大。最后可以实现一定的界面功能,但是还是太不爽了,所以决定放弃使用HGE。在此总结一下自己的想法,如果要用HGE真正开发一款稍微上规模的游戏,应该怎么做,可能也有很多不正确的地方,欢迎指正。
1. 实现页面栈、控件树
我也不知道该怎么定义这个名称,姑且叫它页面栈和控件树吧,其实就类似于WINDOWS的窗口系统,建立起树状结构的控件系统。对于每一个页面记录各种状态如焦点控件等。并通过栈维护各页面的层次关系。可以从配置文件或者页面脚本载入页面。比如游戏中的主角属性页面、装备页面等,框架都是一定的,使用的一些图片资源什么的也是一定的,应该写成配置文件,直接从文件读入。
2. 在页面树的基础上实现消息路由
消息的路由机制必须实现。
3. 建立资源管理器及配置管理器
专门的资源管理器用来加载和卸载各种图片、特效、音乐资源。同理配置管理器,管理整个HGE的配置。
4. 定义界面文件格式并使用界面文件生成具体画面,同时配套开发界面编辑器
如使用XML来定义具体界面,界面编辑器生成XML。
在1,2,3,4条满足的情况下,再进行具体游戏功能性的接口开发。甚至应该把1,2,3,4这部分抽成 引擎无关、平台无关的中间层,向下提供移植接口,用HGE来port。&& 那么整个游戏界面部分以上应该是高度可移植的。
HGE 的 gui 工具是个好东西,特别是里面的 hgeGUIObject,要多用。说个要注意的点,官网上面貌似都没给详细说明&&
hgeGUIObject 的 rect 成员是该控件的操作响应作用域&&不是显示的。让一个控件disable只要rect.Set(0,0,0,0)就行了。注意有时控件莫名其妙的不响应鼠标操作了,也可能是这个冲突导致的。这问题曾经让我崩溃的调了半天。。。
总结一下。
HGE完全开源、基于directX,功能较为基础。我觉得很适合个人学习和开发小型游戏,但是如果要做稍微大型的游戏的话,必须将整个UI的调度机制设计、封装好(我觉得这个工作量挺大),然后整以相关的开发工具。
OK,HGE就告一段落。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:286947次
积分:5067
积分:5067
排名:第1866名
原创:202篇
评论:285条
(2)(1)(1)(1)(1)(3)(1)(1)(1)(1)(1)(3)(1)(1)(2)(2)(2)(3)(3)(3)(3)(4)(1)(8)(8)(5)(5)(9)(8)(5)(6)(5)(10)(7)(17)(25)(16)(11)(8)(2)(7)HGE游戏引擎是一个基于directX的游戏引擎,它的渲染及逻辑是基于帧回调的框架模式,其提供一些基本的图像操作和输入控制功能。
项目如图:
fontconv测试代码(参数二:文件路径):
int main(int argc, char* argv[])
WIN32_FIND_DATA
*buf, filename[256];
*newFile, *nextF
printf(&\nHGE Font 1.XX -& 1.6 converter\nCopyright (C) , Relish Games\n\n&);
if(argc!=2)
printf(&Usage: FONTCONV.EXE &wildcard&\n\n&);
printf(&All files found by the specified wildcard will\n&);
printf(&be automatically converted to newer format. Bitmap files\n&);
printf(&should be available along with font description files.\n\n&);
hSearch=FindFirstFile(argv[1], &SearchData);
nextFile=0;
if(hSearch==INVALID_HANDLE_VALUE || done)
FindClose(hSearch);
if(!(SearchData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
strcpy(filename, argv[1]);
buf=strrchr(filename, '\\');
if(!buf) buf= else buf++;
strcpy(buf,SearchData.cFileName);
strcpy(newFile-&filename,filename);
newFile-&next=0;
if(nextFile) nextFile-&next=newF
else files=newF
nextFile=newF
done=!FindNextFile(hSearch, &SearchData);
hge=hgeCreate(HGE_VERSION);
hge-&System_SetState(HGE_USESOUND, false);
hge-&System_SetState(HGE_WINDOWED, true);
hge-&System_SetState(HGE_SCREENWIDTH, 640);
hge-&System_SetState(HGE_SCREENHEIGHT, 480);
if(!hge-&System_Initiate())
hge-&Release();
printf(&\nCan't initiate HGE.\n\n&,nfiles);
while(newFile)
if(convert(newFile-&filename)) nfiles++;
nextFile=newFile-&
delete newF
newFile=nextF
hge-&System_Shutdown();
hge-&Release();
printf(&\n%d file(s) successfully converted.\n\n&,nfiles);
效果如图:
fonted测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
hge = hgeCreate(HGE_VERSION);
hge-&System_SetState(HGE_INIFILE, &fonted.ini&);
hge-&System_SetState(HGE_LOGFILE, &fonted.log&);
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge-&System_SetState(HGE_RENDERFUNC, RenderFunc);
hge-&System_SetState(HGE_TITLE, &HGE Bitmap Font Builder&);
hge-&System_SetState(HGE_SCREENWIDTH, 800);
hge-&System_SetState(HGE_SCREENHEIGHT, 600);
hge-&System_SetState(HGE_SCREENBPP, 32);
hge-&System_SetState(HGE_USESOUND, false);
if(hge-&Ini_GetInt(&HGE&, &FullScreen&,0)) hge-&System_SetState(HGE_WINDOWED, false);
else hge-&System_SetState(HGE_WINDOWED, true);
if(hge-&System_Initiate())
InitEditor();
hge-&System_Start();
DoneEditor();
else MessageBox(NULL, hge-&System_GetErrorMessage(), &Error&, MB_OK | MB_ICONERROR | MB_TASKMODAL);
hge-&System_Shutdown();
hge-&Release();
效果如图:
hge 和hgehelp是引擎动态库!~
particleed测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
hge = hgeCreate(HGE_VERSION);
hge-&System_SetState(HGE_INIFILE, &particleed.ini&);
hge-&System_SetState(HGE_LOGFILE, &particleed.log&);
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge-&System_SetState(HGE_RENDERFUNC, RenderFunc);
hge-&System_SetState(HGE_TITLE, &HGE Particle Systems Editor&);
hge-&System_SetState(HGE_SCREENWIDTH, 800);
hge-&System_SetState(HGE_SCREENHEIGHT, 600);
hge-&System_SetState(HGE_SCREENBPP, 32);
hge-&System_SetState(HGE_USESOUND, false);
if(hge-&Ini_GetInt(&HGE&, &FullScreen&,0)) hge-&System_SetState(HGE_WINDOWED, false);
else hge-&System_SetState(HGE_WINDOWED, true);
if(hge-&System_Initiate())
InitEditor();
hge-&System_Start();
DoneEditor();
else MessageBox(NULL, hge-&System_GetErrorMessage(), &Error&, MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
hge-&System_Shutdown();
hge-&Release();
效果如图:
pngopt测试代码:
int main(int argc, char* argv[])
WIN32_FIND_DATA
*buf, filename[256];
*newFile, *nextF
printf(&\nPNG Optimizer v0.2\nCopyright (C) , Relish Games\n\n&);
if(argc!=2)
printf(&Usage: PNGOPT.EXE &wildcard&\n\n&);
printf(&The image data of all files found by the specified wildcard\n&);
printf(&will be expanded beneath the alpha channel boundary.\n&);
printf(&So images will render without artifacts when scaled, stretched,\n&);
printf(&rotated or rendered into not integer coordinates.\n\n&);
hSearch=FindFirstFile(argv[1], &SearchData);
nextFile=0;
if(hSearch==INVALID_HANDLE_VALUE || done)
FindClose(hSearch);
if(!(SearchData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
strcpy(filename, argv[1]);
buf=strrchr(filename, '\\');
if(!buf) buf= else buf++;
strcpy(buf,SearchData.cFileName);
strcpy(newFile-&filename,filename);
newFile-&next=0;
if(nextFile) nextFile-&next=newF
else files=newF
nextFile=newF
done=!FindNextFile(hSearch, &SearchData);
hge=hgeCreate(HGE_VERSION);
hge-&System_SetState(HGE_USESOUND, false);
hge-&System_SetState(HGE_WINDOWED, true);
hge-&System_SetState(HGE_SCREENWIDTH, 320);
hge-&System_SetState(HGE_SCREENHEIGHT, 200);
hge-&System_SetState(HGE_SHOWSPLASH, false);
if(!hge-&System_Initiate())
hge-&Release();
printf(&\nCan't initiate HGE.\n\n&,nfiles);
while(newFile)
if(convert(newFile-&filename)) nfiles++;
nextFile=newFile-&
delete newF
newFile=nextF
hge-&System_Shutdown();
hge-&Release();
printf(&\n%d image(s) successfully optimized.\n\n&,nfiles);
效果如图(没有参数):
hge_tut01测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
// Here we use global pointer to HGE interface.
// Instead you may use hgeCreate() every
// time you need access to HGE. Just be sure to
// have a corresponding hge-&Release()
// for each call to hgeCreate()
hge = hgeCreate(HGE_VERSION);
// Set our frame function
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
// Set the window title
hge-&System_SetState(HGE_TITLE, &HGE Tutorial 01 - Minimal HGE application&);
// Run in windowed mode
// Default window size is 800x600
hge-&System_SetState(HGE_WINDOWED, true);
// Don't use BASS for sound
hge-&System_SetState(HGE_USESOUND, false);
// Tries to initiate HGE with the states set.
// If something goes wrong, &false& is returned
// and more specific description of what have
// happened can be read with System_GetErrorMessage().
if(hge-&System_Initiate())
// Starts running FrameFunc().
// Note that the execution &stops& here
// until &true& is returned from FrameFunc().
hge-&System_Start();
// If HGE initialization failed show error message
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.
// Restore video mode and free
// all allocated resources
hge-&System_Shutdown();
// Release the HGE interface.
// If there are no more references,
// the HGE object will be deleted.
hge-&Release();
hge_tut02测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
// Get HGE interface
hge = hgeCreate(HGE_VERSION);
// Set up log file, frame function, render function and window title
hge-&System_SetState(HGE_LOGFILE, &hge_tut02.log&);
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge-&System_SetState(HGE_RENDERFUNC, RenderFunc);
hge-&System_SetState(HGE_TITLE, &HGE Tutorial 02 - Using input, sound and rendering&);
// Set up video mode
hge-&System_SetState(HGE_WINDOWED, true);
hge-&System_SetState(HGE_SCREENWIDTH, 800);
hge-&System_SetState(HGE_SCREENHEIGHT, 600);
hge-&System_SetState(HGE_SCREENBPP, 32);
if(hge-&System_Initiate())
// Load sound and texture
snd=hge-&Effect_Load(&menu.wav&);
quad.tex=hge-&Texture_Load(&particles.png&);
if(!snd || !quad.tex)
// If one of the data files is not found, display
// an error message and shutdown.
MessageBox(NULL, &Can't load MENU.WAV or PARTICLES.PNG&, &Error&, MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge-&System_Shutdown();
hge-&Release();
// Set up quad which we will use for rendering sprite
quad.blend=BLEND_ALPHAADD | BLEND_COLORMUL | BLEND_ZWRITE;
for(int i=0;i&4;i++)
// Set up z-coordinate of vertices
quad.v[i].z=0.5f;
// Set up color. The format of DWORD col is 0xAARRGGBB
quad.v[i].col=0xFFFFA000;
// Set up quad's texture coordinates.
// 0,0 means top left corner and 1,1 -
// bottom right corner of the texture.
quad.v[0].tx=96.0/128.0; quad.v[0].ty=64.0/128.0;
quad.v[1].tx=128.0/128.0; quad.v[1].ty=64.0/128.0;
quad.v[2].tx=128.0/128.0; quad.v[2].ty=96.0/128.0;
quad.v[3].tx=96.0/128.0; quad.v[3].ty=96.0/128.0;
// Let's rock now!
hge-&System_Start();
// Free loaded texture and sound
hge-&Texture_Free(quad.tex);
hge-&Effect_Free(snd);
else MessageBox(NULL, hge-&System_GetErrorMessage(), &Error&, MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
// Clean up and shutdown
hge-&System_Shutdown();
hge-&Release();
效果如图(鼠标可以操作中间的圈圈):
hge_tut03测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
hge = hgeCreate(HGE_VERSION);
hge-&System_SetState(HGE_LOGFILE, &hge_tut03.log&);
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge-&System_SetState(HGE_RENDERFUNC, RenderFunc);
hge-&System_SetState(HGE_TITLE, &HGE Tutorial 03 - Using helper classes&);
hge-&System_SetState(HGE_FPS, 100);
hge-&System_SetState(HGE_WINDOWED, true);
hge-&System_SetState(HGE_SCREENWIDTH, 800);
hge-&System_SetState(HGE_SCREENHEIGHT, 600);
hge-&System_SetState(HGE_SCREENBPP, 32);
if(hge-&System_Initiate()) {
// Load sound and texture
snd=hge-&Effect_Load(&menu.wav&);
tex=hge-&Texture_Load(&particles.png&);
if(!snd || !tex)
// If one of the data files is not found, display
// an error message and shutdown.
MessageBox(NULL, &Can't load one of the following files:\nMENU.WAV, PARTICLES.PNG, FONT1.FNT, FONT1.PNG, TRAIL.PSI&, &Error&, MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge-&System_Shutdown();
hge-&Release();
// Create and set up a sprite
spr=new hgeSprite(tex, 96, 64, 32, 32);
spr-&SetColor(0xFFFFA000);
spr-&SetHotSpot(16,16);
// Load a font
fnt=new hgeFont(&font1.fnt&);
// Create and set up a particle system
spt=new hgeSprite(tex, 32, 32, 32, 32);
spt-&SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);
spt-&SetHotSpot(16,16);
par=new hgeParticleSystem(&trail.psi&,spt);
par-&Fire();
// Let's rock now!
hge-&System_Start();
// Delete created objects and free loaded resources
hge-&Texture_Free(tex);
hge-&Effect_Free(snd);
// Clean up and shutdown
hge-&System_Shutdown();
hge-&Release();
效果如图(影艳):
hge_tut04测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
hge = hgeCreate(HGE_VERSION);
hge-&System_SetState(HGE_LOGFILE, &hge_tut04.log&);
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge-&System_SetState(HGE_RENDERFUNC, RenderFunc);
hge-&System_SetState(HGE_GFXRESTOREFUNC, GfxRestoreFunc);
hge-&System_SetState(HGE_TITLE, &HGE Tutorial 04 - Using render targets&);
hge-&System_SetState(HGE_FPS, 100);
hge-&System_SetState(HGE_WINDOWED, true);
hge-&System_SetState(HGE_SCREENWIDTH, 800);
hge-&System_SetState(HGE_SCREENHEIGHT, 600);
hge-&System_SetState(HGE_SCREENBPP, 32);
if(hge-&System_Initiate()) {
snd=hge-&Effect_Load(&menu.wav&);
tex=hge-&Texture_Load(&particles.png&);
if(!snd || !tex)
// If one of the data files is not found, display
// an error message and shutdown.
MessageBox(NULL, &Can't load one of the following files:\nMENU.WAV, PARTICLES.PNG, FONT1.FNT, FONT1.PNG, TRAIL.PSI&, &Error&, MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge-&System_Shutdown();
hge-&Release();
spr=new hgeSprite(tex, 96, 64, 32, 32);
spr-&SetColor(0xFFFFA000);
spr-&SetHotSpot(16,16);
fnt=new hgeFont(&font1.fnt&);
spt=new hgeSprite(tex, 32, 32, 32, 32);
spt-&SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);
spt-&SetHotSpot(16,16);
par=new hgeParticleSystem(&trail.psi&,spt);
par-&Fire();
// Create a render target and a sprite for it
target=hge-&Target_Create(512,512,false);
tar=new hgeSprite(hge-&Target_GetTexture(target),0,0,512,512);
tar-&SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);
// Let's rock now!
hge-&System_Start();
// Delete created objects and free loaded resources
hge-&Target_Free(target);
hge-&Texture_Free(tex);
hge-&Effect_Free(snd);
// Clean up and shutdown
hge-&System_Shutdown();
hge-&Release();
效果如图:
hge_tut05测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
hge = hgeCreate(HGE_VERSION);
hge-&System_SetState(HGE_LOGFILE, &hge_tut05.log&);
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge-&System_SetState(HGE_RENDERFUNC, RenderFunc);
hge-&System_SetState(HGE_TITLE, &HGE Tutorial 05 - Using distortion mesh&);
hge-&System_SetState(HGE_WINDOWED, true);
hge-&System_SetState(HGE_SCREENWIDTH, 800);
hge-&System_SetState(HGE_SCREENHEIGHT, 600);
hge-&System_SetState(HGE_SCREENBPP, 32);
hge-&System_SetState(HGE_USESOUND, false);
if(hge-&System_Initiate()) {
// Load sound and texture
tex=hge-&Texture_Load(&texture.jpg&);
// If one of the data files is not found, display
// an error message and shutdown.
MessageBox(NULL, &Can't load TEXTURE.JPG&, &Error&, MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge-&System_Shutdown();
hge-&Release();
// Create a distortion mesh
dis=new hgeDistortionMesh(nCols, nRows);
dis-&SetTexture(tex);
dis-&SetTextureRect(0,0,512,512);
dis-&SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_ZWRITE);
dis-&Clear(0xFF000000);
// Load a font
fnt=new hgeFont(&font1.fnt&);
// Let's rock now!
hge-&System_Start();
// Delete created objects and free loaded resources
hge-&Texture_Free(tex);
// Clean up and shutdown
hge-&System_Shutdown();
hge-&Release();
效果如图(图片有波动):
hge_tut06测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
hge = hgeCreate(HGE_VERSION);
hge-&System_SetState(HGE_LOGFILE, &hge_tut06.log&);
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge-&System_SetState(HGE_RENDERFUNC, RenderFunc);
hge-&System_SetState(HGE_TITLE, &HGE Tutorial 06 - Creating menus&);
hge-&System_SetState(HGE_WINDOWED, true);
hge-&System_SetState(HGE_SCREENWIDTH, 800);
hge-&System_SetState(HGE_SCREENHEIGHT, 600);
hge-&System_SetState(HGE_SCREENBPP, 32);
if(hge-&System_Initiate())
// Load sound and textures
quad.tex=hge-&Texture_Load(&bg.png&);
tex=hge-&Texture_Load(&cursor.png&);
snd=hge-&Effect_Load(&menu.wav&);
if(!quad.tex || !tex || !snd)
// If one of the data files is not found, display
// an error message and shutdown.
MessageBox(NULL, &Can't load BG.PNG, CURSOR.PNG or MENU.WAV&, &Error&, MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge-&System_Shutdown();
hge-&Release();
// Set up the quad we will use for background animation
quad.blend=BLEND_ALPHABLEND | BLEND_COLORMUL | BLEND_NOZWRITE;
for(int i=0;i&4;i++)
// Set up z-coordinate of vertices
quad.v[i].z=0.5f;
// Set up color. The format of DWORD col is 0xAARRGGBB
quad.v[i].col=0xFFFFFFFF;
quad.v[0].x=0; quad.v[0].y=0;
quad.v[1].x=800; quad.v[1].y=0;
quad.v[2].x=800; quad.v[2].y=600;
quad.v[3].x=0; quad.v[3].y=600;
// Load the font, create the cursor sprite
fnt=new hgeFont(&font1.fnt&);
spr=new hgeSprite(tex,0,0,32,32);
// Create and initialize the GUI
gui=new hgeGUI();
gui-&AddCtrl(new hgeGUIMenuItem(1,fnt,snd,400,200,0.0f,&Play&));
gui-&AddCtrl(new hgeGUIMenuItem(2,fnt,snd,400,240,0.1f,&Options&));
gui-&AddCtrl(new hgeGUIMenuItem(3,fnt,snd,400,280,0.2f,&Instructions&));
gui-&AddCtrl(new hgeGUIMenuItem(4,fnt,snd,400,320,0.3f,&Credits&));
gui-&AddCtrl(new hgeGUIMenuItem(5,fnt,snd,400,360,0.4f,&Exit&));
gui-&SetNavMode(HGEGUI_UPDOWN | HGEGUI_CYCLED);
gui-&SetCursor(spr);
gui-&SetFocus(1);
gui-&Enter();
// Let's rock now!
hge-&System_Start();
// Delete created objects and free loaded resources
hge-&Effect_Free(snd);
hge-&Texture_Free(tex);
hge-&Texture_Free(quad.tex);
// Clean up and shutdown
hge-&System_Shutdown();
hge-&Release();
效果如图:
hge_tut07测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
hge = hgeCreate(HGE_VERSION);
// Set desired system states and initialize HGE
hge-&System_SetState(HGE_LOGFILE, &hge_tut07.log&);
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge-&System_SetState(HGE_RENDERFUNC, RenderFunc);
hge-&System_SetState(HGE_TITLE, &HGE Tutorial 07 - Thousand of Hares&);
hge-&System_SetState(HGE_USESOUND, false);
hge-&System_SetState(HGE_WINDOWED, true);
hge-&System_SetState(HGE_SCREENWIDTH, SCREEN_WIDTH);
hge-&System_SetState(HGE_SCREENHEIGHT, SCREEN_HEIGHT);
hge-&System_SetState(HGE_SCREENBPP, 32);
if(hge-&System_Initiate())
// Load textures
bgtex=hge-&Texture_Load(&bg2.png&);
tex=hge-&Texture_Load(&zazaka.png&);
if(!bgtex || !tex)
// If one of the data files is not found,
// display an error message and shutdown
MessageBox(NULL, &Can't load BG2.PNG or ZAZAKA.PNG&, &Error&, MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge-&System_Shutdown();
hge-&Release();
// Load font, create sprites
fnt=new hgeFont(&font2.fnt&);
spr=new hgeSprite(tex,0,0,64,64);
spr-&SetHotSpot(32,32);
bgspr=new hgeSprite(bgtex,0,0,800,600);
bgspr-&SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE);
bgspr-&SetColor(0xFF);
bgspr-&SetColor(0xFF);
bgspr-&SetColor(0xFF);
bgspr-&SetColor(0xFF);
// Initialize objects list
pObjects=new sprObject[MAX_OBJECTS];
nObjects=1000;
for(i=0;i&MAX_OBJECTS;i++)
pObjects[i].x=hge-&Random_Float(0,SCREEN_WIDTH);
pObjects[i].y=hge-&Random_Float(0,SCREEN_HEIGHT);
pObjects[i].dx=hge-&Random_Float(-200,200);
pObjects[i].dy=hge-&Random_Float(-200,200);
pObjects[i].scale=hge-&Random_Float(0.5f,2.0f);
pObjects[i].dscale=hge-&Random_Float(-1.0f,1.0f);
pObjects[i].rot=hge-&Random_Float(0,M_PI*2);
pObjects[i].drot=hge-&Random_Float(-1.0f,1.0f);
SetBlend(0);
// Let's rock now!
hge-&System_Start();
// Delete created objects and free loaded resources
delete[] pO
hge-&Texture_Free(tex);
hge-&Texture_Free(bgtex);
// Clean up and shutdown
hge-&System_Shutdown();
hge-&Release();
效果如图:
hge_tut08测试代码:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
hge = hgeCreate(HGE_VERSION);
// Set desired system states and initialize HGE
hge-&System_SetState(HGE_LOGFILE, &hge_tut08.log&);
hge-&System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge-&System_SetState(HGE_RENDERFUNC, RenderFunc);
hge-&System_SetState(HGE_TITLE, &HGE Tutorial 08 - The Big Calm&);
hge-&System_SetState(HGE_USESOUND, false);
hge-&System_SetState(HGE_WINDOWED, true);
hge-&System_SetState(HGE_SCREENWIDTH, SCREEN_WIDTH);
hge-&System_SetState(HGE_SCREENHEIGHT, SCREEN_HEIGHT);
hge-&System_SetState(HGE_SCREENBPP, 32);
if(hge-&System_Initiate())
fnt=new hgeFont(&font2.fnt&);
if(!InitSimulation())
// If one of the data files is not found, display an error message and shutdown
MessageBox(NULL, &Can't load resources. See log for details.&, &Error&, MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge-&System_Shutdown();
hge-&Release();
hge-&System_Start();
DoneSimulation();
hge-&System_Shutdown();
hge-&Release();
效果如图:
学习的目标是成熟!~~~~
&此文从网络中自动搜索生成,不代表本网站赞成被搜索网站的内容或立场
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&
软件世界网- &2014 蜀ICP备号 三峰网旗下网站

我要回帖

更多关于 hge引擎下载 的文章

 

随机推荐