📄 tankfighter.cpp
字号:
#include "Tank.h"
#include "Globe.h"
bool isFull = false;
HGE *hge=0;
hgeSprite *spt;
hgeFont *fnt;
hgeParticleSystem *par;
// Handles for HGE resourcces
HTEXTURE tex;
HEFFECT snd;
// Play sound effect
void boom() {
// int pan=int((x-400)/4);
// float pitch=(dx*dx+dy*dy)*0.0005f+0.2f;
// hge->Effect_PlayEx(snd,100,pan,pitch);
}
bool FrameFunc()
{
float dt=hge->Timer_GetDelta();
// Process keys
if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;
if (hge->Input_GetKeyState(HGEK_ALT) && hge->Input_GetKeyState(HGEK_ENTER) && isFull == false)
{
hge->System_SetState(HGE_WINDOWED, false);
isFull = true;
}
else if(hge->Input_GetKeyState(HGEK_ALT) && hge->Input_GetKeyState(HGEK_ENTER) && isFull == true)
{
hge->System_SetState(HGE_WINDOWED, true);
isFull = false;
}
if (hge->Input_GetKeyState(HGEK_A)) ptank->Move(4,dt);
if (hge->Input_GetKeyState(HGEK_D)) ptank->Move(2,dt);
if (hge->Input_GetKeyState(HGEK_W)) ptank->Move(1,dt);
if (hge->Input_GetKeyState(HGEK_S)) ptank->Move(3,dt);
// Do some movement calculations and collision detection
ptank->Forward();
/*
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();}
*/
// Update particle system
/* par->info.nEmission=(int)(dx*dx+dy*dy)*2;
par->MoveTo(x,y);
par->Update(dt);
*/
return false;
}
bool RenderFunc()
{
// Render graphics
hge->Gfx_BeginScene();
hge->Gfx_Clear(0);
//par->Render();
ptank->Draw();
fnt->printf(5, 5, HGETEXT_LEFT, "dt:%.3f\nFPS:%d (constant)", hge->Timer_GetDelta(), hge->Timer_GetFPS());
hge->Gfx_EndScene();
return false;
}
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, "Tank Fighter");
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);
ptank = new CTank(100.0,100.0,8,0.98f);
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();
return 0;
}
// Create and set up a sprite
ptank->tank_spr = new hgeSprite(tex, 96, 96, 32, 32);
ptank->tank_spr->SetColor(0xFFFFA000);
ptank->tank_spr->SetHotSpot(16,16);
// Load a font
fnt=new hgeFont("font2.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
delete fnt;
// delete spt;
delete ptank->tank_spr;
delete ptank;
hge->Texture_Free(tex);
hge->Effect_Free(snd);
}
// Clean up and shutdown
hge->System_Shutdown();
hge->Release();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -