55502f40dc8b7c769880b10874abc9d0

First post!

Just curious for comments or thoughts on this bit of code from my game, might post the whole game later, though I'm probably going to port it to SDL instead of DarkGDK.

Some notes: YELLOW, GREEN, and so on are from dbRGB() function, example usage const DWORD RED = dbRGB(255, 0, 0);

dbLine draws lines, dbBox draws boxes ...
dbLine(startx, starty, endx, endy)
dbBox(left, top, right, bottom)

example usage of function would be something like:

const unsigned int MAXFUEL = 255;
unsigned int fuel = 200;

drawStatusBar("Fuel", 50, 300, fuel, MAXFUEL);

void drawStatusBar(char* text, int x, int y, int current, int max)	
{
	dbText(x, y-14, text);
	//  X / 50 fraction to draw status bar
	// 66+ green	31+ yellow	-> red
	int rows = (current * 100) / max / 2;
	const int width = 4;
	DWORD color;
	if((current * 100) / max > 65)
		color = GREEN;
	else if((current * 100) / max > 31)
		color = YELLOW;
	else
		color = RED;
	// start and end bars
	dbLine(x, y, x, y+width-1);
	dbLine(x+51, y, x+51, y+width-1);
	dbInk(color, BLACK);
        // status bar
	dbBox(x+1, y, x+rows+1, y+width);
	dbInk(WHITE, BLACK);
	
}

Refactorings

No refactoring yet !

376bcb7213600fed8cd74f092edf1253

Ron Paul

August 28, 2011, August 28, 2011 16:31, permalink

No rating. Login to rate!

a) Needs at least one (possibly more) blinking cursors
b) Rewrite in scheme

376bcb7213600fed8cd74f092edf1253

Ron Paul

August 28, 2011, August 28, 2011 16:31, permalink

No rating. Login to rate!

a) Needs at least one (possibly more) blinking cursors
b) Rewrite in scheme

F9a9ba6663645458aa8630157ed5e71e

Ants

August 27, 2011, August 27, 2011 17:56, permalink

No rating. Login to rate!

A couple questions:
- Comments say Yellow is 31+, but the comparison is against greater than 31. Is the comment out of date?
- Why is there a dbInk(WHITE, BLACK) call at the end of the function?

A couple of suggestions:
Some values are recomputed several times. Save these in a local variables:
- (current * 100) / max
- x + 51
- y + width

Your refactoring





Format Copy from initial code

or Cancel