Example #1
0
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	hge = hgeCreate(HGE_VERSION);

	hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
	hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
	hge->System_SetState(HGE_USESOUND, false);
	hge->System_SetState(HGE_TITLE, "KW");

	int w = 0;
	int h = 0;
	bool mode = false;

	std::ifstream f("options.cfg", std::ios::binary);
	
	if (f.is_open())
	{
		f.read((char *)&w, sizeof(int));
		f.read((char *)&h, sizeof(int));
		f.read((char *)&mode, sizeof(bool));
		f.close();
	}

	if (w != 0 && h != 0)
	{
		SCREEN_WIDTH = w;
		SCREEN_HEIGHT = h;
		WINDOWED = mode;
	}
			
	

	hge->System_SetState(HGE_WINDOWED, WINDOWED);
	hge->System_SetState(HGE_SCREENWIDTH, SCREEN_WIDTH);
	hge->System_SetState(HGE_SCREENHEIGHT, SCREEN_HEIGHT);
	hge->System_SetState(HGE_SCREENBPP, 32);
	hge->System_SetState(HGE_LOGFILE, "debug.log");
	hge->System_SetState(HGE_DONTSUSPEND, true);

	//hge->System_SetState(HGE_FPS, 40);

	if(hge->System_Initiate())
	{
		resource_manager = CreateResourceManager();
		resource_manager->ChangeScript("resource.rs");

		mouse_cursor = resource_manager->GetSprite("target");
		text = resource_manager->GetFont("font2");
		hard = new hgeAnimation( *(resource_manager->GetAnimation( "hard" )) );
		hard->Play();

		InitiateGUI1();

		world = InitiateWorld();

		hge->System_Start();
	}

	delete hard;
	delete world;

	delete mouse_cursor;

	delete gui;
	
	hge->System_Shutdown();
	hge->Release();

	HANDLE mutex;

	mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NAME_MUTEX1);
	CloseHandle(mutex);

	mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NAME_MUTEX2);
	CloseHandle(mutex);

	return 0;
}
Example #2
0
hgeParticleSystem::hgeParticleSystem(const hgeParticleSystem &ps)
{
	memcpy(this, &ps, sizeof(hgeParticleSystem));
	hge=hgeCreate(HGE_VERSION);
}
Example #3
0
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
#endif
{
	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, "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
#ifdef PLATFORM_UNIX
			fprintf(stderr, "Error: Can't load bg2.png or zazaka.png\n");
#else
			MessageBox(NULL, "Can't load bg2.png or zazaka.png", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
#endif
			hge->System_Shutdown();
			hge->Release();
			return 0;
		}

		// 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(0xFF000000,0);
		bgspr->SetColor(0xFF000000,1);
		bgspr->SetColor(0xFF000040,2);
		bgspr->SetColor(0xFF000040,3);

		// 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[] 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;
}
Example #4
0
hgeStringTable::hgeStringTable(const char *filename)
{
	int i;
	void *data;
	DWORD size;
	char *desc, *pdesc;
	NamedString *str;
	char str_name[MAXSTRNAMELENGTH];
	char *str_value, *pvalue;
	
	hge=hgeCreate(HGE_VERSION);
	strings=0;

	// load string table file
	data=hge->Resource_Load(filename, &size);
	if(!data) return;

	desc = new char[size+1];
	memcpy(desc,data,size);
	desc[size]=0;
	hge->Resource_Free(data);

	// check header
	if(memcmp(desc, STRHEADERTAG, sizeof(STRHEADERTAG)-1))
	{
		hge->System_Log(STRFORMATERROR, filename);
		delete[] desc;	
		return;
	}

	pdesc=desc+sizeof(STRHEADERTAG);
	str_value=new char[8192];

	for(;;)
	{
		// skip whitespaces
		while(isspace(*pdesc)) pdesc++;
		if(!*pdesc) break;

		// skip comments
		if(*pdesc==';')
		{
			while(*pdesc && *pdesc != '\n') pdesc++;
			pdesc++;
			continue;
		}

		// get string name -> str_name
		i=0;
		while(pdesc[i] && pdesc[i]!='=' && !isspace(pdesc[i]) && i<MAXSTRNAMELENGTH)
		{
			str_name[i]=pdesc[i];
			i++;
		}
		str_name[i]=0;
		pdesc+=i;

		// skip string name overflow characters
		while(*pdesc && *pdesc!='=' && !isspace(*pdesc)) pdesc++;
		if(!*pdesc) break;

		// skip whitespaces to '='
		while(isspace(*pdesc)) pdesc++;
		if(*pdesc!='=')	{ hge->System_Log(STRFORMATERROR, filename); break; }
		pdesc++;

		// skip whitespaces to '"'
		while(isspace(*pdesc)) pdesc++;
		if(*pdesc!='"')	{ hge->System_Log(STRFORMATERROR, filename); break;	}
		pdesc++;

		// parse string value till the closing '"' -> str_value
		// consider: \", \n, \\, LF, CR, whitespaces at line begin/end
		pvalue=str_value;

		while(*pdesc && *pdesc!='"')
		{
			if(*pdesc=='\n' || *pdesc=='\r')
			{
				while(isspace(*pdesc)) pdesc++;

				pvalue--;
				while(pvalue>=str_value && isspace(*pvalue)) pvalue--;
				pvalue++; *pvalue=' '; pvalue++;

				continue;
			}

			if(*pdesc=='\\')
			{
				pdesc++;
				if(!*pdesc) continue;
				if(*pdesc=='n') *pvalue='\n';
				else *pvalue=*pdesc;
				pvalue++;
				pdesc++;
				continue;
			}

			*pvalue=*pdesc; pvalue++;
			pdesc++;
		}

		*pvalue=0;

		// add the parsed string to the list
		str=new NamedString;
		strcpy(str->name, str_name);
		str->string=new char[strlen(str_value)+1];
		strcpy(str->string, str_value);
		str->next=strings;
		strings=str;

		if(!*pdesc) break;
		pdesc++;
	}

	delete[] str_value;
	delete[] desc;
}
Example #5
0
//初始化
void VideoManager::Init()
{
  m_phge = hgeCreate(HGE_VERSION);
  m_hwnd = m_phge->System_GetState(HGE_HWND);    
}
Example #6
0
hgeSprite::hgeSprite(const hgeSprite &spr)
{
	memcpy(this, &spr, sizeof(hgeSprite));
	hge=hgeCreate(HGE_VERSION);
}
Example #7
0
 HGEImage::HGEImage(HTEXTURE texture, bool autoFree)
     : mTexture(texture),
       mAutoFree(autoFree)
 {
     mHGE = hgeCreate(HGE_VERSION);
 }
bool BApp::OnInit(void)
{
	// create pointer to HGE's interface
	hge = hgeCreate(HGE_VERSION);

	// set HGE's system states, most of them are default
	hge->System_SetState(HGE_FRAMEFUNC, static_OnLoop);		// set frame function
	hge->System_SetState(HGE_RENDERFUNC, static_OnRender);	// set rendering function
	hge->System_SetState(HGE_WINDOWED, true);				// windowed/fullscreen mode
	hge->System_SetState(HGE_USESOUND, true);				// enable/disable sounds
	hge->System_SetState(HGE_FPS, HGEFPS_VSYNC);			// vsync
	hge->System_SetState(HGE_TITLE, "Black Bird");			// window title

	// initialize HGE's with set system states
	if(hge->System_Initiate())
	{
		// initialize music
		b_eBGMusic0			= hge->Effect_Load("snd/deep_space.ogg");
		b_eBGMusic1			= hge->Effect_Load("snd/space_ambient.ogg");
		b_eBGMusic2			= hge->Effect_Load("snd/ambiance_space.ogg");
		b_eSFXGunshot		= hge->Effect_Load("snd/gun_shot.ogg");
		b_eSFXExplosion		= hge->Effect_Load("snd/explosion.aif");

		hge->Effect_PlayEx(b_eBGMusic0,  40, 0, 0, true);
		hge->Effect_PlayEx(b_eBGMusic1, 100, 0, 0, true);
		hge->Effect_PlayEx(b_eBGMusic2,  10, 0, 0, true);

		// initialize player
		b_pPlayerOne		= new BPlayer(hgeVector(10, 268), hgeVector(5, 0));

		// initialize bullets
		b_tBullet			= hge->Texture_Load("img/bullet.png");

		// initialize enemies
		b_tEColors[0]		= hge->Texture_Load("img/eSpritesheet_40x30.png");
		b_tEColors[1]		= hge->Texture_Load("img/eSpritesheet_40x30_hue1.png");
		b_tEColors[2]		= hge->Texture_Load("img/eSpritesheet_40x30_hue2.png");
		b_tEColors[3]		= hge->Texture_Load("img/eSpritesheet_40x30_hue3.png");
		b_tEColors[4]		= hge->Texture_Load("img/eSpritesheet_40x30_hue4.png");

		// initialize backgrounds
		b_tBackground		= hge->Texture_Load("img/farback.jpg");
		b_tStars			= hge->Texture_Load("img/starfield.png");
		b_tBGGapFix			= hge->Texture_Load("img/bg_gapfix.jpg");

			// subtle way to duplicate the background using them as tiles themselves
			b_sBackground	= new hgeSprite(b_tBackground, 0, 0, 1782, 600);
			b_sStars		= new hgeSprite(b_tStars,      0, 0,  800, 600);
			b_sBGGapFix		= new hgeSprite(b_tBGGapFix,   0, 0,   64, 600);
		
		// position of the background is set on the right side and also scrolls to right
		// backgroudnd is 1782px width and window is 800px.
		// 800 - 1782 = -982;
		b_vBGPosition		= hgeVector(-982, 0);	

		// start game loop
		hge->System_Start();
	}
	else
	{
		MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
		return false;
	}

	return true;
}
Example #9
0
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, 60);
    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();
            return 0;
        }

        // 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
        delete par;
        delete fnt;
        delete spt;
        delete spr;
        hge->Texture_Free(tex);
        hge->Effect_Free(snd);
    } else {
        char *msg = hge->System_GetErrorMessage();

    }

    // Clean up and shutdown
    hge->System_Shutdown();
    hge->Release();
    return 0;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	_pHGE = hgeCreate(HGE_VERSION);
	
	_pHGE ->System_SetState(HGE_FRAMEFUNC, FrameFunc);
	_pHGE->System_SetState(HGE_TITLE, "Eucrectica");

	_pHGE->System_SetState(HGE_WINDOWED, true);
	_pHGE->System_SetState(HGE_USESOUND, true);


	_pHGE->System_SetState(HGE_LOGFILE, "Eucrectica.log");
	_pHGE->System_SetState(HGE_RENDERFUNC, RenderFunc);
	_pHGE->System_SetState(HGE_FPS, 60);
	_pHGE->System_SetState(HGE_WINDOWED, true);
	_pHGE->System_SetState(HGE_SCREENWIDTH, 800);
	_pHGE->System_SetState(HGE_SCREENHEIGHT, 600);
	_pHGE->System_SetState(HGE_SCREENBPP, 32);
	
	
	// 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(_pHGE->System_Initiate())
	{
		_Renderer.Init( _pHGE, "../Content/Sprites/");
		_Renderer.LoadSprite( "Mud_Tiles.png", Maths::Vector<2>(128, 128) );
		int x = _Renderer.LoadAnimation( "Walk_Second_128.png", Maths::Vector<2>(128, 256), 1000, true );
		_Renderer.LoadFont( "font1.fnt" );

		_Input.Init( _pHGE );

		// Starts running FrameFunc().
		// Note that the execution "stops" here
		// until "true" is returned from FrameFunc().
		_pHGE->System_Start();
	}
	else
	{	
		// If HGE initialization failed show error message
		MessageBox(NULL, _pHGE->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
	}

	// Now ESC has been pressed or the user
	// has closed the window by other means.
	_Renderer.Destroy();
	// Restore video mode and free
	// all allocated resources
	_pHGE->System_Shutdown();

	// Release the HGE interface.
	// If there are no more references,
	// the HGE object will be deleted.
	_pHGE->Release();

#ifdef _DEBUG
	_CrtDumpMemoryLeaks();
#endif
	
	return 0;
}
Example #11
0
	HgeObj &operator = ( const HgeObj &o ) {
		hge = hgeCreate( HGE_VERSION );
		return *this;
	}
Example #12
0
	HgeObj( const HgeObj &o ) {
		hge = hgeCreate( HGE_VERSION );
	}
Example #13
0
	HgeObj() {
		hge = hgeCreate( HGE_VERSION );
	}
Example #14
0
void OUMapTableImg::InitAll()
{
    m_pHGE = hgeCreate(HGE_VERSION);
}
Example #15
0
hgeGUIObject::hgeGUIObject()
{
	g_hgeguiobject_hge = hgeCreate(HGE_VERSION);
	m_color = hge::COLOR_WHITE;
}
FlashSprite::FlashSprite(void)
{
	m_pHGE = hgeCreate(HGE_VERSION);
	m_pFlashPlayer = 0;
	memset(&m_FlashQuad,0,sizeof(m_FlashQuad));
}
Example #17
0
hgeFont::hgeFont(const char *szFont, bool bMipmap)
{
	void	*data;
	hgeU32	size;
	char	*desc, *pdesc;
	char	linebuf[256];
	char	buf[MAX_PATH], *pbuf;
	char	chr;
	int		i, x, y, w, h, a, c;

	// Setup variables
	
	hge=hgeCreate(HGE_VERSION);

	fHeight=0.0f;
	fScale=1.0f;
	fProportion=1.0f;
	fRot=0.0f;
	fTracking=0.0f;
	fSpacing=1.0f;
	hTexture=0;

	fZ=0.5f;
	nBlend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
	dwCol=0xFFFFFFFF;

	ZeroMemory( &letters, sizeof(letters) );
	ZeroMemory( &pre, sizeof(letters) );
	ZeroMemory( &post, sizeof(letters) );
	
	// Load font description

	data=hge->Resource_Load(szFont, &size);
	if(!data) return;

	desc = new char[size+1];
	memcpy(desc,data,size);
	desc[size]=0;
	hge->Resource_Free(data);

	pdesc=_get_line(desc,linebuf);
	if(strcmp(linebuf, FNTHEADERTAG))
	{
		hge->System_Log("Font %s has incorrect format.", szFont);
		delete[] desc;	
		return;
	}

	// Parse font description

	while(pdesc = _get_line(pdesc,linebuf))
	{
		if(!strncmp(linebuf, FNTBITMAPTAG, sizeof(FNTBITMAPTAG)-1 ))
		{
			strcpy(buf,szFont);
			pbuf=strrchr(buf,'\\');
			if(!pbuf) pbuf=strrchr(buf,'/');
			if(!pbuf) pbuf=buf;
			else pbuf++;
			if(!sscanf(linebuf, "Bitmap = %s", pbuf)) continue;

			hTexture=hge->Texture_Load(buf, 0, bMipmap);
			if(!hTexture)
			{
				delete[] desc;	
				return;
			}
		}

		else if(!strncmp(linebuf, FNTCHARTAG, sizeof(FNTCHARTAG)-1 ))
		{
			pbuf=strchr(linebuf,'=');
			if(!pbuf) continue;
			pbuf++;
			while(*pbuf==' ') pbuf++;
			if(*pbuf=='\"')
			{
				pbuf++;
				i=(unsigned char)*pbuf++;
				pbuf++; // skip "
			}
			else
			{
				i=0;
				while((*pbuf>='0' && *pbuf<='9') || (*pbuf>='A' && *pbuf<='F') || (*pbuf>='a' && *pbuf<='f'))
				{
					chr=*pbuf;
					if(chr >= 'a') chr-='a'-':';
					if(chr >= 'A') chr-='A'-':';
					chr-='0';
					if(chr>0xF) chr=0xF;
					i=(i << 4) | chr;
					pbuf++;
				}
				if(i<0 || i>255) continue;
			}
			sscanf(pbuf, " , %d , %d , %d , %d , %d , %d", &x, &y, &w, &h, &a, &c);

			letters[i] = new hgeSprite(hTexture, (float)x, (float)y, (float)w, (float)h);
			pre[i]=(float)a;
			post[i]=(float)c;
			if(h>fHeight) fHeight=(float)h;
		}
	}

	delete[] desc;	
}