🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

HUDding progress!

Published April 26, 2008
Advertisement
Okay, so I have a working HUD implementation up! The code below looks kind of messy, but the thing is, all of it only needs to be run once ever. Except for hud.Draw(), though.. that's obvious, right?

HUD hud(80, 3);hud.SetBGColor(CC_BLUE);hud.WriteStatic(string() + char(218) + char(191), 0, 0, CCI_BLACK);hud.WriteStatic(string() + char(192) + char(217), 0, 1, CCI_BLACK);hud.WriteStatic(char(179), 6, 0, CCI_BLACK);hud.WriteStatic(char(179), 6, 1, CCI_BLACK);hud.WriteStatic(string() + char(1) + char(26), 8, 0, CC_CYAN);hud.WriteStatic(string() + char(1) + char(26), 8, 1, CCI_BLACK);hud.WriteStatic(char(179), 16, 0, CCI_BLACK);hud.WriteStatic(char(179), 16, 1, CCI_BLACK);hud.WriteStatic(char(2), 18, 0, CC_CYAN);hud.WriteStatic(char(2), 18, 1, CCI_BLACK);hud.WriteStatic(char(179), 25, 0, CCI_BLACK);hud.WriteStatic(char(179), 25, 1, CCI_BLACK);hud.WriteStatic("Skill", 27, 0, CCI_BLACK);hud.WriteStatic("Time", 27, 1, CCI_BLACK);hud.WriteStatic("Score", 27, 2, CCI_BLACK);hud.WriteStatic("Men Left", 2, 2, CCI_BLACK);	statinfo si; // One statinfo to be copied for them allsi.alignright = true;si.color = CC_CYAN;si.pos.Y = 0;	si.theStat = &GameInfo.doorsshotsi.pos.X = 4;hud.AddStat(si);	si.theStat = &GameInfo.snipesshotsi.pos.X = 14;hud.AddStat(si);	si.theStat = &GameInfo.ghostsshotsi.pos.X = 23;hud.AddStat(si);		si.color = CCI_BLACK;si.pos.Y = 1;	si.theStat = &GameInfo.doorsleftsi.pos.X = 4;hud.AddStat(si);	si.theStat = &GameInfo.snipesleftsi.pos.X = 14;hud.AddStat(si);	si.theStat = &GameInfo.ghostsshotsi.pos.X = 23;hud.AddStat(si);	si.theStat = &GameInfo.livessi.pos.X = 0;si.pos.Y = 2;si.alignright = false;hud.AddStat(si);	hud.Draw(0, 0);


Internally, the HUD class contains a "static information buffer", where information that shouldn't be altered often if ever is held. This is where the bits like "Men Left" and the symbols and stuff are held, as well as the HUD background color for each cell. WriteStatic writes a character string (or single character) to that buffer, with the specified forecolor.

Next, I create a statinfo object. AddStat() copies, so we don't have to worry about creating a statinfo for each stat. The statinfo struct contains four members: an int* pointer to the data for the HUD, a positioning COORD, a forecolor WORD, and a boolean that sets whether it should be aligned to the right or not (if true, the position is treated as the location of the last character in the data, instead of the first).

Then, I Draw() the HUD to the screen. The arguments specify where the upper-left corner of the HUD will be put. After all this, all you need to do to change the values on the HUD is change the values that you gave to the statinfo objects! The only thing you need to do is Draw() the HUD again.

The thing I like most about this, though, is that the HUD has its own buffer. All it does to interact with the actual console is print its buffer to the area it wants to. So its internal buffer is only as large as the size parameters passed to it at the start, and I have no worries about ruining data held by the gameview area.

Pic!
Previous Entry HUDding
Next Entry Update so far
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement