Game Development Community

dev|Pro Game Development Curriculum

Numeric Energy HUD

by Josh Moore · 04/11/2006 (2:01 pm) · 4 comments

I made this to display ShapeBase energy as a number so I can use it as ammo for my tanks and turrets. Having a little bar that shows your current energy out of the max just wouldn't work. I'm resourcing it as I'm sure a few people out there will want to do the same thing.

Create a new .cc file with
//-----------------------------------------------------------------------------
// Numeric Energy Hud - By Josh Moore
//-----------------------------------------------------------------------------
// This takes a client's control object's energy and displays it as a number

#include "dgl/dgl.h"
#include "gui/core/guiControl.h"
#include "game/gameConnection.h"
#include "game/shapeBase.h"

//-----------------------------------------------------------------
class NumericEnergyHud : public GuiControl
{
	typedef GuiControl Parent;

public:
	NumericEnergyHud();

	void onRender(Point2I, const RectI &rect);
	DECLARE_CONOBJECT(NumericEnergyHud);
};


//-----------------------------------------------------------------
IMPLEMENT_CONOBJECT(NumericEnergyHud);

NumericEnergyHud::NumericEnergyHud()
{
}

//-----------------------------------------------------------------
void NumericEnergyHud::onRender(Point2I offset, const RectI &updateRect)
{
	GameConnection* conn = GameConnection::getConnectionToServer();
	if(!conn) return;
	ShapeBase* control = conn->getControlObject();
	if(!control) return;

	char display[128];
	dSprintf(display, 128, "%2.0f[[60c20c3b180d4]]", mFloor(control->getEnergyLevel()));

	dglSetBitmapModulation(mProfile->mFontColor);
	renderJustifiedText(offset, mBounds.extent, display);
	dglClearBitmapModulation();
}

Enjoy!

#1
04/11/2006 (2:10 pm)
Why not just use a GuiTextCtrl and set the value like the AmmoAmountHUD resource?
#2
04/11/2006 (5:20 pm)
Sending this kind of information with ClientCommands is too heavy on the network, although I'll admit I use them for ammo based weapons. Would be a good idea to make a GUI that just grabs the ammo from mounted images.
#3
01/06/2007 (8:17 am)
Wonderful resource.
Working in TGE 1.5.
Using it for damage as well.
#4
01/11/2008 (1:54 pm)
Works great, thank you!