首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

函数调用有关问题,求解拿分

2012-04-30 
函数调用问题,求解拿分[codeC/C++][/code]//必须包含的一些头文件//提供HGE的底层接口操作#include hge.

函数调用问题,求解拿分
[code=C/C++][/code]//必须包含的一些头文件
//提供HGE的底层接口操作
#include "hge.h"
// HGE精灵类

#include "hgesprite.h"
// HGE字体类,用于显示文字信息

#include "hgefont.h"
// HGE粒子类
#include "hgeparticle.h"
// 全局的HGE接口类指针

HGE* hge=NULL;

// 全局的HGE对象指针
// HGE精灵,spr为图示中的小球,spt则为粒子(图示中的小五角星)
hgeSprite* spr = NULL;
hgeSprite* spt = NULL;

// HGE字体类,用于显示图示中左上角的帧率信息
hgeFont* fnt = NULL;

// 用以管理粒子生成与消亡的hgeParticleSystem类
hgeParticleSystem* par = NULL;

// HGE资源句柄(实际上即是DWORD类型)
// 纹理句柄;
HTEXTURE tex;
// 声效句柄;
HEFFECT snd;

// 一些全局的变量信息;
// x、y 为小球的当前位置坐标;
float x=100.0f, y=100.0f;

// dx、dy为小球的位置改变(偏移)量;
float dx=0.0f, dy=0.0f;

//小球的速度;
const float speed=90;

//摩擦系数,用以削减小球的实际位移量;
const float friction=0.98f;

// 播放声效;
void boom() {
//设置声道;
int pan=int((x-400)/4);
//设置音高;
float pitch=(dx*dx+dy*dy)*0.0005f+0.2f;
//播放( 具体细节请参见HGE帮助文档 :)下同 );
hge->Effect_PlayEx(snd,100,pan,pitch);
}
//帧函数(HGE应用程序必须编写并设置该函数)
bool FrameFunc()

{
// 获得时间改变量;
float dt=hge->Timer_GetDelta();

// 处理按键;
if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;

if (hge->Input_GetKeyState(HGEK_LEFT)) dx-=speed*dt;

if (hge->Input_GetKeyState(HGEK_RIGHT)) dx+=speed*dt;

if (hge->Input_GetKeyState(HGEK_UP)) dy-=speed*dt;

if (hge->Input_GetKeyState(HGEK_DOWN)) dy+=speed*dt;

// 执行位移量的计算和碰撞检测(防止小球越界);  
dx*=friction;
dy*=friction; 
x+=dx; 
y+=dy;

if(x>784) {x=784-(x-784);dx=-dx;boom();}

if(x<16) {x=16+16-x;dx=-dx;boom();}

if(y>584) {y=584-(y-584);dy=-dy;boom();}

if(y<16) {y=16+16-y;dy=-dy;boom();}
// 更新粒子系统;
par->info.nEmission=(int)(dx*dx+dy*dy)*2;
par->MoveTo(x,y);
par->Update(dt);
return false;
}
//渲染函数;
bool RenderFunc()
{
//渲染图形;
//开始渲染场景;
hge->Gfx_BeginScene();
//以黑色(0)清屏;
hge->Gfx_Clear(0xFF000000);
//渲染粒子系统;
par->Render();
//渲染小球;
spr->Render(x, y);
//输出信息;
fnt->printf(5, 5, HGETEXT_LEFT, "dt:%.3f/nFPS:%d (constant)", 
hge->Timer_GetDelta(), hge->Timer_GetFPS());
//结束渲染场景;
hge->Gfx_EndScene();
return false;
}
//标准WinMain函数;

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{//创建Engine接口;
hge = hgeCreate(HGE_VERSION);

//生成日志;
hge->System_SetState(HGE_LOGFILE, "Game.log");

//设置回调;
hge->System_SetState(HGE_FRAMEFUNC,FrameFunc);
hge->System_SetState(HGE_RENDERFUNC,RenderFunc);

//设置窗口标题;
hge->System_SetState(HGE_TITLE, "MyHGEDemo4");

//设置最大FPS;
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);

//使用声音资源;
hge->System_SetState(HGE_USESOUND, true);

//Engine初始化;
if(hge->System_Initiate())
{
// 加载声音及纹理;
snd=hge->Effect_Load("020music.mp3");
if(!snd)
{
// 如果其中一项加载失败则报告错误并关闭HGE;
// 简单的MessageBox信息框;
MessageBox(NULL, "Can't load sound",
"Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge->System_Shutdown();
hge->Release();
return 0;
}

tex=hge->Texture_Load("G.png");


if(!tex)
{
// 如果其中一项加载失败则报告错误并关闭HGE;
// 简单的MessageBox信息框;
MessageBox(NULL, "Can't load G.png",
"Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge->System_Shutdown();
hge->Release();
return 0;
}

spr=new hgeSprite(tex, 96, 64, 32, 32);

spr->SetColor(0xFFFFA000);

spr->SetHotSpot(16,16);



// 加载字体

fnt=new hgeFont("font1.fnt");



// 创建并设置HGE粒子类

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();

hge->System_Start();
}
// 删除创建的对象并释放加载的资源;
delete par;
delete fnt;
delete spt;
delete spr;

hge->Texture_Free(tex);

hge->Effect_Free(snd);

// 关闭HGE;

hge->System_Shutdown();

hge->Release();

return 0;
}


http://blog.csdn.net/tkokof1/article/details/4930982
这上面的一个例子,为什么调试能通过,运行时就会出错呢?

[解决办法]
你确定你调试能通过??运行的时候是什么错误??运行的是Release版本吗??
[解决办法]
附上错误,附上错误代码。。。

热点排行