Код:
#include "..\..\include\hge.h"
#include "..\..\include\hgefont.h"
#include "GameObjects.h"
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define MIN_OBJECTS 1
#define MAX_OBJECTS 8000
CObject *Object;
struct sprObject
{
float x,y;
float dx,dy;
float scale,rot;
float dscale,drot;
DWORD color;
};
sprObject* pObjects;
int nObjects;
int nBlend;
// Pointer to the HGE interface (helper classes require this to work)
HGE *hge=0;
// Resource handles
HTEXTURE tex, bgtex;
hgeSprite *spr, *bgspr, *spr2;
hgeFont *fnt;
// Set up blending mode for the scene
bool FrameFunc()
{
float dt=hge->Timer_GetDelta();
float f= 0.0f;
// Process keys
if ( hge->Input_GetKey() == HGEK_UP )
for (int i=0; i < 100; i++)
{
f += 0.01;
Object->x += 0.1+f;
}
switch(hge->Input_GetKey())
{
case HGEK_DOWN: Object->x -= 1.7; break;
case HGEK_ESCAPE: return true;
}
return false;
}
bool RenderFunc()
{
int i;
// Render the scene
hge->Gfx_BeginScene();
bgspr->RenderEx(0,0, 0.0, 1.5, 1.5);
//spr2->Render(100, 100);
Object->Draw();
for(i=0;i<nObjects;i++)
{
spr->SetColor(pObjects[i].color);
spr->RenderEx(pObjects[i].x, pObjects[i].y, pObjects[i].rot, pObjects[i].scale);
}
fnt->SetScale(2.0);
fnt->printf(7, 7, HGETEXT_LEFT, "UP and DOWN to adjust number of hares: %d\nSPACE to change blending mode: %d\nFPS: %d",
nObjects, nBlend, hge->Timer_GetFPS());
hge->Gfx_EndScene();
return false;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
int i;
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, "Test Game!!!");
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);
//hge->System_SetState(HGE_FPS, 70);
hge->System_SetState(HGE_SHOWSPLASH, false);
if(hge->System_Initiate())
{
// Load textures
bgtex = hge->Texture_Load("bg2.png");
tex=hge->Texture_Load("PM_1.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();
return 0;
}
// Load font, create sprites
fnt=new hgeFont("font2.fnt");
spr=new hgeSprite(tex,0,0,334,200);
spr2= new hgeSprite(tex,0,0,334,200);
spr->SetHotSpot(32, 32);
bgspr=new hgeSprite(bgtex,0,0,800,600);
bgspr->SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE);
bgspr->SetColor(0xFF0000FF,0);
bgspr->SetColor(0xFFFF0000,1);
bgspr->SetColor(0xFF000040,2);
bgspr->SetColor(0xFF000040,3);
// Initialize objects list
pObjects=new sprObject[MAX_OBJECTS];
nObjects=10;
Object = new CObject(tex);
// Let's rock now!
hge->System_Start();
// Delete created objects and free loaded resources
delete[] pObjects;
delete fnt;
delete spr;
delete bgspr;
hge->Texture_Free(tex);
hge->Texture_Free(bgtex);
}
// Clean up and shutdown
hge->System_Shutdown();
hge->Release();
return 0;
}