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 !
Ron Paul
August 28, 2011, August 28, 2011 16:31, permalink
a) Needs at least one (possibly more) blinking cursors
b) Rewrite in scheme
Ron Paul
August 28, 2011, August 28, 2011 16:31, permalink
a) Needs at least one (possibly more) blinking cursors
b) Rewrite in scheme
Ants
August 27, 2011, August 27, 2011 17:56, permalink
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
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);